use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.
the class AtomTest method testContainsFalse.
/**
* Test method for
* {@link fr.lirmm.graphik.graal.core.DefaultAtom#contains(fr.lirmm.graphik.graal.api.core.Term)}.
*/
@Theory
public void testContainsFalse(AtomFactory factory) {
// given
Atom a = factory.create(TestUtils.pXA);
// when
boolean contains = a.contains(TestUtils.B);
// then
Assert.assertFalse(contains);
}
use of fr.lirmm.graphik.graal.api.core.Atom 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.Atom in project graal by graphik-team.
the class IndexedByBodyPredicatesRuleSet method add.
// /////////////////////////////////////////////////////////////////////////
// OVERRIDE METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public boolean add(Rule rule) {
super.add(rule);
CloseableIteratorWithoutException<Atom> it = rule.getBody().iterator();
while (it.hasNext()) {
Atom a = it.next();
add(a.getPredicate(), rule);
}
return true;
}
use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.
the class BCCScheduler method constructHyperGraph.
/**
* The HyperGraph of variables of h. There is an hyper edge between a set of
* variables if they appear in a same atom.
*
* @param h
* @return the HyperGraph of variables of h.
*/
protected static HyperGraph constructHyperGraph(InMemoryAtomSet h, int nbVariables, Term[] inverseMap, Map<Term, Integer> map, Iterable<Term> ans) {
HyperGraph graph = new DefaultHyperGraph(nbVariables + 1);
CloseableIteratorWithoutException<Atom> it = h.iterator();
while (it.hasNext()) {
Atom a = it.next();
DefaultHyperEdge edge = new DefaultHyperEdge();
int arity = 0;
for (Variable t : a.getVariables()) {
++arity;
edge.addVertice(map.get(t));
}
if (arity >= 2) {
graph.add(edge);
}
}
return graph;
}
use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.
the class BCCScheduler method computeProba.
/**
* @param h
* @param data
* @param nbVar
* @param map
* @param rc
* @return the probability to have an image for each variables which appears
* in h.
*/
protected double[] computeProba(InMemoryAtomSet h, Store data, int nbVar, Map<Term, Integer> map, RulesCompilation rc) {
final double[] proba = new double[nbVar + 1];
Arrays.fill(proba, -1.);
CloseableIteratorWithoutException<Atom> it = h.iterator();
while (it.hasNext()) {
Atom a = it.next();
double probaA = ProbaUtils.computeProba(a, data, rc);
for (Term t : a.getVariables()) {
int i = map.get(t);
if (proba[i] < 0) {
proba[i] = probaA;
} else {
proba[i] *= probaA;
}
}
}
return proba;
}
Aggregations