Search in sources :

Example 71 with OWL2Parser

use of fr.lirmm.graphik.graal.io.owl.OWL2Parser in project graal by graphik-team.

the class OWL2ParserTest method dataMinCardinality1.

@Test
public void dataMinCardinality1() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":D rdf:type rdfs:Datatype . " + ":B rdf:type owl:Class . " + ":p rdf:type owl:DatatypeProperty . " + " [ rdf:type owl:Restriction ; " + " owl:onProperty :p ; " + " owl:onDataRange :D ; " + " owl:minCardinality 1 ] " + "  " + " rdfs:subClassOf :B . ");
    int nbRules = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (o instanceof Rule) {
            ++nbRules;
            Rule r = (Rule) o;
            CloseableIteratorWithoutException<Atom> bodyIt = r.getBody().iterator();
            CloseableIteratorWithoutException<Atom> headIt = r.getHead().iterator();
            Assert.assertTrue(bodyIt.hasNext());
            Assert.assertTrue(headIt.hasNext());
            Atom body1 = bodyIt.next();
            Atom body2 = bodyIt.next();
            Atom head = headIt.next();
            Assert.assertFalse(bodyIt.hasNext());
            Assert.assertFalse(headIt.hasNext());
            Assert.assertTrue(D.equals(body1.getPredicate()) || D.equals(body2.getPredicate()));
            Assert.assertTrue(P.equals(body1.getPredicate()) || P.equals(body2.getPredicate()));
            Assert.assertTrue(D.equals(body1.getPredicate()) || P.equals(body1.getPredicate()));
            Assert.assertTrue(D.equals(body2.getPredicate()) || P.equals(body2.getPredicate()));
            Assert.assertEquals(B, head.getPredicate());
        }
    }
    parser.close();
    Assert.assertEquals("Number of assertions found:", 1, nbRules);
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) Rule(fr.lirmm.graphik.graal.api.core.Rule) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 72 with OWL2Parser

use of fr.lirmm.graphik.graal.io.owl.OWL2Parser in project graal by graphik-team.

the class OWL2ParserTest method objectHasValue.

@Test
public void objectHasValue() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + ":p rdf:type owl:ObjectProperty . " + "	[rdf:type owl:Restriction ;	owl:onProperty :p ;" + "			owl:hasValue :i1]" + "	rdfs:subClassOf :A . ");
    int nbRules = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (o instanceof Rule) {
            ++nbRules;
            Rule r = (Rule) o;
            CloseableIteratorWithoutException<Atom> bodyIt = r.getBody().iterator();
            CloseableIteratorWithoutException<Atom> headIt = r.getHead().iterator();
            Assert.assertTrue(bodyIt.hasNext());
            Assert.assertTrue(headIt.hasNext());
            Atom body = bodyIt.next();
            Atom head = headIt.next();
            Assert.assertFalse(bodyIt.hasNext());
            Assert.assertFalse(headIt.hasNext());
            Assert.assertEquals(P, body.getPredicate());
            Assert.assertEquals(A, head.getPredicate());
            Assert.assertTrue(!body.getTerm(0).isConstant());
            Assert.assertEquals(body.getTerm(0), head.getTerm(0));
            Assert.assertEquals(I1, body.getTerm(1));
        }
    }
    parser.close();
    Assert.assertEquals("Number of assertions found:", 1, nbRules);
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) Rule(fr.lirmm.graphik.graal.api.core.Rule) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 73 with OWL2Parser

use of fr.lirmm.graphik.graal.io.owl.OWL2Parser in project graal by graphik-team.

the class OWL2ParserTest method intersectionOfObjectOneOfAndUnionOf.

@Test
public void intersectionOfObjectOneOfAndUnionOf() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":ClassA rdf:type owl:Class . " + ":ClassB rdf:type owl:Class . " + ":ClassC rdf:type owl:Class . " + ":ClassD rdf:type owl:Class . " + ":ClassE rdf:type owl:Class . " + "[ owl:intersectionOf ( [ owl:oneOf ( :i1 :i2 ) ] [ owl:unionOf ( :ClassC :ClassD ) ] ) ] rdfs:subClassOf :ClassE. ");
    int nbRules = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (o instanceof Rule) {
            ++nbRules;
        }
    }
    parser.close();
    Assert.assertEquals("Number of assertions found:", 4, nbRules);
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) Rule(fr.lirmm.graphik.graal.api.core.Rule) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Test(org.junit.Test)

Aggregations

OWL2Parser (fr.lirmm.graphik.graal.io.owl.OWL2Parser)73 Test (org.junit.Test)73 DefaultNegativeConstraint (fr.lirmm.graphik.graal.core.DefaultNegativeConstraint)67 Rule (fr.lirmm.graphik.graal.api.core.Rule)52 Atom (fr.lirmm.graphik.graal.api.core.Atom)41 Prefix (fr.lirmm.graphik.util.Prefix)23 OWL2ParserException (fr.lirmm.graphik.graal.io.owl.OWL2ParserException)13 CloseableIteratorWithoutException (fr.lirmm.graphik.util.stream.CloseableIteratorWithoutException)13 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)13 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)10 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)4 Term (fr.lirmm.graphik.graal.api.core.Term)4