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);
}
}
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);
}
}
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);
}
}
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);
}
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);
}
Aggregations