use of fr.lirmm.graphik.graal.core.unifier.QueryUnifier in project graal by graphik-team.
the class AbstractRewritingOperator method getAggregatedUnifiers.
/**
* Returns all the aggregated unifiers compute from the given unifiers
*/
protected LinkedList<QueryUnifier> getAggregatedUnifiers(List<QueryUnifier> unifToAggregate) {
LinkedList<QueryUnifier> unifAggregated = new LinkedList<QueryUnifier>();
LinkedList<QueryUnifier> restOfUnifToAggregate = new LinkedList<QueryUnifier>(unifToAggregate);
Iterator<QueryUnifier> itr = unifToAggregate.iterator();
QueryUnifier u;
while (itr.hasNext()) {
u = itr.next();
restOfUnifToAggregate.remove(u);
// add to the result all the aggregated piece-unifier build from u
// and the rest of the mgu single piece-unifiers
unifAggregated.addAll(aggregate(u, restOfUnifToAggregate));
}
return unifAggregated;
}
use of fr.lirmm.graphik.graal.core.unifier.QueryUnifier in project graal by graphik-team.
the class AbstractRewritingOperator method aggregate.
/**
* Returns the list of all the aggregated unifiers that can be build from u
* and others unifiers of l. recursive function
*
* @param u
* the unifier whose we want aggregate with the unifiers of l
* @param l
* list of unifiers
* @return the list of all aggregated unifier build from u and unifiers of
* l
*/
@SuppressWarnings({ "unchecked" })
private LinkedList<QueryUnifier> aggregate(QueryUnifier u, LinkedList<QueryUnifier> l) {
LinkedList<QueryUnifier> lu = (LinkedList<QueryUnifier>) l.clone();
// if there is no more unifier to aggregate
if (lu.isEmpty()) {
LinkedList<QueryUnifier> res = new LinkedList<QueryUnifier>();
res.add(u);
return res;
} else {
// take the first one
QueryUnifier first = lu.getFirst();
// remove first one from lu
lu.removeFirst();
// if first can be aggregated with u
LinkedList<QueryUnifier> res = aggregate(u, lu);
if (u.isCompatible(first)) {
// System.out.println("oui");
// compute the others aggregation from the aggregation of u and
// first and the rest of lu
res.addAll(aggregate(u.aggregate(first), lu));
// concatenate this result and the others aggregations from u
// and the rest of lu
}
return res;
}
}
use of fr.lirmm.graphik.graal.core.unifier.QueryUnifier 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.core.unifier.QueryUnifier 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.core.unifier.QueryUnifier in project graal by graphik-team.
the class AggregAllRulesOperator 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>();
List<QueryUnifier> unifiers;
for (Rule r : getUnifiableRules(q.getAtomSet().predicatesIterator(), ruleSet, compilation)) {
unifiers = getSinglePieceUnifiers(q, r, compilation);
for (QueryUnifier u : unifiers) {
rewriteSet.add(Utils.rewriteWithMark(q, u));
}
}
return rewriteSet;
}
Aggregations