Search in sources :

Example 26 with LinkedListAtomSet

use of fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet in project graal by graphik-team.

the class NaturalRDBMSStore method atomsByPredicate.

@Override
public CloseableIterator<Atom> atomsByPredicate(Predicate p) throws AtomSetException {
    if (!this.check(p)) {
        return Iterators.<Atom>emptyIterator();
    }
    List<Term> terms = new LinkedList<Term>();
    for (int i = 0; i < p.getArity(); ++i) {
        terms.add(DefaultTermFactory.instance().createVariable("X" + i));
    }
    Atom atom = DefaultAtomFactory.instance().create(p, terms);
    ConjunctiveQuery query = DefaultConjunctiveQueryFactory.instance().create(new LinkedListAtomSet(atom));
    SqlHomomorphism solver = SqlHomomorphism.instance();
    try {
        return new SubstitutionIterator2AtomIterator(atom, solver.execute(query, this));
    } catch (HomomorphismException e) {
        throw new AtomSetException(e);
    }
}
Also used : HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) SqlHomomorphism(fr.lirmm.graphik.graal.store.rdbms.homomorphism.SqlHomomorphism) Term(fr.lirmm.graphik.graal.api.core.Term) SubstitutionIterator2AtomIterator(fr.lirmm.graphik.graal.core.stream.SubstitutionIterator2AtomIterator) Atom(fr.lirmm.graphik.graal.api.core.Atom) LinkedList(java.util.LinkedList) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)

Example 27 with LinkedListAtomSet

use of fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet in project graal by graphik-team.

the class ConjunctiveQueryTest method booleanQueryTest.

/**
 * Test a boolean query
 */
@Theory
public void booleanQueryTest(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
    try {
        store.addAll(DlgpParser.parseAtomSet("<P>(a,b).<P>(b,c).<Q>(a,c).<Q>(d,c)."));
        InMemoryAtomSet queryAtomSet = new LinkedListAtomSet();
        queryAtomSet.add(DlgpParser.parseAtom("<Q>(a,c)."));
        ConjunctiveQuery query = DefaultConjunctiveQueryFactory.instance().create(queryAtomSet);
        CloseableIterator<Substitution> subReader;
        Substitution sub;
        subReader = h.execute(query, store);
        Assert.assertTrue(subReader.hasNext());
        sub = subReader.next();
        Assert.assertEquals(0, sub.getTerms().size());
        Assert.assertFalse(subReader.hasNext());
        subReader.close();
    } catch (Exception e) {
        Assert.assertTrue(e.getMessage(), false);
    }
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Theory(org.junit.experimental.theories.Theory)

Example 28 with LinkedListAtomSet

use of fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet in project graal by graphik-team.

the class ConjunctiveQueryTest method booleanQueryWithoutAnswerTest.

/**
 * Test a boolean query
 */
@Theory
public void booleanQueryWithoutAnswerTest(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
    try {
        InMemoryAtomSet queryAtomSet = new LinkedListAtomSet();
        queryAtomSet.add(DlgpParser.parseAtom("<Q>(a,c)."));
        ConjunctiveQuery query = DefaultConjunctiveQueryFactory.instance().create(queryAtomSet);
        CloseableIterator<Substitution> subReader;
        subReader = h.execute(query, store);
        Assert.assertFalse(subReader.hasNext());
        subReader.close();
    } catch (Exception e) {
        Assert.assertTrue(e.getMessage(), false);
    }
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Theory(org.junit.experimental.theories.Theory)

Example 29 with LinkedListAtomSet

use of fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet in project graal by graphik-team.

the class LiteralsTest method doubleType.

@Theory
public void doubleType(AtomSet store) throws Exception {
    Atom a = DlgpParser.parseAtom("<AGE>(a,5.2E20).");
    store.add(a);
    ConjunctiveQuery q = new DefaultConjunctiveQuery(new LinkedListAtomSet(a), Collections.<Term>emptyList());
    Assert.assertTrue(SmartHomomorphism.instance().execute(q, store).hasNext());
    Atom b = store.iterator().next();
    Assert.assertEquals(a, b);
}
Also used : DefaultConjunctiveQuery(fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) Atom(fr.lirmm.graphik.graal.api.core.Atom) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) DefaultConjunctiveQuery(fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery) Theory(org.junit.experimental.theories.Theory)

Example 30 with LinkedListAtomSet

use of fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet in project graal by graphik-team.

the class LiteralsTest method booleanType.

@Theory
public void booleanType(AtomSet store) throws Exception {
    Atom a = DlgpParser.parseAtom("<IS_HUMAN>(a,true).");
    store.add(a);
    ConjunctiveQuery q = new DefaultConjunctiveQuery(new LinkedListAtomSet(a), Collections.<Term>emptyList());
    Assert.assertTrue(SmartHomomorphism.instance().execute(q, store).hasNext());
    Atom b = store.iterator().next();
    Assert.assertEquals(a, b);
}
Also used : DefaultConjunctiveQuery(fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) Atom(fr.lirmm.graphik.graal.api.core.Atom) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) DefaultConjunctiveQuery(fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery) Theory(org.junit.experimental.theories.Theory)

Aggregations

LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)52 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)35 Atom (fr.lirmm.graphik.graal.api.core.Atom)28 LinkedList (java.util.LinkedList)19 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)18 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)17 Term (fr.lirmm.graphik.graal.api.core.Term)17 DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)11 Theory (org.junit.experimental.theories.Theory)11 DefaultConjunctiveQuery (fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery)9 Test (org.junit.Test)9 Variable (fr.lirmm.graphik.graal.api.core.Variable)8 DefaultConjunctiveQueryWithNegatedParts (fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts)8 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)7 Rule (fr.lirmm.graphik.graal.api.core.Rule)6 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)5 SubstitutionIterator2AtomIterator (fr.lirmm.graphik.graal.core.stream.SubstitutionIterator2AtomIterator)5 SqlHomomorphism (fr.lirmm.graphik.graal.store.rdbms.homomorphism.SqlHomomorphism)5 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)4 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)4