Search in sources :

Example 41 with OntModel

use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.

the class SimpleReasonerInversePropertyTest method removeTBoxInverseAssertion1.

/*
	 * removing an inverseOf assertion from the tbox
	 */
public void removeTBoxInverseAssertion1(boolean sameAs) throws InterruptedException {
    // set up the tbox
    OntModel tBox = createTBoxModel();
    OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
    OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
    setInverse(P, Q);
    // this is the model to receive abox inferences
    Model inf = ModelFactory.createDefaultModel();
    // abox
    OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
    // set up SimpleReasoner and SimpleReasonerTBox listener,
    // register them with abox and tbox
    SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
    simpleReasoner.setSameAsEnabled(sameAs);
    aBox.register(simpleReasoner);
    SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
    tBox.register(simpleReasonerTBoxListener);
    // add statements to the abox and verify inference
    Resource c = aBox.createIndividual("http://test.vivo/c", OWL.Thing);
    Resource d = aBox.createIndividual("http://test.vivo/d", OWL.Thing);
    aBox.add(c, P, d);
    Assert.assertTrue(inf.contains(d, Q, c));
    // Remove P and Q inverse relationship and wait for
    // SimpleReasoner TBox thread to end.
    removeInverse(P, Q);
    while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
        Thread.sleep(delay);
    }
    // Verify inference has been removed
    Assert.assertFalse(inf.contains(d, Q, c));
    simpleReasonerTBoxListener.setStopRequested();
}
Also used : OntProperty(org.apache.jena.ontology.OntProperty) OntModel(org.apache.jena.ontology.OntModel) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) OntModel(org.apache.jena.ontology.OntModel)

Example 42 with OntModel

use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.

the class SimpleReasonerInversePropertyTest method addABoxAssertion4.

/*
	* adding abox data where the property has an inverse and
	* and equivalent property.
	*/
public void addABoxAssertion4(boolean sameAs) {
    // set up the tbox
    OntModel tBox = createTBoxModel();
    OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
    OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
    OntProperty R = createObjectProperty(tBox, "http://test.vivo/R", "property R");
    setInverse(P, Q);
    setInverse(R, Q);
    setEquivalent(R, P);
    // this is the model to receive abox inferences
    Model inf = ModelFactory.createDefaultModel();
    // create an ABox and register the SimpleReasoner with it
    OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
    SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
    sr.setSameAsEnabled(sameAs);
    aBox.register(sr);
    // add abox statements and verify inferences
    Resource a = aBox.createResource("http://test.vivo/a");
    Resource b = aBox.createResource("http://test.vivo/b");
    Resource c = aBox.createResource("http://test.vivo/c");
    Resource d = aBox.createResource("http://test.vivo/d");
    aBox.add(a, R, b);
    Assert.assertTrue(inf.contains(b, Q, a));
    aBox.add(c, Q, d);
    Assert.assertTrue(inf.contains(d, P, c));
    Assert.assertTrue(inf.contains(d, R, c));
}
Also used : OntProperty(org.apache.jena.ontology.OntProperty) OntModel(org.apache.jena.ontology.OntModel) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) OntModel(org.apache.jena.ontology.OntModel)

Example 43 with OntModel

use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.

the class SimpleReasonerInversePropertyTest method addABoxAssertion1.

/*
	* basic scenarios around adding abox data
	*
	* Create a Tbox with property P inverseOf property Q.
    * Add a statement a P b, and verify that b Q a is inferred.
    * Add a statement c Q d and verify that d Q c is inferred.
	*/
