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