Search in sources :

Example 1 with Rule

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;
}
Also used : TreeSet(java.util.TreeSet) AtomicHeadRule(fr.lirmm.graphik.graal.core.unifier.AtomicHeadRule) Rule(fr.lirmm.graphik.graal.api.core.Rule) Predicate(fr.lirmm.graphik.graal.api.core.Predicate)

Example 2 with Rule

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;
}
Also used : QueryUnifier(fr.lirmm.graphik.graal.core.unifier.QueryUnifier) Rule(fr.lirmm.graphik.graal.api.core.Rule) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) LinkedList(java.util.LinkedList)

Example 3 with Rule

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;
}
Also used : QueryUnifier(fr.lirmm.graphik.graal.core.unifier.QueryUnifier) Rule(fr.lirmm.graphik.graal.api.core.Rule) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) LinkedList(java.util.LinkedList)

Example 4 with Rule

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));
}
Also used : DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) SWRLRule(org.semanticweb.owlapi.model.SWRLRule)

Example 5 with Rule

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;
}
Also used : OWLDataPropertyExpression(org.semanticweb.owlapi.model.OWLDataPropertyExpression) OWLObjectPropertyExpression(org.semanticweb.owlapi.model.OWLObjectPropertyExpression) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) OWLClassExpression(org.semanticweb.owlapi.model.OWLClassExpression) Term(fr.lirmm.graphik.graal.api.core.Term)

Aggregations

Rule (fr.lirmm.graphik.graal.api.core.Rule)141 Test (org.junit.Test)87 Atom (fr.lirmm.graphik.graal.api.core.Atom)64 OWL2Parser (fr.lirmm.graphik.graal.io.owl.OWL2Parser)52 DefaultNegativeConstraint (fr.lirmm.graphik.graal.core.DefaultNegativeConstraint)49 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)26 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)23 LinkedList (java.util.LinkedList)19 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)16 Term (fr.lirmm.graphik.graal.api.core.Term)15 Prefix (fr.lirmm.graphik.util.Prefix)14 CloseableIteratorWithoutException (fr.lirmm.graphik.util.stream.CloseableIteratorWithoutException)14 OWL2ParserException (fr.lirmm.graphik.graal.io.owl.OWL2ParserException)13 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)9 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)9 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)7 KnowledgeBase (fr.lirmm.graphik.graal.api.kb.KnowledgeBase)7 DefaultRule (fr.lirmm.graphik.graal.core.DefaultRule)7 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)6 Variable (fr.lirmm.graphik.graal.api.core.Variable)6