Skip to content

Commit

Permalink
Load FOAF separately and add as import (avoids printing all of foaf!)
Browse files Browse the repository at this point in the history
  • Loading branch information
stain committed May 24, 2013
1 parent cbfd2fc commit b6f91eb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
public class RDFMessageBodyWriter implements MessageBodyWriter<OrcidMessage> {

private static final String FOAF_0_1 = "http://xmlns.com/foaf/0.1/";
private OntModel ontModel;
@SuppressWarnings("unused")
private Ontology foaf;
private DatatypeProperty foafName;
Expand Down Expand Up @@ -187,28 +186,33 @@ public void writeTo(OrcidMessage xml, Class<?> type, Type genericType, Annotatio
}

protected OntModel getOntModel() {
if (ontModel != null) {
return ontModel;
if (foaf == null) {
loadFoaf();
}
// No.. Let's go thread-safe and make it
synchronized (this) {
if (ontModel == null) {
// Create RDF model
ontModel = ModelFactory.createOntologyModel();
ontModel.setDynamicImports(true);
InputStream foafOnt = getClass().getResourceAsStream("foaf.rdf");
ontModel.setNsPrefix("foaf", FOAF_0_1);
ontModel.read(foafOnt, FOAF_0_1);

// The loaded ontology
foaf = ontModel.getOntology(FOAF_0_1);

// properties from foaf
foafName = ontModel.getDatatypeProperty(FOAF_0_1 + "name");
foafGivenName = ontModel.getDatatypeProperty(FOAF_0_1 + "givenName");
familyName = ontModel.getDatatypeProperty(FOAF_0_1 + "familyName");
}
return ontModel;

OntModel ontModel = ModelFactory.createOntologyModel();
ontModel.setNsPrefix("foaf", FOAF_0_1);
ontModel.getDocumentManager().loadImports(foaf.getOntModel());
return ontModel;
}

protected synchronized void loadFoaf() {
if (foaf != null) {
return;
}
OntModel ontModel = ModelFactory.createOntologyModel();

// Load from classpath
InputStream foafOnt = getClass().getResourceAsStream("foaf.rdf");
foaf = ontModel.createOntology(FOAF_0_1);
foaf.getModel().read(foafOnt, FOAF_0_1);

// // The loaded ontology
// foaf = ontModel.getOntology(FOAF_0_1);

// properties from foaf
foafName = ontModel.getDatatypeProperty(FOAF_0_1 + "name");
foafGivenName = ontModel.getDatatypeProperty(FOAF_0_1 + "givenName");
familyName = ontModel.getDatatypeProperty(FOAF_0_1 + "familyName");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void writeRdfXML() throws Exception {
assertTrue(str.contains("http://orcid.example.com/000-1337"));
assertTrue(str.contains("foaf:name>John"));
assertTrue(str.contains("rdf:about"));
// assertFalse(str.contains("subClassOf"));
assertFalse(str.contains("subClassOf"));
}

@Test
Expand All @@ -92,7 +92,7 @@ public void writeTurte() throws Exception {
assertTrue(str.contains("<http://orcid.example.com/000-1337>"));
assertTrue(str.contains("foaf:Person"));
assertTrue(str.contains("foaf:name \"John F"));
// assertFalse(str.contains("subClassOf"));
assertFalse(str.contains("subClassOf"));
}


Expand Down

0 comments on commit b6f91eb

Please sign in to comment.