Search in sources :

Example 1 with Individual

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
        }
    }
}
Also used : Email(org.orcid.jaxb.model.message.Email) Address(org.orcid.jaxb.model.message.Address) Individual(org.apache.jena.ontology.Individual)

Example 2 with Individual

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;
}
Also used : Individual(org.apache.jena.ontology.Individual) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) Literal(org.apache.jena.rdf.model.Literal)

Example 3 with Individual

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);
    }
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Individual(org.apache.jena.ontology.Individual) OntModel(org.apache.jena.ontology.OntModel) MediaType(javax.ws.rs.core.MediaType)

Example 4 with Individual

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));
}
Also used : ObjectProperty(org.apache.jena.ontology.ObjectProperty) StringWriter(java.io.StringWriter) Individual(org.apache.jena.ontology.Individual) OntModel(org.apache.jena.ontology.OntModel) Model(org.apache.jena.rdf.model.Model) OntModel(org.apache.jena.ontology.OntModel) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 5 with Individual

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;
}
Also used : Individual(org.apache.jena.ontology.Individual) Literal(org.apache.jena.rdf.model.Literal) History(org.orcid.jaxb.model.record_v2.History)

Aggregations

Individual (org.apache.jena.ontology.Individual)53 ArrayList (java.util.ArrayList)17 OntClass (org.apache.jena.ontology.OntClass)16 Literal (org.apache.jena.rdf.model.Literal)6 OntModel (org.apache.jena.ontology.OntModel)4 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 MediaType (javax.ws.rs.core.MediaType)2 ObjectProperty (org.apache.jena.ontology.ObjectProperty)2 OntResource (org.apache.jena.ontology.OntResource)2 Test (org.junit.Test)2 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Model (org.apache.jena.rdf.model.Model)1 Resource (org.apache.jena.rdf.model.Resource)1 Address (org.orcid.jaxb.model.message.Address)1 Email (org.orcid.jaxb.model.message.Email)1 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)1 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)1 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)1