Skip to content

Commit

Permalink
load pav and prov ontologies for provenance
Browse files Browse the repository at this point in the history
  • Loading branch information
stain committed May 26, 2013
1 parent 06057ab commit 8744ea9
Show file tree
Hide file tree
Showing 4 changed files with 2,402 additions and 622 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@
@Produces( { APPLICATION_RDFXML, TEXT_TURTLE, TEXT_N3 })
public class RDFMessageBodyWriter implements MessageBodyWriter<OrcidMessage> {

private static final String FOAF_RDF = "foaf.rdf";
private static final String PAV = "http://purl.org/pav/";
private static final String PAV_RDF = "pav.rdf";
private static final String PROV_O_RDF = "prov-o.rdf";
private static final String PROV = "http://www.w3.org/prov#";
private static final String PROV_O = "http://www.w3.org/prov-o#";
private static final String FOAF_0_1 = "http://xmlns.com/foaf/0.1/";
@SuppressWarnings("unused")
private Ontology foaf;

private DatatypeProperty foafName;
private DatatypeProperty foafGivenName;
private DatatypeProperty foafFamilyName;
Expand All @@ -69,10 +74,12 @@ public class RDFMessageBodyWriter implements MessageBodyWriter<OrcidMessage> {

@Value("${org.orcid.core.baseUri:http://orcid.org}")
private String baseUri = "http://orcid.org";
private OntClass foafDocument;
private DatatypeProperty foafAccountName;
private ObjectProperty foafPrimaryTopic;
private OntClass foafPersonalProfileDocument;
private OntModel prov;
private OntModel foaf;
private OntModel pav;

/**
* Ascertain if the MessageBodyWriter supports a particular type.
Expand Down Expand Up @@ -166,11 +173,12 @@ public void writeTo(OrcidMessage xml, Class<?> type, Type genericType, Annotatio

OrcidProfile orcidProfile = xml.getOrcidProfile();


Individual person = describePerson(orcidProfile, m);

Individual account = describeAccount(orcidProfile, m, person);

if (orcidProfile != null) {
Individual person = describePerson(orcidProfile, m);
if (person != null) {
Individual account = describeAccount(orcidProfile, m, person);
}
}

MediaType rdfXml = new MediaType("application", "rdf+xml");
if (mediaType.isCompatible(rdfXml)) {
Expand Down Expand Up @@ -204,7 +212,13 @@ private Individual describeAccount(OrcidProfile orcidProfile, OntModel m, Indivi
private Individual describePerson(OrcidProfile orcidProfile, OntModel m) {
String orcidUri = orcidProfile.getOrcidId();
Individual person = m.createIndividual(orcidUri, foafPerson);
if (orcidProfile.getOrcidBio() == null) {
return person;
}
PersonalDetails personalDetails = orcidProfile.getOrcidBio().getPersonalDetails();
if (personalDetails == null) {
return person;
}

if (personalDetails.getCreditName() != null) {
person.addProperty(foafName, personalDetails.getCreditName().getContent());
Expand All @@ -225,29 +239,60 @@ protected OntModel getOntModel() {
if (foaf == null) {
loadFoaf();
}

if (prov == null) {
loadProv();
}
if (pav == null) {
loadPav();
}


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

protected synchronized void loadFoaf() {
if (foaf != null) {
protected synchronized void loadPav() {
if (pav != null) {
return;
}
OntModel ontModel = loadOntologyFromClasspath(PAV_RDF, PAV);
pav = ontModel;
}

protected synchronized void loadProv() {
if (prov != null) {
return;
}
OntModel ontModel = loadOntologyFromClasspath(PROV_O_RDF, PROV_O);

prov = ontModel;
}

protected OntModel loadOntologyFromClasspath(String classPathUri, String uri) {
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);
InputStream inStream = getClass().getResourceAsStream(classPathUri);
if (inStream == null) {
throw new IllegalArgumentException("Can't load " + classPathUri);
}
Ontology ontology = ontModel.createOntology(uri);
ontModel.read(inStream, uri);
return ontModel;
}

// // The loaded ontology
protected synchronized void loadFoaf() {
if (foaf != null) {
return;
}

OntModel ontModel = loadOntologyFromClasspath(FOAF_RDF, FOAF_0_1);

// foaf = ontModel.getOntology(FOAF_0_1);

// classes from foaf
foafDocument = ontModel.getOntClass(FOAF_0_1 + "Document");
foafPerson = ontModel.getOntClass(FOAF_0_1 + "Person");
foafOnlineAccount = ontModel.getOntClass(FOAF_0_1 + "OnlineAccount");
foafPersonalProfileDocument = ontModel.getOntClass(FOAF_0_1 + "PersonalProfileDocument");
Expand All @@ -264,5 +309,6 @@ protected synchronized void loadFoaf() {
foafAccount = ontModel.getObjectProperty(FOAF_0_1 + "account");
foafAccountServiceHomepage = ontModel.getObjectProperty(FOAF_0_1 + "accountServiceHomepage");

foaf = ontModel;
}
}
Loading

0 comments on commit 8744ea9

Please sign in to comment.