use of fr.lirmm.graphik.graal.api.core.Variable in project graal by graphik-team.
the class DefaultScheduler method execute.
@Override
public VarSharedData[] execute(InMemoryAtomSet h, List<Term> ans, AtomSet data, RulesCompilation rc) {
Set<Variable> terms = h.getVariables();
VarSharedData[] vars = new VarSharedData[terms.size() + 2];
int level = 0;
vars[level] = new VarSharedData(level);
Set<Term> alreadyAffected = new TreeSet<Term>();
for (Term t : ans) {
if (t instanceof Variable && !alreadyAffected.contains(t)) {
++level;
vars[level] = new VarSharedData(level);
vars[level].value = (Variable) t;
alreadyAffected.add(t);
}
}
int lastAnswerVariable = level;
for (Term t : terms) {
if (!alreadyAffected.contains(t)) {
++level;
vars[level] = new VarSharedData(level);
vars[level].value = (Variable) t;
}
}
++level;
vars[level] = new VarSharedData(level);
vars[level].previousLevel = lastAnswerVariable;
return vars;
}
use of fr.lirmm.graphik.graal.api.core.Variable in project graal by graphik-team.
the class FrontierRestrictedChaseHaltingConditionTest method test.
@Test
public void test() throws IteratorException, HomomorphismFactoryException, HomomorphismException {
InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create(DlgpParser.parseAtom("p(a,b)."));
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, a);
s.put(y, atom1.getTerm(1));
toAdd = condition.apply(rule, s, atomset);
Assert.assertFalse(toAdd.hasNext());
toAdd.close();
}
use of fr.lirmm.graphik.graal.api.core.Variable in project graal by graphik-team.
the class OWLEquivalentClassExpressionVisitorImpl method visit.
@Override
public InMemoryAtomSet visit(OWLDataSomeValuesFrom arg) {
Variable newGlueVariable = varGen.getFreshSymbol();
InMemoryAtomSet atomset = arg.getProperty().accept(new OWLPropertyExpressionVisitorImpl(glueVariable, newGlueVariable));
if (!arg.getFiller().equals(DF.getTopDatatype())) {
atomset.addAll(arg.getFiller().accept(new OWLEquivalentDataRangeVisitorImpl(newGlueVariable)));
}
return atomset;
}
use of fr.lirmm.graphik.graal.api.core.Variable in project graal by graphik-team.
the class Atom2SubstitutionConverterTest method basic2.
@Test
public void basic2() throws ParseException {
// given
Predicate p = DefaultPredicateFactory.instance().create("p", 3);
Variable x = DefaultTermFactory.instance().createVariable("X");
Variable y = DefaultTermFactory.instance().createVariable("Y");
Variable z = DefaultTermFactory.instance().createVariable("Z");
Atom queryAtom = new DefaultAtom(p, x, y, z);
List<Term> ansList = new LinkedList<>();
ansList.add(x);
ansList.add(z);
// when
Converter<Atom, Substitution> converter = new Atom2SubstitutionConverter(queryAtom, ansList);
Substitution s = null;
try {
s = converter.convert(DlgpParser.parseAtom("p(a,b,c)."));
} catch (ConversionException e) {
fail();
}
// then
Constant a = DefaultTermFactory.instance().createConstant("a");
Constant c = DefaultTermFactory.instance().createConstant("c");
assertEquals(a, s.createImageOf(x));
assertEquals(y, s.createImageOf(y));
assertEquals(c, s.createImageOf(z));
}
use of fr.lirmm.graphik.graal.api.core.Variable in project graal by graphik-team.
the class Atom2SubstitutionConverterTest method githubIssue2.
@Test
public void githubIssue2() throws ParseException {
// given
Predicate p = DefaultPredicateFactory.instance().create("p", 1);
Variable x = DefaultTermFactory.instance().createVariable("X");
Variable y = DefaultTermFactory.instance().createVariable("Y");
Atom queryAtom = new DefaultAtom(p, x);
List<Term> ansList = new LinkedList<>();
ansList.add(y);
// when
Converter<Atom, Substitution> converter = new Atom2SubstitutionConverter(queryAtom, ansList);
Substitution s = null;
try {
s = converter.convert(DlgpParser.parseAtom("p(a)."));
} catch (ConversionException e) {
fail();
}
// then
assertEquals(x, s.createImageOf(x));
assertEquals(y, s.createImageOf(y));
}
Aggregations