Commit dc1aa320 authored by bseeger's avatar bseeger
Browse files

changes based on feedback

parent 9a578353
Repository PCDM object extension
Repository RDFS entailment extension
================================
This extension operates on LDP resources, performing
RDFS entailment for the specified ontologies and returns
the entailed triples for the resource.
the entailed triples for the resource.
For example:
......
/*
* Copyright 2016 Amherst College
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.amherst.acdc.exts.entailment;
/**
* Some header field definitions
*
* @author bseeger
*/
final class EntailmentHeaders {
public final static String ENTAILMENT_ACCEPT = "CamelEntailmentAccept";
private EntailmentHeaders() {
// prevent instantiation
}
}
......@@ -15,7 +15,6 @@
*/
package edu.amherst.acdc.exts.entailment;
import static edu.amherst.acdc.exts.entailment.EntailmentHeaders.ENTAILMENT_ACCEPT;
import static java.util.Optional.ofNullable;
import static org.apache.camel.Exchange.CONTENT_TYPE;
import static org.apache.camel.Exchange.HTTP_METHOD;
......@@ -38,6 +37,7 @@ public class EntailmentRouter extends RouteBuilder {
private final static String DEFAULT_CONTENT_TYPE = "text/turtle";
private final static String HTTP_QUERY_CONTEXT = "context";
private final static String ENTAILMENT_ACCEPT = "CamelEntailmentAccept";
/**
* Configure the message route workflow.
......
......@@ -16,6 +16,7 @@
package edu.amherst.acdc.services.entailment;
import static java.util.Optional.ofNullable;
import static java.util.stream.Collectors.toMap;
import static org.apache.http.impl.client.HttpClientBuilder.create;
import static org.apache.jena.rdf.model.ModelFactory.createDefaultModel;
import static org.apache.jena.rdf.model.ModelFactory.createRDFSModel;
......@@ -30,12 +31,10 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.http.impl.client.LaxRedirectStrategy;
import org.apache.jena.rdf.model.InfModel;
......@@ -54,8 +53,6 @@ public class EntailmentServiceImpl implements EntailmentService {
private static final Logger LOGGER = getLogger(EntailmentServiceImpl.class);
private List<String> rdfsOntologies;
private static final Lang DEFAULT_LANG = TURTLE;
private InfModel rdfsModel = createRDFSModel(createDefaultModel());
......@@ -74,9 +71,7 @@ public class EntailmentServiceImpl implements EntailmentService {
public EntailmentServiceImpl(final String ontologies) {
LOGGER.info("EntailmentServiceImpl: ontologies: {}", ontologies);
rdfsOntologies = new ArrayList<>(Arrays.asList(ontologies.split(",")));
rdfsOntologies.stream()
Arrays.stream(ontologies.split(","))
.peek(ont -> LOGGER.info("adding to rdfs model: {}", ont))
.map(String::trim)
.forEach(ont -> read(rdfsModel, ont));
......@@ -120,16 +115,11 @@ public class EntailmentServiceImpl implements EntailmentService {
private Map<String,String> getPrefixMap(final Model model, final Map<String,String> prefixes) {
final List<Statement> props = model.listStatements().toList();
final Map<String,String> modelPrefixes = new HashMap<String,String>();
final Map<String,String> modelPrefixes = new HashMap<>();
final Map<String,String> flip_prefixes =
prefixes.entrySet().stream().collect(Collectors.toMap(
Map.Entry::getValue,
Map.Entry::getKey,
(key1, key2) -> {
return key1;
}
));
prefixes.entrySet().stream().collect(toMap(Map.Entry::getValue, Map.Entry::getKey, (key1, key2) -> key1));
LOGGER.debug("There are {} properties on resource", props.size());
props.forEach(statement -> {
......
......@@ -42,12 +42,11 @@ public class EntailmentServiceTest {
private final String subject = "http://localhost:8080/fcrepo/rest/test";
private final String appType = "urn:app#Complete";
private String ontologies =
"http://purl.org/dc/terms/," +
"https://www.w3.org/2009/08/skos-reference/skos.rdf," +
"https://www.w3.org/2000/01/rdf-schema.rdf";
private String ontologies = "http://purl.org/dc/terms/," +
"http://purl.org/dc/elements/1.1/," +
"http://id.loc.gov/ontologies/bibframe/," +
"http://www.w3.org/2004/02/skos/core#," +
"http://www.w3.org/2000/01/rdf-schema#";
private final EntailmentService svc = new EntailmentServiceImpl(ontologies);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment