Search in sources :

Example 81 with Term

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

Example 82 with Term

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

Example 83 with Term

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;
}
Also used : InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Term(fr.lirmm.graphik.graal.api.core.Term) LinkedList(java.util.LinkedList)

Example 84 with Term

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

Example 85 with Term

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)));
}
Also used : DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Term(fr.lirmm.graphik.graal.api.core.Term) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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