Search in sources :

Example 41 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 42 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 43 with OWL2Parser

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

the class OWL2ParserTest method complexDataMinCardinality0InRightHandSide.

@Test
public void complexDataMinCardinality0InRightHandSide() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":D rdf:type rdfs:Datatype . " + ":B rdf:type owl:Class . " + ":p rdf:type owl:DatatypeProperty . " + " :B rdfs:subClassOf [a owl:Restriction; owl:onProperty :p; owl:someValuesFrom [ rdf:type owl:Restriction ; " + " owl:onProperty :p ; " + " owl:onDataRange :D ; " + " owl:minCardinality 0 ] ]. ");
    int nbAssertions = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (!(o instanceof Prefix)) {
            ++nbAssertions;
        }
    }
    parser.close();
    Assert.assertEquals("Number of assertions found:", 1, nbAssertions);
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) Prefix(fr.lirmm.graphik.util.Prefix) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Test(org.junit.Test)

Example 44 with OWL2Parser

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

the class OWL2ParserTest method complexObjectMinCardinality0InRightHandSide.

@Test
public void complexObjectMinCardinality0InRightHandSide() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + ":B rdf:type owl:Class . " + ":p rdf:type owl:ObjectProperty . " + " :B rdfs:subClassOf [a owl:Restriction; owl:onProperty :p; owl:someValuesFrom [ rdf:type owl:Restriction ; " + " owl:onProperty :p ; " + " owl:onClass :A ; " + " owl:minCardinality 0 ] ]. ");
    int nbAssertions = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (!(o instanceof Prefix)) {
            ++nbAssertions;
        }
    }
    parser.close();
    Assert.assertEquals("Number of assertions found:", 1, nbAssertions);
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) Prefix(fr.lirmm.graphik.util.Prefix) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Test(org.junit.Test)

Example 45 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)71 Test (org.junit.Test)71 DefaultNegativeConstraint (fr.lirmm.graphik.graal.core.DefaultNegativeConstraint)65 Rule (fr.lirmm.graphik.graal.api.core.Rule)50 Atom (fr.lirmm.graphik.graal.api.core.Atom)41 Prefix (fr.lirmm.graphik.util.Prefix)21 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