use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class AbstractSubstitution method createImageOf.
@Override
public Rule createImageOf(Rule rule) {
Rule substitut = DefaultRuleFactory.instance().create();
this.apply(rule.getBody(), substitut.getBody());
this.apply(rule.getHead(), substitut.getHead());
return substitut;
}
use of fr.lirmm.graphik.graal.api.core.Rule 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;
}
use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class OWLAxiomParser method equivalentPropertiesAxiom.
private Iterable<? extends Object> equivalentPropertiesAxiom(Iterable<? extends OWLPropertyExpression> properties) {
Collection<Rule> rules = GraalUtils.<Rule>createCollection();
InMemoryAtomSet a1, a2;
Iterator<? extends OWLPropertyExpression> it1, it2;
it1 = properties.iterator();
while (it1.hasNext()) {
OWLPropertyExpression propExpr = (OWLPropertyExpression) it1.next();
a1 = propExpr.accept(propertyVisitorXY);
it1.remove();
it2 = properties.iterator();
while (it2.hasNext()) {
OWLPropertyExpression next = (OWLPropertyExpression) it2.next();
a2 = next.accept(propertyVisitorXY);
rules.add(DefaultRuleFactory.instance().create(a1, a2));
rules.add(DefaultRuleFactory.instance().create(a2, a1));
}
}
return rules;
}
use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class OWLAxiomParser method mainProcess.
private Iterable<? extends Rule> mainProcess(OWLSubClassOfAxiom arg) {
Collection<Rule> objects = new LinkedList<Rule>();
InMemoryAtomSet body = null;
try {
body = arg.getSubClass().accept(this.classVisitorX);
} catch (UnsupportedConstructor e) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("[ " + arg.getSubClass() + "] is not supported as subClass. This axioms was skipped : " + arg);
}
return Collections.emptyList();
}
// RULES
InMemoryAtomSet head = null;
try {
if (arg.getSuperClass() instanceof OWLObjectMaxCardinality) {
OWLObjectMaxCardinality maxCard = (OWLObjectMaxCardinality) arg.getSuperClass();
body.addAll(maxCard.getProperty().accept(this.propertyVisitorXY));
body.addAll(maxCard.getProperty().accept(this.propertyVisitorXZ));
InMemoryAtomSet bodyTemplate = body;
head = GraalUtils.createAtomSet(DefaultAtomFactory.instance().create(Predicate.EQUALITY, glueVarY, glueVarZ));
OWLClassExpression expr = OWLAPIUtils.classExpressionDisjunctiveNormalForm(maxCard.getFiller());
for (Pair<OWLClassExpression, OWLClassExpression> pair : MathUtils.selfCartesianProduct(OWLAPIUtils.getObjectUnionOperands(expr))) {
body = new LinkedListAtomSet(bodyTemplate);
body.addAll(pair.getLeft().accept(classVisitorY));
body.addAll(pair.getRight().accept(classVisitorZ));
objects.add(DefaultRuleFactory.instance().create(body, head));
}
} else if (arg.getSuperClass() instanceof OWLDataMaxCardinality) {
OWLDataMaxCardinality maxCard = (OWLDataMaxCardinality) arg.getSuperClass();
Predicate p = GraalUtils.createPredicate(maxCard.getProperty());
body.add(DefaultAtomFactory.instance().create(p, glueVarX, glueVarY));
body.add(DefaultAtomFactory.instance().create(p, glueVarX, glueVarZ));
InMemoryAtomSet bodyTemplate = body;
head = GraalUtils.createAtomSet(DefaultAtomFactory.instance().create(Predicate.EQUALITY, glueVarY, glueVarZ));
OWLDataRange expr = OWLAPIUtils.dataRangeDisjunctiveNormalForm(maxCard.getFiller());
for (Pair<OWLDataRange, OWLDataRange> pair : MathUtils.selfCartesianProduct(OWLAPIUtils.getDataUnionOperands(expr))) {
body = new LinkedListAtomSet(bodyTemplate);
body.addAll(pair.getLeft().accept(dataRangeVisitorY));
body.addAll(pair.getRight().accept(dataRangeVisitorZ));
objects.add(DefaultRuleFactory.instance().create(body, head));
}
} else if (arg.getSuperClass() instanceof OWLDataAllValuesFrom) {
OWLDataAllValuesFrom allvalues = (OWLDataAllValuesFrom) arg.getSuperClass();
Predicate p = GraalUtils.createPredicate(allvalues.getProperty());
body.add(DefaultAtomFactory.instance().create(p, glueVarX, glueVarY));
head = allvalues.getFiller().accept(dataRangeVisitorY);
objects.add(DefaultRuleFactory.instance().create(body, head));
} else {
head = arg.getSuperClass().accept(this.classVisitorX);
objects.add(DefaultRuleFactory.instance().create(body, head));
}
} catch (UnsupportedConstructor e) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("[ " + e.getConstructor() + "] is not supported here. This axioms was skipped : " + arg);
}
objects = Collections.emptyList();
}
return objects;
}
use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class SparqlRuleParser method execute.
// /////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
// /////////////////////////////////////////////////////////////////////////
private void execute(String sparqlQuery) {
Query sparql = QueryFactory.create(sparqlQuery);
this.prefixes = new LinkedList<Prefix>();
for (Map.Entry<String, String> e : sparql.getPrefixMapping().getNsPrefixMap().entrySet()) {
this.prefixes.add(new Prefix(e.getKey(), e.getValue()));
}
Rule rule = new DefaultRule();
if (sparql.isConstructType()) {
Template template = sparql.getConstructTemplate();
for (Triple triple : template.getTriples()) {
rule.getHead().add(SparqlUtils.triple2Atom(triple));
}
}
ElementVisitorImpl visitor = new ElementVisitorImpl(rule.getBody());
sparql.getQueryPattern().visit(visitor);
this.rule = rule;
}
Aggregations