use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.
the class SparqlConjunctiveQueryWriter method write.
@Override
public SparqlConjunctiveQueryWriter write(ConjunctiveQuery query) throws IOException {
this.write("SELECT DISTINCT ");
for (Term t : query.getAnswerVariables()) {
this.write(t);
this.write(' ');
}
this.write("\nWHERE\n{\n");
boolean isFirst = true;
CloseableIteratorWithoutException<Atom> it = query.getAtomSet().iterator();
while (it.hasNext()) {
Atom a = it.next();
if (!isFirst) {
this.write(" .\n");
} else {
isFirst = false;
}
this.writeAtom(a);
}
this.write("\n}\n");
return this;
}
use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.
the class SparqlRuleWriter method writeAtomSet.
// /////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
// /////////////////////////////////////////////////////////////////////////
private void writeAtomSet(InMemoryAtomSet atomset) throws IOException {
this.write(" {\n");
boolean isFirst = true;
CloseableIteratorWithoutException<Atom> it = atomset.iterator();
while (it.hasNext()) {
Atom a = it.next();
if (!isFirst) {
this.write(" .\n");
} else {
isFirst = false;
}
this.writeAtom(a);
}
this.write("\n }\n");
}
use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.
the class SparqlRuleTest method testStringLiteral.
@Test
public void testStringLiteral() {
String query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" + "PREFIX : <" + PREFIX + ">" + "CONSTRUCT" + "{" + " ?x :q 'toto' " + "}" + "WHERE" + "{" + " ?x :p 'toto' ." + "}";
Rule rule = new SparqlRuleParser(query).getRule();
CloseableIteratorWithoutException<Atom> it = rule.getBody().iterator();
while (it.hasNext()) {
Atom a = it.next();
Assert.assertEquals(P, a.getPredicate());
Assert.assertEquals(STRING, a.getTerm(1));
}
it = rule.getHead().iterator();
while (it.hasNext()) {
Atom a = it.next();
Assert.assertEquals(Q, a.getPredicate());
Assert.assertEquals(STRING, a.getTerm(1));
}
}
use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.
the class SparqlRuleTest method testRDFType.
@Test
public void testRDFType() {
String query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" + "PREFIX : <" + PREFIX + ">" + "CONSTRUCT" + "{" + " ?x rdf:type :B " + "}" + "WHERE" + "{" + " ?x a :A ." + "}";
Rule rule = new SparqlRuleParser(query).getRule();
CloseableIteratorWithoutException<Atom> it = rule.getBody().iterator();
while (it.hasNext()) {
Atom a = it.next();
Assert.assertEquals(A, a.getPredicate());
}
it = rule.getHead().iterator();
while (it.hasNext()) {
Atom a = it.next();
Assert.assertEquals(B, a.getPredicate());
}
}
use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.
the class DefaultKnowledgeBaseTest method testDefaultKnowledgeBaseParserOfObject.
/**
* Test method for
* {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#DefaultKnowledgeBase(fr.lirmm.graphik.graal.api.io.Parser)}.
*
* @throws ParseException
* @throws AtomSetException
*/
@Test
public void testDefaultKnowledgeBaseParserOfObject() throws ParseException, AtomSetException {
Atom aa = DlgpParser.parseAtom("q(a).");
Atom ab = DlgpParser.parseAtom("q(b).");
Atom ac = DlgpParser.parseAtom("q(c).");
Rule r = DlgpParser.parseRule("[R] p(X) :- q(X).");
NegativeConstraint nc = DlgpParser.parseNegativeConstraint("[NC] ! :- q(X), p(X).");
KnowledgeBase kb = new DefaultKnowledgeBase(new DlgpParser("[R] p(X) :- q(X). q(a), q(b). q(c). [NC] ! :- q(X), p(X)."));
Assert.assertTrue(kb.getOntology().contains(r));
Assert.assertTrue(kb.getOntology().contains(nc));
Assert.assertTrue(kb.getFacts().contains(aa));
Assert.assertTrue(kb.getFacts().contains(ab));
Assert.assertTrue(kb.getFacts().contains(ac));
kb.close();
}
Aggregations