Search in sources :

Example 46 with Atom

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

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

the class OWL2ParserTest method dataPropertyDomainAxiom.

@Test
public void dataPropertyDomainAxiom() throws OWL2ParserException {
    // C(X) :- p(X, Y).
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:DatatypeProperty . " + ":C rdf:type owl:Class ." + ":p rdfs:domain :C .");
    boolean found = false;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (!(o instanceof Prefix)) {
            Assert.assertTrue(o instanceof Rule);
            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(C, classs.getPredicate());
            Assert.assertEquals(property.getTerm(0), classs.getTerm(0));
            found = true;
        }
    }
    parser.close();
    Assert.assertTrue("Number of assertions found:", found);
}
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) Test(org.junit.Test)

Example 48 with Atom

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

the class OWL2ParserTest method objectPropertyChain.

@Test
public void objectPropertyChain() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ObjectProperty . " + ":q rdf:type owl:ObjectProperty . " + ":r rdf:type owl:ObjectProperty . " + ":s rdf:type owl:ObjectProperty . " + "_:x rdfs:subPropertyOf :s ; " + " owl:propertyChain  ( :p :q :r ) . ");
    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 body1 = it.next();
            Atom body2 = it.next();
            Atom body3 = it.next();
            Assert.assertFalse(it.hasNext());
            Atom property = (Atom) r.getHead().iterator().next();
            Assert.assertTrue(P.equals(body1.getPredicate()) || Q.equals(body1.getPredicate()) || R.equals(body1.getPredicate()));
            Assert.assertTrue(P.equals(body2.getPredicate()) || Q.equals(body2.getPredicate()) || R.equals(body2.getPredicate()));
            Assert.assertTrue(P.equals(body3.getPredicate()) || Q.equals(body3.getPredicate()) || R.equals(body3.getPredicate()));
            Assert.assertEquals(S, property.getPredicate());
            Term x = null, y = null;
            if (P.equals(body1.getPredicate())) {
                x = body1.getTerm(0);
            } else if (P.equals(body2.getPredicate())) {
                x = body2.getTerm(0);
            } else if (P.equals(body3.getPredicate())) {
                x = body3.getTerm(0);
            }
            if (R.equals(body1.getPredicate())) {
                y = body1.getTerm(1);
            } else if (R.equals(body2.getPredicate())) {
                y = body2.getTerm(1);
            } else if (R.equals(body3.getPredicate())) {
                y = body3.getTerm(1);
            }
            Assert.assertEquals(x, property.getTerm(0));
            Assert.assertEquals(y, property.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) Term(fr.lirmm.graphik.graal.api.core.Term) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 49 with Atom

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

the class OWL2ParserTest method subObjectPropertyOf.

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

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

the class OWLPropertyExpressionVisitorImpl method visit.

@Override
public InMemoryAtomSet visit(OWLObjectProperty property) {
    Predicate p = GraalUtils.createPredicate(property);
    Atom a = DefaultAtomFactory.instance().create(p, glueVariable1, glueVariable2);
    return GraalUtils.createAtomSet(a);
}
Also used : Atom(fr.lirmm.graphik.graal.api.core.Atom) Predicate(fr.lirmm.graphik.graal.api.core.Predicate)

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