Search in sources :

Example 16 with Atom

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();
}
Also used : DefaultConjunctiveQueryWithNegatedParts(fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts) Variable(fr.lirmm.graphik.graal.api.core.Variable) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) 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) Atom(fr.lirmm.graphik.graal.api.core.Atom) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 17 with Atom

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());
}
Also used : Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 18 with Atom

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());
}
Also used : Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 19 with Atom

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));
}
Also used : ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 20 with Atom

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);
}
Also used : Term(fr.lirmm.graphik.graal.api.core.Term) Atom(fr.lirmm.graphik.graal.api.core.Atom) NegativeConstraint(fr.lirmm.graphik.graal.api.core.NegativeConstraint) 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