Search in sources :

Example 56 with Rule

use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.

the class UnifierTest method example35MelanieThesis.

@Test
public void example35MelanieThesis() {
    Rule rule = DefaultRuleFactory.instance().create();
    rule.getBody().add(TestUtils.pXY);
    rule.getHead().add(TestUtils.qXY);
    InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create();
    atomset.add(TestUtils.qUV);
    atomset.add(TestUtils.pVW);
    atomset.add(TestUtils.qTW);
    CloseableIteratorWithoutException<Substitution> unifiers = DefaultUnifierAlgorithm.instance().computePieceUnifier(rule, atomset);
    Assert.assertEquals(2, Iterators.count(unifiers));
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) Test(org.junit.Test)

Example 57 with Rule

use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.

the class IndexedByBodyPredicatesRuleSet method addAll.

@Override
public boolean addAll(Collection<? extends Rule> c) {
    boolean res = super.addAll(c);
    for (Rule rule : c) {
        CloseableIteratorWithoutException<Atom> it = rule.getBody().iterator();
        while (it.hasNext()) {
            Atom a = it.next();
            add(a.getPredicate(), rule);
        }
    }
    return res;
}
Also used : Rule(fr.lirmm.graphik.graal.api.core.Rule) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 58 with Rule

use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.

the class DefaultOntology method resetVocabulary.

// /////////////////////////////////////////////////////////////////////////
// OBJECT OVERRIDE METHODS
// /////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
// /////////////////////////////////////////////////////////////////////////
/**
 */
private void resetVocabulary() {
    // reset vocabulary
    this.vocabulary = new TreeSet<Predicate>();
    for (Rule r : this) {
        this.vocabulary.addAll(r.getBody().getPredicates());
        this.vocabulary.addAll(r.getHead().getPredicates());
    }
}
Also used : Rule(fr.lirmm.graphik.graal.api.core.Rule) Predicate(fr.lirmm.graphik.graal.api.core.Predicate)

Example 59 with Rule

use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.

the class DefaultGraphOfRuleDependencies method computeDependencies.

protected void computeDependencies(DependencyChecker... checkers) {
    // preprocess
    IndexedByBodyPredicatesRuleSet index = new IndexedByBodyPredicatesRuleSet(this.graph.vertexSet());
    Iterable<Rule> candidates = null;
    Set<String> marked = new TreeSet<String>();
    for (Rule r1 : this.graph.vertexSet()) {
        marked.clear();
        CloseableIteratorWithoutException<Atom> it = r1.getHead().iterator();
        while (it.hasNext()) {
            Atom a = it.next();
            candidates = index.getRulesByBodyPredicate(a.getPredicate());
            if (candidates != null) {
                for (Rule r2 : candidates) {
                    if (marked.add(r2.getLabel())) {
                        Set<Substitution> unifiers = computeDependency(r1, r2, checkers);
                        if (!unifiers.isEmpty()) {
                            this.setDependency(r1, unifiers, r2);
                        }
                    }
                }
            }
        }
    }
}
Also used : IndexedByBodyPredicatesRuleSet(fr.lirmm.graphik.graal.core.ruleset.IndexedByBodyPredicatesRuleSet) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) TreeSet(java.util.TreeSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 60 with Rule

use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.

the class DefaultGraphOfRuleDependencies method getSubGraph.

@Override
public DefaultGraphOfRuleDependencies getSubGraph(Iterable<Rule> ruleSet) {
    DefaultGraphOfRuleDependencies subGRD = new DefaultGraphOfRuleDependencies(this.computingUnifiers);
    subGRD.addRuleSet(ruleSet);
    for (Rule src : ruleSet) {
        for (Rule target : ruleSet) {
            Integer e = this.graph.getEdge(src, target);
            if (e != null) {
                // there is an edge
                for (Substitution s : this.edgesValue.get(e)) {
                    subGRD.addDependency(src, s, target);
                }
            }
        }
    }
    return subGRD;
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) Rule(fr.lirmm.graphik.graal.api.core.Rule)

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