Search in sources :

Example 51 with InMemoryAtomSet

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

the class AtomSetUtils method sep.

/**
 * Return the terms occuring both in Q\P and P
 */
public static LinkedList<Term> sep(InMemoryAtomSet a1, InMemoryAtomSet a2) {
    InMemoryAtomSet pBar = minus(a2, a1);
    LinkedList<Term> sep = new LinkedList<Term>();
    for (Term t : pBar.getTerms()) {
        for (Term x : a2.getTerms()) if (x.equals(t))
            sep.add(t);
    }
    return sep;
}
Also used : InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Term(fr.lirmm.graphik.graal.api.core.Term) LinkedList(java.util.LinkedList)

Example 52 with InMemoryAtomSet

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

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

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

the class OWL2ParserTest method classAssertion.

// /////////////////////////////////////////////////////////////////////////
// ASSERTIONS
// /////////////////////////////////////////////////////////////////////////
@Test
public void classAssertion() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + ":i1 a :A ." + "");
    int nbFacts = 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));
        }
    }
    parser.close();
    Assert.assertEquals("Number of assertions found:", 1, nbFacts);
}
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 55 with InMemoryAtomSet

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

InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)122 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)40 Atom (fr.lirmm.graphik.graal.api.core.Atom)38 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)35 Test (org.junit.Test)35 Term (fr.lirmm.graphik.graal.api.core.Term)31 Rule (fr.lirmm.graphik.graal.api.core.Rule)25 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)23 LinkedList (java.util.LinkedList)22 DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)21 Variable (fr.lirmm.graphik.graal.api.core.Variable)19 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)10 DefaultNegativeConstraint (fr.lirmm.graphik.graal.core.DefaultNegativeConstraint)10 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)9 Theory (org.junit.experimental.theories.Theory)9 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)8 DefaultConjunctiveQueryWithNegatedParts (fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts)8 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)8 OWL2Parser (fr.lirmm.graphik.graal.io.owl.OWL2Parser)7 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)6