use of org.apache.jena.ontology.Individual in project ORCID-Source by ORCID.
the class RDFMessageBodyWriter method describeContactDetails.
private void describeContactDetails(ContactDetails contactDetails, Individual person, OntModel m) {
if (contactDetails == null) {
return;
}
List<Email> emails = contactDetails.getEmail();
if (emails != null) {
for (Email email : emails) {
if (email.isCurrent()) {
Individual mbox = m.createIndividual("mailto:" + email.getValue(), null);
person.addProperty(FOAF.mbox, mbox);
}
}
}
Address addr = contactDetails.getAddress();
if (addr != null) {
if (addr.getCountry() != null) {
String countryCode = addr.getCountry().getValue().name();
Individual position = m.createIndividual(Geonames.Feature);
position.addProperty(Geonames.countryCode, countryCode);
person.addProperty(FOAF.based_near, position);
Individual country = getCountry(countryCode);
if (country != null) {
country = addToModel(position.getOntModel(), country);
position.addProperty(Geonames.parentCountry, country);
}
// TODO: Include URI and (a) full name of country
// Potential source: geonames.org
// See https://gist.github.com/stain/7566375
}
}
}
use of org.apache.jena.ontology.Individual in project ORCID-Source by ORCID.
the class RDFMessageBodyWriter method describeAccount.
private Individual describeAccount(OrcidProfile orcidProfile, OntModel m, Individual person) {
String orcidURI = orcidProfile.getOrcidIdentifier().getUri();
String orcidPublicationsUri = orcidURI + "#workspace-works";
Individual publications = m.createIndividual(orcidPublicationsUri, FOAF.Document);
// list of publications
// (anchor in the HTML rendering - foaf:publications goes to a foaf:Document - not to an
// RDF list of publications - although we should probably also have that)
person.addProperty(FOAF.publications, publications);
String orcidAccountUri = orcidURI + "#orcid-id";
Individual account = m.createIndividual(orcidAccountUri, FOAF.OnlineAccount);
person.addProperty(FOAF.account, account);
Individual webSite = null;
if (baseUri != null) {
webSite = m.createIndividual(baseUri, null);
account.addProperty(FOAF.accountServiceHomepage, webSite);
}
String orcId = orcidProfile.getOrcidIdentifier().getPath();
account.addProperty(FOAF.accountName, orcId);
account.addLabel(orcId, null);
// The current page is the foaf:PersonalProfileDocument - this assumes
// we have done a 303 See Other redirect to the RDF resource, so that it
// differs from the ORCID uri.
// for example:
//
// GET http://orcid.org/0000-0003-4654-1403
// Accept: text/turtle
//
// HTTP/1.1 303 See Other
// Location: https://pub.orcid.org/experimental_rdf_v1/0000-0001-9842-9718
String profileUri;
if (getUriInfo() != null) {
profileUri = getUriInfo().getAbsolutePath().toASCIIString();
} else {
// Some kind of fallback, although the PersonalProfiledocument should be an
// information resource without #anchor
profileUri = orcidURI + "#personalProfileDocument";
}
Individual profileDoc = m.createIndividual(profileUri, FOAF.PersonalProfileDocument);
profileDoc.addProperty(FOAF.primaryTopic, person);
OrcidHistory history = orcidProfile.getOrcidHistory();
if (history != null) {
if (history.isClaimed().booleanValue()) {
// Set account as PersonalProfileDocument
profileDoc.addProperty(FOAF.maker, person);
}
// Who made the profile?
switch(history.getCreationMethod()) {
case DIRECT:
case MEMBER_REFERRED:
case WEBSITE:
profileDoc.addProperty(PAV.createdBy, person);
profileDoc.addProperty(PROV.wasAttributedTo, person);
if (webSite != null && (history.getCreationMethod() == CreationMethod.WEBSITE || history.getCreationMethod() == CreationMethod.DIRECT)) {
profileDoc.addProperty(PAV.createdWith, webSite);
}
break;
case API:
Individual api = m.createIndividual(MEMBER_API, PROV.SoftwareAgent);
profileDoc.addProperty(PAV.importedBy, api);
if (history.isClaimed().booleanValue()) {
profileDoc.addProperty(PAV.curatedBy, person);
}
break;
default:
// Some unknown agent!
profileDoc.addProperty(PAV.createdWith, m.createIndividual(null, PROV.Agent));
}
if (history.getLastModifiedDate() != null) {
Literal when = calendarAsLiteral(history.getLastModifiedDate().getValue(), m);
profileDoc.addLiteral(PAV.lastUpdateOn, when);
profileDoc.addLiteral(PROV.generatedAtTime, when);
}
if (history.getSubmissionDate() != null) {
profileDoc.addLiteral(PAV.createdOn, calendarAsLiteral(history.getSubmissionDate().getValue(), m));
}
if (history.getCompletionDate() != null) {
profileDoc.addLiteral(PAV.contributedOn, calendarAsLiteral(history.getCompletionDate().getValue(), m));
}
if (history.getDeactivationDate() != null) {
profileDoc.addLiteral(PROV.invalidatedAtTime, calendarAsLiteral(history.getDeactivationDate().getValue(), m));
}
}
return profileDoc;
}
use of org.apache.jena.ontology.Individual in project ORCID-Source by ORCID.
the class RDFMessageBodyWriter method writeTo.
/**
* Write a type to an HTTP response. The response header map is mutable but
* any changes must be made before writing to the output stream since the
* headers will be flushed prior to writing the response body.
*
* @param message
* the instance to write.
* @param type
* the class of object that is to be written.
* @param genericType
* the type of object to be written, obtained either by
* reflection of a resource method return type or by inspection
* of the returned instance.
* {@link javax.ws.rs.core.GenericEntity} provides a way to
* specify this information at runtime.
* @param annotations
* an array of the annotations on the resource method that
* returns the object.
* @param mediaType
* the media type of the HTTP entity.
* @param httpHeaders
* a mutable map of the HTTP response headers.
* @param entityStream
* the {@link java.io.OutputStream} for the HTTP entity. The
* implementation should not close the output stream.
* @throws java.io.IOException
* if an IO error arises
* @throws javax.ws.rs.WebApplicationException
* if a specific HTTP error response needs to be produced. Only
* effective if thrown prior to the response being committed.
*/
@Override
public void writeTo(OrcidMessage xml, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
OntModel m = getOntModel();
if (xml.getErrorDesc() != null) {
describeError(xml.getErrorDesc(), m);
}
OrcidProfile orcidProfile = xml.getOrcidProfile();
// System.out.println(httpHeaders);
Individual profileDoc = null;
if (orcidProfile != null) {
Individual person = describePerson(orcidProfile, m);
if (person != null) {
profileDoc = describeAccount(orcidProfile, m, person);
}
}
MediaType jsonLd = new MediaType("application", "ld+json");
MediaType nTriples = new MediaType("application", "n-triples");
MediaType rdfXml = new MediaType("application", "rdf+xml");
String base = null;
if (getUriInfo() != null) {
getUriInfo().getAbsolutePath().toASCIIString();
}
if (mediaType.isCompatible(nTriples)) {
// NOTE: N-Triples requires absolute URIs
m.write(entityStream, "N-TRIPLES");
} else if (mediaType.isCompatible(jsonLd)) {
m.write(entityStream, "JSON-LD", base);
} else if (mediaType.isCompatible(rdfXml)) {
m.write(entityStream, "RDF/XML", base);
} else {
// Turtle is the safest default
m.write(entityStream, "TURTLE", base);
}
}
use of org.apache.jena.ontology.Individual in project jena by apache.
the class JenaOSGITest method testJenaCore.
@Test
public void testJenaCore() throws Exception {
Model model = makeModel();
Writer writer = new StringWriter();
model.write(writer, "N-Triples");
assertEquals("<http://example.com/alice> <http://xmlns.com/foaf/0.1/knows> <http://example.com/bob> .", writer.toString().trim());
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
ObjectProperty knowsObjProp = ontModel.createObjectProperty(knows.getURI());
ObjectProperty hasFriend = ontModel.createObjectProperty("http://example.com/has_friend");
hasFriend.addSuperProperty(knowsObjProp);
Individual aliceIndividual = ontModel.createIndividual(alice);
Individual bobIndividiual = ontModel.createIndividual(bob);
ontModel.add(aliceIndividual, hasFriend, bobIndividiual);
assertTrue(aliceIndividual.hasProperty(knowsObjProp, bobIndividiual));
}
use of org.apache.jena.ontology.Individual in project ORCID-Source by ORCID.
the class RDFMessageBodyWriterV2 method describeAccount.
private Individual describeAccount(Record record, OntModel m, Individual person) {
String orcidURI = record.getOrcidIdentifier().getUri();
String orcidPublicationsUri = orcidURI + "#workspace-works";
Individual publications = m.createIndividual(orcidPublicationsUri, FOAF.Document);
// list of publications
// (anchor in the HTML rendering - foaf:publications goes to a foaf:Document - not to an
// RDF list of publications - although we should probably also have that)
person.addProperty(FOAF.publications, publications);
String orcidAccountUri = orcidURI + "#orcid-id";
Individual account = m.createIndividual(orcidAccountUri, FOAF.OnlineAccount);
person.addProperty(FOAF.account, account);
Individual webSite = null;
if (baseUri != null) {
webSite = m.createIndividual(baseUri, null);
account.addProperty(FOAF.accountServiceHomepage, webSite);
}
String orcId = record.getOrcidIdentifier().getPath();
account.addProperty(FOAF.accountName, orcId);
account.addLabel(orcId, null);
// The current page is the foaf:PersonalProfileDocument - this assumes
// we have done a 303 See Other redirect to the RDF resource, so that it
// differs from the ORCID uri.
// for example:
//
// GET http://orcid.org/0000-0003-4654-1403
// Accept: text/turtle
//
// HTTP/1.1 303 See Other
// Location: https://pub.orcid.org/experimental_rdf_v1/0000-0001-9842-9718
String profileUri;
if (getUriInfo() != null) {
profileUri = getUriInfo().getAbsolutePath().toASCIIString();
} else {
// Some kind of fallback, although the PersonalProfiledocument should be an
// information resource without #anchor
profileUri = orcidURI + "#personalProfileDocument";
}
Individual profileDoc = m.createIndividual(profileUri, FOAF.PersonalProfileDocument);
profileDoc.addProperty(FOAF.primaryTopic, person);
History history = record.getHistory();
if (history != null) {
if (history.getClaimed()) {
// Set account as PersonalProfileDocument
profileDoc.addProperty(FOAF.maker, person);
}
// Who made the profile?
switch(history.getCreationMethod()) {
case DIRECT:
case MEMBER_REFERRED:
case WEBSITE:
profileDoc.addProperty(PAV.createdBy, person);
profileDoc.addProperty(PROV.wasAttributedTo, person);
if (webSite != null && (history.getCreationMethod() == CreationMethod.WEBSITE || history.getCreationMethod() == CreationMethod.DIRECT)) {
profileDoc.addProperty(PAV.createdWith, webSite);
}
break;
case API:
Individual api = m.createIndividual(MEMBER_API, PROV.SoftwareAgent);
profileDoc.addProperty(PAV.importedBy, api);
if (history.getClaimed()) {
profileDoc.addProperty(PAV.curatedBy, person);
}
break;
default:
// Some unknown agent!
profileDoc.addProperty(PAV.createdWith, m.createIndividual(null, PROV.Agent));
}
if (history.getLastModifiedDate() != null) {
Literal when = calendarAsLiteral(history.getLastModifiedDate().getValue(), m);
profileDoc.addLiteral(PAV.lastUpdateOn, when);
profileDoc.addLiteral(PROV.generatedAtTime, when);
}
if (history.getSubmissionDate() != null) {
profileDoc.addLiteral(PAV.createdOn, calendarAsLiteral(history.getSubmissionDate().getValue(), m));
}
if (history.getCompletionDate() != null) {
profileDoc.addLiteral(PAV.contributedOn, calendarAsLiteral(history.getCompletionDate().getValue(), m));
}
if (history.getDeactivationDate() != null) {
profileDoc.addLiteral(PROV.invalidatedAtTime, calendarAsLiteral(history.getDeactivationDate().getValue(), m));
}
}
return profileDoc;
}
Aggregations