Search in sources :

Example 31 with Atom

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

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

the class OWL2ParserTest method inverseFunctionalObjectProperty.

@Test
public void inverseFunctionalObjectProperty() {
    // Y = Z :- p(Y, X), p(Z, X).
    try {
        OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:InverseFunctionalProperty . ");
        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 b1 = it.next();
                Atom b2 = it.next();
                Assert.assertFalse(it.hasNext());
                it = r.getHead().iterator();
                Atom h = it.next();
                Assert.assertFalse(it.hasNext());
                Assert.assertEquals(P, b1.getPredicate());
                Assert.assertEquals(P, b2.getPredicate());
                Assert.assertEquals(Predicate.EQUALITY, h.getPredicate());
                Assert.assertEquals(b1.getTerm(1), b2.getTerm(1));
                Assert.assertTrue(b1.getTerm(0).equals(h.getTerm(0)) || b1.getTerm(0).equals(h.getTerm(1)));
                Assert.assertTrue(b2.getTerm(0).equals(h.getTerm(0)) || b2.getTerm(0).equals(h.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 33 with Atom

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

the class OWL2ParserTest method objectInverseOf.

// /////////////////////////////////////////////////////////////////////////
// OTHERS
// /////////////////////////////////////////////////////////////////////////
@Test
public void objectInverseOf() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ObjectProperty . " + ":q rdf:type owl:ObjectProperty . " + ":p rdfs:subPropertyOf [owl:inverseOf :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.assertEquals(P, subProperty.getPredicate());
            Assert.assertEquals(Q, property.getPredicate());
            Assert.assertEquals(subProperty.getTerm(0), property.getTerm(1));
            Assert.assertEquals(subProperty.getTerm(1), property.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)

Example 34 with Atom

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

the class OWL2ParserTest method inverseObjectProperty.

@Test
public void inverseObjectProperty() {
    // q(X, Y) <-> p(Y, X).
    try {
        OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ObjectProperty . " + ":q rdf:type owl:ObjectProperty . " + ":p owl:inverseOf :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(1));
                Assert.assertEquals(property.getTerm(1), subProperty.getTerm(0));
            }
        }
        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 35 with Atom

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

the class OWL2ParserTest method objectPropertyRange.

// /////////////////////////////////////////////////////////////////////////
// 
// /////////////////////////////////////////////////////////////////////////
@Test
public void objectPropertyRange() {
    // C(Y) :- p(X, Y).
    try {
        OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ObjectProperty . " + ":A rdf:type owl:Class . " + ":p rdfs:range :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(1), 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)

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