Search in sources :

Example 16 with LinkedListAtomSet

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

the class ConjunctiveQueryTest method emptyQueryTest.

/**
 * Test an empty query that must have an empty substitution
 */
@Theory
public void emptyQueryTest(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
    try {
        store.addAll(DlgpParser.parseAtomSet("<P>(a,b), <P>(b,c), <Q>(c,a)."));
        InMemoryAtomSet queryAtomSet = new LinkedListAtomSet();
        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 17 with LinkedListAtomSet

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

the class ConjunctiveQueryTest method emptyQueryAndEmptyAtomSetTest.

/**
 * Test an empty query with an empty atomSet that must have an empty
 * substitution
 */
@Theory
public void emptyQueryAndEmptyAtomSetTest(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
    try {
        InMemoryAtomSet queryAtomSet = new LinkedListAtomSet();
        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 18 with LinkedListAtomSet

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

the class LiteralsTest method integerType.

@Theory
public void integerType(AtomSet store) throws Exception {
    Atom a = DlgpParser.parseAtom("<AGE>(a,1).");
    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 19 with LinkedListAtomSet

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

the class DefaultConjunctiveQueryFactory method create.

@Override
public ConjunctiveQuery create(Atom atom, List<Term> ans) {
    LinkedList<Atom> list = new LinkedList<Atom>();
    list.add(atom);
    return new DefaultConjunctiveQuery(new LinkedListAtomSet(list), ans);
}
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) LinkedList(java.util.LinkedList)

Example 20 with LinkedListAtomSet

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

the class AbstractMapper method map.

@Override
public InMemoryAtomSet map(InMemoryAtomSet atomset) {
    InMemoryAtomSet mapped;
    try {
        mapped = atomset.getClass().newInstance();
    } catch (InstantiationException e) {
        mapped = new LinkedListAtomSet();
    } catch (IllegalAccessException e) {
        mapped = new LinkedListAtomSet();
    }
    CloseableIteratorWithoutException<Atom> it = atomset.iterator();
    while (it.hasNext()) {
        mapped.add(this.map(it.next()));
    }
    it.close();
    return mapped;
}
Also used : InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) Atom(fr.lirmm.graphik.graal.api.core.Atom)

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