use of fr.lirmm.graphik.graal.api.core.Constant in project graal by graphik-team.
the class AbstractAtomSet method getConstants.
@Override
public Set<Constant> getConstants() throws AtomSetException {
Set<Constant> terms = new HashSet<Constant>();
CloseableIterator<Atom> atomIt = this.iterator();
try {
while (atomIt.hasNext()) {
Iterator<Term> termIt = atomIt.next().iterator();
while (termIt.hasNext()) {
Term t = termIt.next();
if (t.isConstant()) {
terms.add((Constant) t);
}
}
}
} catch (Exception e) {
throw new AtomSetException(e);
}
return terms;
}
use of fr.lirmm.graphik.graal.api.core.Constant in project graal by graphik-team.
the class FrontierRestrictedChaseHaltingConditionTest method test2.
@Test
public void test2() throws IteratorException, HomomorphismFactoryException, HomomorphismException {
InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create(DlgpParser.parseAtomSet("p(a,b), p(b,a)."));
Rule rule = DlgpParser.parseRule("p(X,Z):-p(X,Y).");
Variable x = DefaultTermFactory.instance().createVariable("X");
Variable y = DefaultTermFactory.instance().createVariable("Y");
Constant a = DefaultTermFactory.instance().createConstant("a");
Constant b = DefaultTermFactory.instance().createConstant("b");
Substitution s = DefaultSubstitutionFactory.instance().createSubstitution();
s.put(x, a);
s.put(y, b);
FrontierRestrictedChaseHaltingCondition condition = new FrontierRestrictedChaseHaltingCondition();
CloseableIterator<Atom> toAdd = condition.apply(rule, s, atomset);
Assert.assertTrue(toAdd.hasNext());
Atom atom1 = toAdd.next();
atomset.add(atom1);
Assert.assertFalse(toAdd.hasNext());
toAdd.close();
s = DefaultSubstitutionFactory.instance().createSubstitution();
s.put(x, b);
s.put(y, a);
toAdd = condition.apply(rule, s, atomset);
Assert.assertTrue(toAdd.hasNext());
Atom atom2 = toAdd.next();
atomset.add(atom2);
Assert.assertFalse(toAdd.hasNext());
toAdd.close();
Assert.assertNotEquals(atom1.getTerm(1), atom2.getTerm(1));
}
Aggregations