use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.
the class ConjunctiveQueryWithFixedVariables method appendTo.
@Override
public void appendTo(StringBuilder sb) {
for (Constant t : this.atomSet.getConstants()) sb.append(t).append(',');
sb.append("), ANS(");
for (Term t : this.answerVariables) sb.append(t).append(',');
sb.append(") :- ");
sb.append(this.atomSet);
}
use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.
the class DefaultConjunctiveQuery method appendTo.
@Override
public void appendTo(StringBuilder sb) {
sb.append("ANS(");
boolean first = true;
for (Term t : this.responseVariables) {
if (!first) {
sb.append(',');
}
first = false;
sb.append(t);
}
sb.append(") : ");
sb.append(this.atomSet);
}
use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.
the class AtomSetUtils method sep.
/**
* Return the terms occuring both in Q\P and P
*/
public static LinkedList<Term> sep(InMemoryAtomSet a1, InMemoryAtomSet a2) {
InMemoryAtomSet pBar = minus(a2, a1);
LinkedList<Term> sep = new LinkedList<Term>();
for (Term t : pBar.getTerms()) {
for (Term x : a2.getTerms()) if (x.equals(t))
sep.add(t);
}
return sep;
}
use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.
the class PureQuery method removeAnswerPredicate.
public static void removeAnswerPredicate(ConjunctiveQuery query) {
Term[] ans = query.getAnswerVariables().toArray(new Term[query.getAnswerVariables().size()]);
CloseableIteratorWithoutException<Atom> ita = query.getAtomSet().iterator();
InMemoryAtomSet toRemove = new LinkedListAtomSet();
InMemoryAtomSet toAdd = new LinkedListAtomSet();
while (ita.hasNext()) {
Atom a = ita.next();
if (a.getPredicate().equals(ansPredicate)) {
Term ansTerm = ans[(Integer) ((Literal) a.getTerm(0)).getValue()];
if (!ansTerm.equals(a.getTerm(1))) {
toAdd.add(DefaultAtomFactory.instance().create(Predicate.EQUALITY, ansTerm, a.getTerm(1)));
}
toRemove.add(a);
}
}
query.getAtomSet().removeAll(toRemove);
query.getAtomSet().addAll(toAdd);
}
use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.
the class DlgpWriterTest method writeVariable.
@Test
public void writeVariable() throws IOException {
Term x = DefaultTermFactory.instance().createVariable("x");
ByteArrayOutputStream os = new ByteArrayOutputStream();
DlgpWriter writer = new DlgpWriter(os);
writer.write(new DefaultAtom(predicat, x));
writer.flush();
String s = new String(os.toByteArray(), "UTF-8");
writer.close();
Assert.assertTrue("Variable label does not begin with upper case.", Character.isUpperCase(s.charAt(s.indexOf("(") + 1)));
}
Aggregations