Search in sources :

Example 31 with Individual

use of org.apache.jena.ontology.Individual in project jena by apache.

the class schemagen method writeOntIndividuals.

/**
 * Write individuals as ontology terms
 */
protected void writeOntIndividuals() {
    String template = m_options.hasIndividualTemplateOption() ? m_options.getIndividualTemplateOption() : DEFAULT_INDIVIDUAL_TEMPLATE;
    for (Iterator<? extends RDFNode> i = selectIndividuals(); i.hasNext(); ) {
        Individual ind = ((Resource) i.next()).as(Individual.class);
        // do we have a local class resource
        Resource cls = ind.getOntClass();
        if (cls == null) {
            cls = OWL.Thing;
        }
        String varName = m_resourcesToNames.get(cls);
        String valType = (varName != null) ? varName : "M_MODEL.createClass( \"" + cls.getURI() + "\" )";
        // push the individuals type onto the stack
        addReplacementPattern("valtype", valType);
        writeValue(ind, template, "Individual", "createIndividual", "_INSTANCE");
        pop(1);
    }
}
Also used : Individual(org.apache.jena.ontology.Individual)

Example 32 with Individual

use of org.apache.jena.ontology.Individual in project ORCID-Source by ORCID.

the class RDFMessageBodyWriter method describeResearcherUrls.

private void describeResearcherUrls(ResearcherUrls researcherUrls, Individual person, OntModel m) {
    if (researcherUrls == null || researcherUrls.getResearcherUrl() == null) {
        return;
    }
    for (ResearcherUrl url : researcherUrls.getResearcherUrl()) {
        Individual page = m.createIndividual(url.getUrl().getValue(), null);
        String urlName = getUrlName(url);
        if (isHomePage(urlName)) {
            person.addProperty(FOAF.homepage, page);
        } else if (isFoaf(urlName)) {
            // TODO: What if we want to link to the URL of the other FOAF
            // *Profile*?
            // Note: We don't dear here to do owl:sameAs or
            // prov:specializationOf as we don't know the extent of the
            // other FOAF profile - we'll
            // suffice to say it's an alternate view of the same person
            person.addProperty(PROV.alternateOf, page);
            page.addRDFType(FOAF.Person);
            page.addRDFType(PROV.Person);
            person.addSeeAlso(page);
        } else if (isWebID(urlName)) {
            person.addSameAs(page);
        } else {
            // It's some other foaf:page which might not be about
            // this person
            person.addProperty(FOAF.page, page);
        }
    }
}
Also used : Individual(org.apache.jena.ontology.Individual) ResearcherUrl(org.orcid.jaxb.model.message.ResearcherUrl)

Example 33 with Individual

use of org.apache.jena.ontology.Individual in project ORCID-Source by ORCID.

the class RDFMessageBodyWriter method describeError.

protected void describeError(ErrorDesc errorDesc, OntModel m) {
    String error = errorDesc.getContent();
    Individual root = m.createIndividual(m.createResource());
    root.setLabel("Error", EN);
    root.setComment(error, EN);
}
Also used : Individual(org.apache.jena.ontology.Individual)

Example 34 with Individual

use of org.apache.jena.ontology.Individual in project ORCID-Source by ORCID.

the class RDFMessageBodyWriter method describePerson.

private Individual describePerson(OrcidProfile orcidProfile, OntModel m) {
    String orcidUri = orcidProfile.getOrcidIdentifier().getUri();
    Individual person = m.createIndividual(orcidUri, FOAF.Person);
    person.addRDFType(PROV.Person);
    if (orcidProfile.getOrcidBio() == null) {
        return person;
    }
    OrcidBio orcidBio = orcidProfile.getOrcidBio();
    if (orcidBio == null) {
        return person;
    }
    describePersonalDetails(orcidBio.getPersonalDetails(), person, m);
    describeContactDetails(orcidBio.getContactDetails(), person, m);
    describeBiography(orcidBio.getBiography(), person, m);
    describeResearcherUrls(orcidBio.getResearcherUrls(), person, m);
    return person;
}
Also used : OrcidBio(org.orcid.jaxb.model.message.OrcidBio) Individual(org.apache.jena.ontology.Individual)

Example 35 with Individual

use of org.apache.jena.ontology.Individual in project ORCID-Source by ORCID.

the class RDFMessageBodyWriterV2 method describeContactDetails.

private void describeContactDetails(Person orcidPerson, Individual person, OntModel m) {
    if (orcidPerson == null) {
        return;
    }
    Emails emails = orcidPerson.getEmails();
    if (emails != null) {
        for (Email email : emails.getEmails()) {
            if (email.isCurrent()) {
                Individual mbox = m.createIndividual("mailto:" + email.getEmail(), null);
                person.addProperty(FOAF.mbox, mbox);
            }
        }
    }
    Addresses addresses = orcidPerson.getAddresses();
    Address addr = (addresses != null && addresses.getAddress().size() > 0) ? addresses.getAddress().get(0) : null;
    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 : Addresses(org.orcid.jaxb.model.record_v2.Addresses) Email(org.orcid.jaxb.model.record_v2.Email) Address(org.orcid.jaxb.model.record_v2.Address) Individual(org.apache.jena.ontology.Individual) Emails(org.orcid.jaxb.model.record_v2.Emails)

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