public void addABoxAssertion1(boolean sameAs) {
    // set up the tbox
    OntModel tBox = createTBoxModel();
    OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
    OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
    setInverse(P, Q);
    // this is the model to receive abox inferences
    Model inf = ModelFactory.createDefaultModel();
    // create an abox and register the SimpleReasoner listener with it
    OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
    SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
    sr.setSameAsEnabled(sameAs);
    aBox.register(sr);
    // add assertions to the abox and verify inferences
    Resource a = aBox.createResource("http://test.vivo/a");
    Resource b = aBox.createResource("http://test.vivo/b");
    Resource c = aBox.createResource("http://test.vivo/c");
    Resource d = aBox.createResource("http://test.vivo/d");
    aBox.add(a, P, b);
    Assert.assertTrue(inf.contains(b, Q, a));
    aBox.add(c, Q, d);
    Assert.assertTrue(inf.contains(d, P, c));
    // delete assertions and verify that inferences go away
    aBox.remove(c, Q, d);
    Assert.assertFalse(inf.contains(d, P, c));
    aBox.remove(a, P, b);
    Assert.assertFalse(inf.contains(b, Q, a));
}
Also used : OntProperty(org.apache.jena.ontology.OntProperty) OntModel(org.apache.jena.ontology.OntModel) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) OntModel(org.apache.jena.ontology.OntModel)

Example 44 with OntModel

use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.

the class SimpleReasonerInversePropertyTest method addABoxAssertion2.

/*
	 * don't infer statements already in the abox
	 * (never infer because it's in the abox already)
	*/
public void addABoxAssertion2(boolean sameAs) {
    // set up the tbox
    OntModel tBox = createTBoxModel();
    OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
    OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
    setInverse(P, Q);
    // this is the model to receive abox inferences
    Model inf = ModelFactory.createDefaultModel();
    // create an ABox and add data (no inferencing happening yet)
    OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
    // Individuals a, b, c and d
    Resource a = aBox.createResource("http://test.vivo/a");
    Resource b = aBox.createResource("http://test.vivo/b");
    aBox.add(b, Q, a);
    // register SimpleReasoner
    aBox.register(new SimpleReasoner(tBox, aBox, inf));
    Assert.assertFalse(inf.contains(b, Q, a));
    // add data and verify inferences
    aBox.add(a, P, b);
    Assert.assertFalse(inf.contains(b, Q, a));
}
Also used : OntProperty(org.apache.jena.ontology.OntProperty) OntModel(org.apache.jena.ontology.OntModel) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) OntModel(org.apache.jena.ontology.OntModel)

Example 45 with OntModel

use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.

the class JenaOntologyLoader method loadSystemAndUsers.

/**
 * This should load the system with classes, data properties and
 * object properties that the vitro systems needs.
 *
 * @throws Exception
 */
OntModel loadSystemAndUsers() throws Exception {
    Model model = ModelFactory.createDefaultModel();
    for (String ont : systemOnts) {
        InputStream in = this.getClass().getResourceAsStream(ont);
        model.read(in, null);
        in.close();
    }
    ontModel = ModelFactory.createOntologyModel(ONT_MODEL_SPEC, model);
    ontModel.prepare();
    return ontModel;
}
Also used : InputStream(java.io.InputStream) Model(org.apache.jena.rdf.model.Model) OntModel(org.apache.jena.ontology.OntModel)

Aggregations

OntModel (org.apache.jena.ontology.OntModel)272 Model (org.apache.jena.rdf.model.Model)112 Resource (org.apache.jena.rdf.model.Resource)92 Test (org.junit.Test)51 Statement (org.apache.jena.rdf.model.Statement)41 OntClass (org.apache.jena.ontology.OntClass)33 StmtIterator (org.apache.jena.rdf.model.StmtIterator)31 ArrayList (java.util.ArrayList)29 OntProperty (org.apache.jena.ontology.OntProperty)29 OntResource (org.apache.jena.ontology.OntResource)26 Literal (org.apache.jena.rdf.model.Literal)26 RDFNode (org.apache.jena.rdf.model.RDFNode)26 IOException (java.io.IOException)24 Individual (org.apache.jena.ontology.Individual)22 Property (org.apache.jena.rdf.model.Property)21 QueryExecution (org.apache.jena.query.QueryExecution)16 StringReader (java.io.StringReader)15 DatatypeProperty (org.apache.jena.ontology.DatatypeProperty)14 InputStream (java.io.InputStream)12 DataProperty (edu.cornell.mannlib.vitro.webapp.beans.DataProperty)11