Search in sources :

Example 6 with OntModel

use of org.apache.jena.ontology.OntModel 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 7 with OntModel

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

the class RDFMessageBodyWriter method getOntModel.

protected OntModel getOntModel() {
    OntModel ontModel = ModelFactory.createOntologyModel();
    ontModel.setNsPrefix("foaf", FOAF.NS);
    ontModel.setNsPrefix("prov", PROV.NS);
    ontModel.setNsPrefix("pav", PAV.NS);
    ontModel.setNsPrefix("gn", Geonames.NS);
    // ontModel.getDocumentManager().loadImports(foaf.getOntModel());
    return ontModel;
}
Also used : OntModel(org.apache.jena.ontology.OntModel)

Example 8 with OntModel

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

the class RDFMessageBodyWriter method getCountries.

protected OntModel getCountries() {
    if (countries != null) {
        // Check for a static cache
        return countries;
    }
    // Load list of countries
    InputStream countriesStream = getClass().getResourceAsStream(COUNTRIES_TTL);
    if (countriesStream == null) {
        throw new IllegalStateException("Can't find country resource on classpath: " + COUNTRIES_TTL);
    }
    OntModel ontModel = ModelFactory.createOntologyModel();
    ontModel.read(countriesStream, "http://example.com/", "TURTLE");
    // Note: We should not need to synchronize(this) to cache, 
    // as the odd concurrent duplicate load is not harmful
    // and can be thrown away
    countries = ontModel;
    return countries;
}
Also used : InputStream(java.io.InputStream) OntModel(org.apache.jena.ontology.OntModel)

Example 9 with OntModel

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

the class TDB method sync.

/** Sync a TDB-backed Model. Do nothing if not TDB-backed. */
public static void sync(Model model) {
    if (model instanceof OntModelImpl) {
        OntModelImpl ontModel = (OntModelImpl) model;
        sync(ontModel.getBaseGraph());
        return;
    }
    // This never happens (there is only one OntModel implementation)
    if (model instanceof OntModel) {
        OntModel ontModel = (OntModel) model;
        sync(ontModel.getBaseModel());
        return;
    }
    sync(model.getGraph());
}
Also used : OntModelImpl(org.apache.jena.ontology.impl.OntModelImpl) OntModel(org.apache.jena.ontology.OntModel)

Example 10 with OntModel

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

the class TestOWLMisc method doTestSameAsDifferentFrom.

/**
     * Test sameAs/differentFrom interaction
     */
public void doTestSameAsDifferentFrom(OntModelSpec os) {
    String test = "[ a owl:AllDifferent ; owl:distinctMembers ( :limited1 :limited2 :limited3 ) ] .\n" + ":limited4 owl:sameAs :limited1 .";
    OntModel inf = ModelFactory.createOntologyModel(os, modelFromN3(test));
    Resource l4 = inf.getResource(NS + "limited4");
    Resource l2 = inf.getResource(NS + "limited2");
    Resource l3 = inf.getResource(NS + "limited3");
    assertTrue(inf.contains(l4, OWL.differentFrom, l2));
    assertTrue(inf.contains(l4, OWL.differentFrom, l3));
}
Also used : OntModel(org.apache.jena.ontology.OntModel)

Aggregations

OntModel (org.apache.jena.ontology.OntModel)12 Individual (org.apache.jena.ontology.Individual)3 Model (org.apache.jena.rdf.model.Model)2 Resource (org.apache.jena.rdf.model.Resource)2 Test (org.junit.Test)2 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 MediaType (javax.ws.rs.core.MediaType)1 BaseTest (org.apache.jena.atlas.junit.BaseTest)1 Triple (org.apache.jena.graph.Triple)1 DatatypeProperty (org.apache.jena.ontology.DatatypeProperty)1 ObjectProperty (org.apache.jena.ontology.ObjectProperty)1 OntClass (org.apache.jena.ontology.OntClass)1 OntModelImpl (org.apache.jena.ontology.impl.OntModelImpl)1 InfModel (org.apache.jena.rdf.model.InfModel)1 StmtIterator (org.apache.jena.rdf.model.StmtIterator)1 ValidityReport (org.apache.jena.reasoner.ValidityReport)1 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)1