Search in sources :

Example 26 with OWL2Parser

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

the class OWL2ParserTest method objectAllValuesFrom.

@Test
public void objectAllValuesFrom() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + ":B rdf:type owl:Class . " + ":p rdf:type owl:ObjectProperty . " + ":A rdfs:subClassOf [ rdf:type owl:Restriction ;" + "							owl:onProperty :p ;" + "	                        owl:allValuesFrom :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.assertTrue(!head.getTerm(0).isConstant());
            Assert.assertEquals(body1.getTerm(0), body2.getTerm(0));
            Assert.assertEquals(B, head.getPredicate());
            Assert.assertTrue(A.equals(body1.getPredicate()) || A.equals(body2.getPredicate()));
            Assert.assertTrue(P.equals(body1.getPredicate()) || P.equals(body2.getPredicate()));
            if (P.equals(body1.getPredicate())) {
                Assert.assertEquals(body1.getTerm(1), head.getTerm(0));
            } else {
                Assert.assertEquals(body2.getTerm(1), head.getTerm(0));
            }
            Assert.assertFalse(bodyIt.hasNext());
            Assert.assertFalse(headIt.hasNext());
        }
    }
    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 27 with OWL2Parser

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

the class OWL2ParserTest method equivalentProperty.

@Test
public void equivalentProperty() {
    // q(X, Y) <-> p(X, Y).
    try {
        OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ObjectProperty . " + ":q rdf:type owl:ObjectProperty . " + ":p owl:equivalentProperty :q .");
        int nbRules = 0;
        while (parser.hasNext()) {
            Object o = parser.next();
            if (o instanceof Rule) {
                ++nbRules;
                Rule r = (Rule) o;
                Atom subProperty = (Atom) r.getBody().iterator().next();
                Atom property = (Atom) r.getHead().iterator().next();
                Assert.assertTrue(Q.equals(property.getPredicate()) || P.equals(property.getPredicate()));
                Assert.assertTrue(Q.equals(subProperty.getPredicate()) || P.equals(subProperty.getPredicate()));
                Assert.assertEquals(property.getTerm(0), subProperty.getTerm(0));
                Assert.assertEquals(property.getTerm(1), subProperty.getTerm(1));
            }
        }
        parser.close();
        Assert.assertEquals("Number of assertions found:", 2, 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 28 with OWL2Parser

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

the class OWL2ParserTest method assertionDataProperty.

@Test
public void assertionDataProperty() throws OWL2ParserException, IteratorException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:DatatypeProperty . " + ":i1 :p 7 ." + "");
    boolean found = false;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (!(o instanceof Prefix)) {
            AtomSet atomset = (AtomSet) o;
            Atom a = atomset.iterator().next();
            Assert.assertEquals(P, a.getPredicate());
            Iterator<Term> it = a.iterator();
            Assert.assertEquals(I1, it.next());
            Assert.assertEquals(L1, it.next());
            found = true;
        }
    }
    parser.close();
    Assert.assertTrue("Number of assertions found:", found);
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Prefix(fr.lirmm.graphik.util.Prefix) Term(fr.lirmm.graphik.graal.api.core.Term) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 29 with OWL2Parser

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

the class OWL2ParserTest method disjointProperty.

@Test
public void disjointProperty() {
    // ! :- q(X, Y), p(X, Y).
    try {
        OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ObjectProperty . " + ":q rdf:type owl:ObjectProperty . " + ":p owl:propertyDisjointWith :q .");
        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 a1 = (Atom) it.next();
                Atom a2 = (Atom) it.next();
                Assert.assertFalse(it.hasNext());
                Assert.assertTrue(P.equals(a1.getPredicate()) || Q.equals(a1.getPredicate()));
                Assert.assertTrue(P.equals(a2.getPredicate()) || Q.equals(a2.getPredicate()));
                Assert.assertTrue(P.equals(a2.getPredicate()) || P.equals(a1.getPredicate()));
                Assert.assertTrue(Q.equals(a2.getPredicate()) || Q.equals(a1.getPredicate()));
                Assert.assertEquals(a1.getTerm(0), a2.getTerm(0));
                Assert.assertEquals(a1.getTerm(1), a2.getTerm(1));
            }
        }
        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 30 with OWL2Parser

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

the class OWL2ParserTest method objectMinCardinality0.

@Test
public void objectMinCardinality0() 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 0 ] " + "  " + " 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 body = bodyIt.next();
            Atom head = headIt.next();
            Assert.assertFalse(bodyIt.hasNext());
            Assert.assertFalse(headIt.hasNext());
            Assert.assertEquals(Predicate.TOP, body.getPredicate());
            Assert.assertEquals(B, head.getPredicate());
            Assert.assertTrue(!body.getTerm(0).isConstant());
            Assert.assertEquals(body.getTerm(0), head.getTerm(0));
        }
    }
    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)

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