Search in sources :

Example 96 with Term

use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.

the class DlgpWriter method write.

@Override
public DlgpWriter write(ConjunctiveQuery query) throws IOException {
    if (!query.getLabel().isEmpty()) {
        this.writeLabel(query.getLabel());
    }
    this.write('?');
    Collection<Term> avars = query.getAnswerVariables();
    if (!avars.isEmpty()) {
        boolean isFirst = true;
        this.write('(');
        for (Term t : avars) {
            if (isFirst) {
                isFirst = false;
            } else {
                this.write(',');
            }
            this.writeTerm(t);
        }
        this.write(')');
    }
    this.write(" :- ");
    this.writeAtomSet(query.getAtomSet().iterator(), false);
    this.write(".\n");
    return this;
}
Also used : Term(fr.lirmm.graphik.graal.api.core.Term)

Example 97 with Term

use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.

the class OWL2ParserTest method assertionObjectProperty.

@Test
public void assertionObjectProperty() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ObjectProperty . " + ":i1 :p :i2 ." + "");
    boolean found = false;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (!(o instanceof Prefix)) {
            InMemoryAtomSet atomset = (InMemoryAtomSet) o;
            Atom a = atomset.iterator().next();
            Assert.assertEquals(P, a.getPredicate());
            Iterator<Term> it = a.iterator();
            Assert.assertEquals(I1, it.next());
            Assert.assertEquals(I2, it.next());
            found = true;
        }
    }
    parser.close();
    Assert.assertTrue("Number of assertions found:", found);
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Prefix(fr.lirmm.graphik.util.Prefix) Term(fr.lirmm.graphik.graal.api.core.Term) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 98 with Term

use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.

the class DlgpParserTest method parseQueryWithStringLiteralInAns.

@Test
public void parseQueryWithStringLiteralInAns() throws ParseException {
    ConjunctiveQuery q = DlgpParser.parseQuery("?(\"string\",X) :- p(a,X).");
    List<Term> ans = q.getAnswerVariables();
    Assert.assertEquals(LSTRING, ans.get(0));
    Assert.assertEquals(X, ans.get(1));
    Atom a = q.getAtomSet().iterator().next();
    Assert.assertEquals(A, a.getTerm(0));
    Assert.assertEquals(X, a.getTerm(1));
}
Also used : Term(fr.lirmm.graphik.graal.api.core.Term) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 99 with Term

use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.

the class DlgpParserTest method parseAtomSetException.

@Test(expected = DlgpParseException.class)
public void parseAtomSetException() throws ParseException, IteratorException {
    CloseableIterator<Atom> it = DlgpParser.parseAtomSet("p(a). p(b) 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)

Example 100 with Term

use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.

the class DlgpParserTest method parseAtomSet.

// /////////////////////////////////////////////////////////////////////////
// ATOMSET
// /////////////////////////////////////////////////////////////////////////
@Test
public void parseAtomSet() throws ParseException, IteratorException {
    CloseableIterator<Atom> it = DlgpParser.parseAtomSet("p(a). p(b), 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

Term (fr.lirmm.graphik.graal.api.core.Term)173 Atom (fr.lirmm.graphik.graal.api.core.Atom)86 LinkedList (java.util.LinkedList)41 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)36 Test (org.junit.Test)35 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)34 Variable (fr.lirmm.graphik.graal.api.core.Variable)32 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)27 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)26 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)23 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)18 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)15 Rule (fr.lirmm.graphik.graal.api.core.Rule)15 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)14 TreeSet (java.util.TreeSet)12 Constant (fr.lirmm.graphik.graal.api.core.Constant)9 DBTable (fr.lirmm.graphik.graal.store.rdbms.util.DBTable)9 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9 TreeMap (java.util.TreeMap)8