Search in sources :

Example 11 with Atom

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

the class EqualityUtilsTest method testBottomQuery2.

@Test
public void testBottomQuery2() throws ParseException {
    ConjunctiveQuery q = DlgpParser.parseQuery("?(X,Y) :- p(X,Y), X=a, X=Y, Y=b.");
    Pair<ConjunctiveQuery, Substitution> pair = EqualityUtils.processEquality(q);
    q = pair.getLeft();
    Substitution s = pair.getRight();
    // check substitution minimality
    Assert.assertTrue(s.getTerms().isEmpty());
    // check query ans part
    Assert.assertEquals(0, q.getAnswerVariables().size());
    // check query atomset
    Assert.assertEquals(1, Iterators.count(q.getAtomSet().iterator()));
    Atom atom = q.getAtomSet().iterator().next();
    Assert.assertEquals(Predicate.BOTTOM, atom.getPredicate());
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 12 with Atom

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

the class OWL2Parser method removeUselessTopInBody.

private static InMemoryAtomSet removeUselessTopInBody(InMemoryAtomSet atomset) {
    InMemoryAtomSet newAtomset = new DefaultInMemoryGraphStore();
    CloseableIteratorWithoutException<Atom> it = atomset.iterator();
    InMemoryAtomSet toRemove = new LinkedListAtomSet();
    Atom a;
    while (it.hasNext()) {
        a = it.next();
        if (!a.getPredicate().equals(Predicate.TOP)) {
            newAtomset.add(a);
            toRemove.add(a);
        } else {
        }
    }
    atomset.removeAll(toRemove);
    // for each top predicate
    Set<Term> terms = newAtomset.getTerms();
    it = atomset.iterator();
    while (it.hasNext()) {
        a = it.next();
        if (!terms.contains(a.getTerm(0))) {
            newAtomset.add(a);
        }
    }
    return newAtomset;
}
Also used : InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) Term(fr.lirmm.graphik.graal.api.core.Term) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 13 with Atom

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

the class OWL2Parser method removeUselessBottom.

/**
 * bottom and A => bottom
 *
 * @param atomset
 * @return an InMemoryAtomSet logically equivalents to the specified one.
 */
private static InMemoryAtomSet removeUselessBottom(InMemoryAtomSet atomset) {
    CloseableIteratorWithoutException<Atom> it = atomset.iterator();
    Atom a;
    while (it.hasNext()) {
        a = it.next();
        if (a.getPredicate().equals(Predicate.BOTTOM)) {
            return BOTTOM_ATOMSET;
        }
    }
    return atomset;
}
Also used : Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 14 with Atom

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

the class OWLAxiomParser method visit.

@Override
public Iterable<? extends Object> visit(OWLSameIndividualAxiom arg) {
    Collection<Atom> c = GraalUtils.<Atom>createCollection();
    LinkedList<OWLIndividual> list = new LinkedList<OWLIndividual>(arg.getIndividualsAsList());
    Iterator<OWLIndividual> it1, it2;
    it1 = list.iterator();
    while (it1.hasNext()) {
        OWLIndividual individu1 = it1.next();
        it1.remove();
        Term t1 = GraalUtils.createTerm(individu1);
        it2 = list.iterator();
        while (it2.hasNext()) {
            OWLIndividual individu2 = it2.next();
            Term t2 = GraalUtils.createTerm(individu2);
            Atom a = new DefaultAtom(equalityPredicate, t1, t2);
            c.add(a);
        }
    }
    return c;
}
Also used : DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Term(fr.lirmm.graphik.graal.api.core.Term) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Atom(fr.lirmm.graphik.graal.api.core.Atom) LinkedList(java.util.LinkedList) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual)

Example 15 with Atom

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

the class HomomorphismTest method test6Compilation.

@Test
public void test6Compilation() throws HomomorphismException, IteratorException, AtomSetException {
    InMemoryAtomSet data = new DefaultInMemoryGraphStore();
    RuleSet rules = new LinkedListRuleSet();
    rules.add(DlgpParser.parseRule("r(X,Y) :- s(X,Y)."));
    RulesCompilation comp = new IDCompilation();
    comp.compile(rules.iterator());
    data.addAll(DlgpParser.parseAtomSet("p(a,b), q(b), p(a,c), s(a,d), q(d), s(a,e)."));
    Variable y = DefaultTermFactory.instance().createVariable("Y");
    Variable z = DefaultTermFactory.instance().createVariable("Z");
    InMemoryAtomSet positivePart = new LinkedListAtomSet();
    positivePart.addAll(DlgpParser.parseAtomSet("p(X,Y),r(X,Z)."));
    CloseableIteratorWithoutException<Atom> it = positivePart.iterator();
    it.next().setTerm(1, y);
    it.next().setTerm(1, z);
    LinkedList<InMemoryAtomSet> parts = new LinkedList<InMemoryAtomSet>();
    InMemoryAtomSet negatedPart = new LinkedListAtomSet();
    negatedPart.addAll(DlgpParser.parseAtomSet("q(Y)."));
    negatedPart.iterator().next().setTerm(0, y);
    parts.add(negatedPart);
    negatedPart = new LinkedListAtomSet();
    negatedPart.addAll(DlgpParser.parseAtomSet("q(Z)."));
    negatedPart.iterator().next().setTerm(0, z);
    parts.add(negatedPart);
    DefaultConjunctiveQueryWithNegatedParts query = new DefaultConjunctiveQueryWithNegatedParts(positivePart, parts);
    BacktrackHomomorphismWithNegatedParts h = new BacktrackHomomorphismWithNegatedParts();
    CloseableIterator<Substitution> res = h.execute(query, data, comp);
    Assert.assertTrue(res.hasNext());
    res.next();
    Assert.assertFalse(res.hasNext());
    res.close();
}
Also used : RuleSet(fr.lirmm.graphik.graal.api.core.RuleSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) Variable(fr.lirmm.graphik.graal.api.core.Variable) IDCompilation(fr.lirmm.graphik.graal.core.compilation.IDCompilation) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) Atom(fr.lirmm.graphik.graal.api.core.Atom) LinkedList(java.util.LinkedList) DefaultConjunctiveQueryWithNegatedParts(fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) RulesCompilation(fr.lirmm.graphik.graal.api.core.RulesCompilation) 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