Search in sources :

Example 11 with OWL2Parser

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

the class OWL2ParserTest method symetricObjectPropertyOf.

@Test
public void symetricObjectPropertyOf() {
    // p(X, Y) :- p(Y, X).
    try {
        OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:SymmetricProperty . ");
        int nbRules = 0;
        while (parser.hasNext()) {
            Object o = parser.next();
            if (o instanceof Rule) {
                ++nbRules;
                Rule r = (Rule) o;
                CloseableIteratorWithoutException<Atom> it = r.getBody().iterator();
                Atom b = (Atom) it.next();
                Assert.assertFalse(it.hasNext());
                it = r.getHead().iterator();
                Atom h = (Atom) it.next();
                Assert.assertFalse(it.hasNext());
                Assert.assertEquals(P, b.getPredicate());
                Assert.assertEquals(P, h.getPredicate());
                Assert.assertNotEquals(b.getTerm(0), b.getTerm(1));
                Assert.assertEquals(b.getTerm(0), h.getTerm(1));
                Assert.assertEquals(b.getTerm(1), h.getTerm(0));
            }
        }
        parser.close();
        Assert.assertEquals("Number of assertions found:", 1, nbRules);
    } catch (Exception e) {
        Assert.assertFalse(e.getMessage(), true);
    }
}
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) OWL2ParserException(fr.lirmm.graphik.graal.io.owl.OWL2ParserException) CloseableIteratorWithoutException(fr.lirmm.graphik.util.stream.CloseableIteratorWithoutException) IteratorException(fr.lirmm.graphik.util.stream.IteratorException) Test(org.junit.Test)

Example 12 with OWL2Parser

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

the class OWL2ParserTest method unionOfObjectOneOf.

@Test
public void unionOfObjectOneOf() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + "[ owl:unionOf ( [ owl:oneOf ( :i1 :i2 ) ] [ owl:oneOf ( :i3 :i4 ) ] ) ] rdfs:subClassOf :A. ");
    int nbRules = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (o instanceof InMemoryAtomSet) {
            CloseableIteratorWithoutException<Atom> it = ((InMemoryAtomSet) o).iterator();
            while (it.hasNext()) {
                it.next();
                ++nbRules;
            }
        }
    }
    parser.close();
    Assert.assertEquals("Number of assertions found:", 4, nbRules);
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 13 with OWL2Parser

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

the class OWL2ParserTest method objectOneOf.

@Test
public void objectOneOf() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + "[ owl:oneOf ( :i1 :i2 :i3 ) ] rdfs:subClassOf :A . ");
    int nbRules = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (o instanceof InMemoryAtomSet) {
            CloseableIteratorWithoutException<Atom> it = ((InMemoryAtomSet) o).iterator();
            while (it.hasNext()) {
                Atom a = it.next();
                ++nbRules;
                Assert.assertTrue(a.getTerm(0).equals(I1) || a.getTerm(0).equals(I2) || a.getTerm(0).equals(I3));
                Assert.assertEquals(A, a.getPredicate());
            }
        }
    }
    parser.close();
    Assert.assertEquals("Number of assertions found:", 3, nbRules);
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 14 with OWL2Parser

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

the class OWL2ParserTest method objectMinCardinality1.

@Test
public void objectMinCardinality1() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + ":B rdf:type owl:Class . " + ":p rdf:type owl:ObjectProperty . " + " [ rdf:type owl:Restriction ; " + " owl:onProperty :p ; " + " owl:onClass :A ; " + " 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(A.equals(body1.getPredicate()) || A.equals(body2.getPredicate()));
            Assert.assertTrue(P.equals(body1.getPredicate()) || P.equals(body2.getPredicate()));
            Assert.assertTrue(A.equals(body1.getPredicate()) || P.equals(body1.getPredicate()));
            Assert.assertTrue(A.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 15 with OWL2Parser

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

the class OWL2ParserTest method complexClassAssertion.

@Test
public void complexClassAssertion() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + ":B rdf:type owl:Class . " + ":i1 a [owl:intersectionOf ( :A [owl:complementOf :B] ) ] ." + "");
    int nbFacts = 0;
    int nbConstraint = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if ((o instanceof InMemoryAtomSet)) {
            ++nbFacts;
            CloseableIteratorWithoutException<Atom> it = ((InMemoryAtomSet) o).iterator();
            Assert.assertTrue(it.hasNext());
            Atom a = it.next();
            Assert.assertEquals(A, a.getPredicate());
            Assert.assertEquals(I1, a.getTerm(0));
        }
        if ((o instanceof DefaultNegativeConstraint)) {
            ++nbConstraint;
            CloseableIteratorWithoutException<Atom> it = ((DefaultNegativeConstraint) o).getBody().iterator();
            Assert.assertTrue(it.hasNext());
            Atom a = it.next();
            Assert.assertEquals(B, a.getPredicate());
            Assert.assertEquals(I1, a.getTerm(0));
        }
    }
    parser.close();
    Assert.assertEquals("Number of assertions found:", 1, nbFacts);
    Assert.assertEquals("Number of assertions found:", 1, nbConstraint);
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Atom(fr.lirmm.graphik.graal.api.core.Atom) 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