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));
}
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;
}
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());
}
}
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);
}
}
}
}
}
}
}
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;
}
Aggregations