Search in sources :

Example 41 with Atom

use of fr.lirmm.graphik.graal.api.core.Atom 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 42 with Atom

use of fr.lirmm.graphik.graal.api.core.Atom 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 43 with Atom

use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.

the class OWL2ParserTest method objectPropertyDomain.

@Test
public void objectPropertyDomain() {
    // C(Y) :- p(X, Y).
    try {
        OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ObjectProperty . " + ":A rdf:type owl:Class . " + ":p rdfs:domain :A .");
        boolean found = false;
        while (parser.hasNext()) {
            Object o = parser.next();
            if (!(o instanceof Prefix)) {
                Rule r = (Rule) o;
                Atom property = (Atom) r.getBody().iterator().next();
                Assert.assertEquals(P, property.getPredicate());
                Atom classs = (Atom) r.getHead().iterator().next();
                Assert.assertEquals(A, classs.getPredicate());
                Assert.assertEquals(property.getTerm(0), classs.getTerm(0));
                found = true;
            }
        }
        parser.close();
        Assert.assertTrue("Number of assertions found:", found);
    } catch (Exception e) {
        Assert.assertFalse(e.getMessage(), true);
    }
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) Prefix(fr.lirmm.graphik.util.Prefix) Rule(fr.lirmm.graphik.graal.api.core.Rule) 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 44 with Atom

use of fr.lirmm.graphik.graal.api.core.Atom 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 45 with Atom

use of fr.lirmm.graphik.graal.api.core.Atom 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)

Aggregations

Atom (fr.lirmm.graphik.graal.api.core.Atom)269 Test (org.junit.Test)97 Term (fr.lirmm.graphik.graal.api.core.Term)86 Rule (fr.lirmm.graphik.graal.api.core.Rule)64 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)41 OWL2Parser (fr.lirmm.graphik.graal.io.owl.OWL2Parser)41 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)40 LinkedList (java.util.LinkedList)40 DefaultNegativeConstraint (fr.lirmm.graphik.graal.core.DefaultNegativeConstraint)36 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)35 Theory (org.junit.experimental.theories.Theory)35 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)34 Variable (fr.lirmm.graphik.graal.api.core.Variable)33 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)31 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)29 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)28 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)27 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)14 CloseableIteratorWithoutException (fr.lirmm.graphik.util.stream.CloseableIteratorWithoutException)14 OWL2ParserException (fr.lirmm.graphik.graal.io.owl.OWL2ParserException)13