Skip to content

Commit

Permalink
Further examples of RDF generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Feb 5, 2015
1 parent 56e604d commit de328de
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
Expand Up @@ -28,11 +28,11 @@
import org.fcrepo.kernel.identifiers.IdentifierConverter;
import org.slf4j.Logger;

import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.rdf.model.Resource;

/**
* @author cabeer
* @author ajs6f
* @since 9/16/14
*/
public class LdpRdfContext extends NodeRdfContext {
Expand All @@ -49,27 +49,15 @@ public LdpRdfContext(final FedoraResource resource,
final IdentifierConverter<Resource, FedoraResource> idTranslator) {
super(resource, idTranslator);

concat(typeContext());
concat(create(subject(), type.asNode(), RDF_SOURCE.asNode()));

if (resource instanceof Container) {
concat(containerContext());
concat(create(subject(), type.asNode(), CONTAINER.asNode()));

if (!resource.hasType(FEDORA_CONTAINER)) {
concat(defaultContainerContext());
concat(create(subject(), type.asNode(), BASIC_CONTAINER.asNode()));
}
}

}

private Triple typeContext() {
return create(subject(), type.asNode(), RDF_SOURCE.asNode());
}

private Triple containerContext() {
return create(subject(), type.asNode(), CONTAINER.asNode());
}

private Triple defaultContainerContext() {
return create(subject(), type.asNode(), BASIC_CONTAINER.asNode());
}
}
Expand Up @@ -19,7 +19,6 @@
import static com.hp.hpl.jena.graph.NodeFactory.createURI;
import static com.hp.hpl.jena.graph.Triple.create;
import static com.hp.hpl.jena.vocabulary.RDF.type;
import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toMap;
import static org.fcrepo.kernel.RdfLexicon.HAS_NAMESPACE_PREFIX;
import static org.fcrepo.kernel.RdfLexicon.HAS_NAMESPACE_URI;
Expand All @@ -28,6 +27,7 @@
import static org.fcrepo.kernel.impl.utils.UncheckedFunction.uncheck;

import java.util.Arrays;
import java.util.stream.Stream;

import javax.jcr.NamespaceRegistry;
import javax.jcr.RepositoryException;
Expand Down Expand Up @@ -59,12 +59,12 @@ public NamespaceRdfContext(final Session session) throws RepositoryException {
namespaces(Arrays.stream(namespaceRegistry.getPrefixes()).filter(p -> !p.isEmpty() && !p.equals("jcr")).collect(
toMap(p -> p, uncheck(p -> getRDFNamespaceForJcrNamespace(namespaceRegistry.getURI(p))))));

concat(namespaces().entrySet().stream().<Triple>flatMap(
concat(namespaces().entrySet().stream().flatMap(
e -> {
final Node nsSubject = createURI(e.getValue());
return asList(create(nsSubject, type.asNode(), VOAF_VOCABULARY.asNode()),
return Stream.of(create(nsSubject, type.asNode(), VOAF_VOCABULARY.asNode()),
create(nsSubject, HAS_NAMESPACE_PREFIX.asNode(), createLiteral(e.getKey())),
create(nsSubject, HAS_NAMESPACE_URI.asNode(), createLiteral(e.getValue()))).stream();
}).iterator());
create(nsSubject, HAS_NAMESPACE_URI.asNode(), createLiteral(e.getValue())));
}));
}
}
Expand Up @@ -58,14 +58,16 @@ public NodeRdfContext(final FedoraResource resource,
final IdentifierConverter<Resource, FedoraResource> idTranslator) {
super();
this.resource = resource;
try {
final Node node = resource().getNode();
if (nonNull(node)) {

final Node node = resource().getNode();
if (nonNull(node)) {
try {
session(node.getSession());
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}

this.idTranslator = idTranslator;
this.subject = idTranslator.reverse().convert(resource).asNode();
}
Expand Down
Expand Up @@ -51,6 +51,7 @@ public RdfStream apply(final NodeDefinition input) {

if (requiredPrimaryTypes.length > 1) {
// TODO we can express this as an OWL unionOf. But should we?
// TODO ajs6f replies: why would we not just emit multiple type triples instead of using OWL?
LOGGER.trace(
"Skipping RDFS:range for {} with multiple primary types",
propertyDefinitionNode.getName());
Expand Down
Expand Up @@ -75,7 +75,7 @@ public void setUp() throws RepositoryException {
}

@Test
public void testGoodDefinition() throws RepositoryException {
public void testGoodDefinition() {
final Set<Triple> results =
copyOf(testMapper.apply(mockItemDefinition).iterator());
LOGGER.debug("Created RDF: ");
Expand Down

0 comments on commit de328de

Please sign in to comment.