use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.
the class HomomorphismTest method test6.
@Test
public void test6() throws HomomorphismException, IteratorException, AtomSetException {
InMemoryAtomSet data = new DefaultInMemoryGraphStore();
data.addAll(DlgpParser.parseAtomSet("p(a,b), q(b), p(a,c), r(a,d), q(d), r(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);
Assert.assertTrue(res.hasNext());
res.next();
Assert.assertFalse(res.hasNext());
res.close();
}
use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.
the class DlgpParserTest method parseAtom.
// /////////////////////////////////////////////////////////////////////////
// ATOM
// /////////////////////////////////////////////////////////////////////////
@Test
public void parseAtom() throws ParseException {
Atom a = DlgpParser.parseAtom("p(a, X).");
Assert.assertTrue(a.getTerm(1).isVariable());
}
use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.
the class DlgpParserTest method uriValide.
@Test
public void uriValide() throws ParseException {
String uri = "/a//a///a////a/////a//////" + "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "´áéíóúýàèìòùỳ¨äëïöüÿâêîôûŷ" + "?¿.:,;!¡~'" + "0123456789₀₁₂₃₄₅₆₇₈₉₍₎₊₋₌ₐₑₒₓₔ⁰¹⁴⁵⁶⁷⁸⁹⁺⁽⁾⁼⁻" + "+-*%=()[]«»_—–#" + "ßæœçåÅøØĐħĦ" + "€$¤£" + "¶¦¬©®™ªº♯♮♭" + "ΑΒΔΕΦΓΗΙΘΚΛΜΝΟΠΧΡΣΤΥΩΞΨΖαβδεφγηιθκλμνοπχρστυωξψζ" + "‰≃≠≮≯≤≥≰≱≲≳Ω¼½¾ƒℓ⅓⅔⅛⅜⅝⅞⩽⩾←↑→↓↔↦⇒⇔∂∙∏∑∆∇√∞∫≈≡∀∃∈∉∪∩⊂⊃♀♂ℝℂℚℕℤℍ⊥‖∧∨⟦⟧⟨⟩∘" + // unbreakable
" " + // spaces
"////";
Atom a = DlgpParser.parseAtom("<" + uri + ">(<" + uri + ">).");
Assert.assertEquals(uri, a.getPredicate().getIdentifier().toString());
Assert.assertEquals(uri, a.getTerm(0).getIdentifier().toString());
}
use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.
the class DlgpParserTest method parseQueryWithPrefix.
@Test
public void parseQueryWithPrefix() throws ParseException {
ConjunctiveQuery q = DlgpParser.parseQuery("@prefix ex: <http://example.com/> ?(X) :- ex:p(a,X).");
Assert.assertEquals(X, q.getAnswerVariables().get(0));
Atom a = q.getAtomSet().iterator().next();
Assert.assertEquals(A, a.getTerm(0));
Assert.assertEquals(X, a.getTerm(1));
}
use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.
the class DlgpParserTest method parseAtomSetWithPrefix.
@Test
public void parseAtomSetWithPrefix() throws ParseException, IteratorException {
CloseableIterator<Atom> it = DlgpParser.parseAtomSet("@prefix ex: <http://example.com/> ex:p(a). ex:p(b), ex:p(1).");
int cpt = 0;
while (it.hasNext()) {
++cpt;
Atom a = it.next();
Term t = a.getTerm(0);
Assert.assertTrue(t.equals(B) || t.equals(A) || t.equals(L1));
}
Assert.assertEquals(3, cpt);
}
Aggregations