use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class AbstractRewritingOperator method getUnifiableRules.
protected Collection<Rule> getUnifiableRules(CloseableIteratorWithoutException<Predicate> preds, IndexedByHeadPredicatesRuleSet ruleSet, RulesCompilation compilation) {
TreeSet<Rule> res = new TreeSet<Rule>(RuleOrder.instance());
TreeSet<Predicate> unifiablePreds = new TreeSet<Predicate>();
while (preds.hasNext()) {
unifiablePreds.addAll(compilation.getUnifiablePredicate(preds.next()));
}
for (Predicate pred : unifiablePreds) {
for (Rule r : ruleSet.getRulesByHeadPredicate(pred)) {
res.add(r);
}
}
return res;
}
use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class AggregSingleRuleOperator method getRewritesFrom.
// /////////////////////////////////////////////////////////////////////////
// METHODS
// /////////////////////////////////////////////////////////////////////////
/**
* Returns the rewrites compute from the given fact and the rule set of the
* receiving object.
*
* @param q
* A fact
* @return the ArrayList that contains the rewrites compute from the given
* fact and the rule set of the receiving object.
*/
@Override
public Collection<ConjunctiveQuery> getRewritesFrom(ConjunctiveQuery q, IndexedByHeadPredicatesRuleSet ruleSet, RulesCompilation compilation) {
LinkedList<ConjunctiveQuery> rewriteSet = new LinkedList<ConjunctiveQuery>();
Collection<QueryUnifier> unifiers = new LinkedList<QueryUnifier>();
for (Rule r : getUnifiableRules(q.getAtomSet().predicatesIterator(), ruleSet, compilation)) {
unifiers.addAll(getSRUnifier(q, r, compilation));
}
/**
* compute the rewrite from the unifier *
*/
ConjunctiveQuery a;
for (QueryUnifier u : unifiers) {
a = Utils.rewrite(q, u);
if (a != null) {
rewriteSet.add(a);
}
}
return rewriteSet;
}
use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class BasicAggregAllRulesOperator method getRewritesFrom.
// /////////////////////////////////////////////////////////////////////////
// METHODS
// /////////////////////////////////////////////////////////////////////////
/**
* Returns the rewrites compute from the given fact and the rule set of the
* receiving object.
*
* @param q
* A fact
* @return the ArrayList that contains the rewrites compute from the given
* fact and the rule set of the receiving object.
*/
@Override
public Collection<ConjunctiveQuery> getRewritesFrom(ConjunctiveQuery q, IndexedByHeadPredicatesRuleSet ruleSet, RulesCompilation compilation) {
LinkedList<ConjunctiveQuery> currentRewrites = new LinkedList<ConjunctiveQuery>();
LinkedList<QueryUnifier> srUnifiers = new LinkedList<QueryUnifier>();
LinkedList<QueryUnifier> unifiers = new LinkedList<QueryUnifier>();
for (Rule r : getUnifiableRules(q.getAtomSet().predicatesIterator(), ruleSet, compilation)) {
/**
* compute the single rule unifiers *
*/
srUnifiers.addAll(getSRUnifier(q, r, compilation));
}
/**
* compute the aggregated unifier *
*/
unifiers = getAggregatedUnifiers(srUnifiers);
/**
* compute the rewrite from the unifier *
*/
for (QueryUnifier u : unifiers) {
ConjunctiveQuery a = Utils.rewrite(q, u);
currentRewrites.add(a);
}
return currentRewrites;
}
use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class OWLAxiomParser method functionalPropertyAxiom.
// /////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
// /////////////////////////////////////////////////////////////////////////
private Iterable<? extends Object> functionalPropertyAxiom(OWLPropertyExpression property) {
InMemoryAtomSet body = property.accept(propertyVisitorXY);
body.addAll(property.accept(propertyVisitorXZ));
InMemoryAtomSet head = GraalUtils.createAtomSet(new DefaultAtom(equalityPredicate, glueVarY, glueVarZ));
return Collections.<Rule>singleton(DefaultRuleFactory.instance().create(body, head));
}
use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class OWLAxiomParser method visit.
// /////////////////////////////////////////////////////////////////////////
// HasKey
// /////////////////////////////////////////////////////////////////////////
@Override
public Iterable<? extends Object> visit(OWLHasKeyAxiom arg) {
// =(Y, Z) :- C(Y), C(Z), p1(Y, X1), p1(Z, X1), ..., pn(Y, Xn), pn(Z,
// Xn).
Collection<Rule> rules = GraalUtils.<Rule>createCollection();
freeVarGen.setIndex(2);
InMemoryAtomSet head = GraalUtils.createAtomSet(DefaultAtomFactory.instance().create(equalityPredicate, glueVarX, glueVarY));
OWLClassExpression classExpression = OWLAPIUtils.classExpressionDisjunctiveNormalForm(arg.getClassExpression());
for (Pair<OWLClassExpression, OWLClassExpression> pair : MathUtils.selfCartesianProduct(OWLAPIUtils.getObjectUnionOperands(classExpression))) {
InMemoryAtomSet body = pair.getLeft().accept(classVisitorX);
body.addAll(pair.getRight().accept(classVisitorY));
for (OWLObjectPropertyExpression pe : arg.getObjectPropertyExpressions()) {
Term var = freeVarGen.getFreshSymbol();
body.addAll(pe.accept(new OWLPropertyExpressionVisitorImpl(glueVarX, var)));
body.addAll(pe.accept(new OWLPropertyExpressionVisitorImpl(glueVarY, var)));
}
for (OWLDataPropertyExpression pe : arg.getDataPropertyExpressions()) {
Term var = freeVarGen.getFreshSymbol();
body.add(DefaultAtomFactory.instance().create(GraalUtils.createPredicate(pe), glueVarX, var));
body.add(DefaultAtomFactory.instance().create(GraalUtils.createPredicate(pe), glueVarY, var));
}
rules.add(DefaultRuleFactory.instance().create(body, head));
}
return rules;
}
Aggregations