use of fr.lirmm.graphik.graal.api.core.Term 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;
}
use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.
the class AbstractDlgpListener method startsObject.
@Override
public void startsObject(OBJECT_TYPE objectType, String name) {
this.label = (name == null) ? "" : name;
atomSet = new LinkedListAtomSet();
atomSet2 = null;
if (OBJECT_TYPE.QUERY.equals(objectType)) {
this.answerVars = new LinkedList<Term>();
}
}
use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.
the class AbstractDlgpListener method endsConjunction.
@Override
public void endsConjunction(OBJECT_TYPE objectType) {
switch(objectType) {
case QUERY:
Set<Variable> bodyVars = this.atomSet.getVariables();
for (Term t : this.answerVars) {
if (t.isVariable() && !bodyVars.contains(t)) {
throw new ParseError("The variable [" + t + "] of the answer list does not appear in the query body.");
}
}
this.createQuery(DefaultConjunctiveQueryFactory.instance().create(this.label, this.atomSet, this.answerVars));
break;
case NEG_CONSTRAINT:
this.createNegConstraint(new DefaultNegativeConstraint(this.label, this.atomSet));
break;
case RULE:
if (this.atomSet2 == null) {
this.atomSet2 = this.atomSet;
this.atomSet = new LinkedListAtomSet();
} else {
this.createRule(DefaultRuleFactory.instance().create(this.label, this.atomSet, this.atomSet2));
}
break;
case FACT:
this.createAtomSet(this.atomSet);
break;
default:
break;
}
}
use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.
the class AbstractDlgpListener method createsAtom.
@Override
public void createsAtom(Object predicate, Object[] terms) {
List<Term> list = new LinkedList<Term>();
for (Object t : terms) {
list.add(createTerm(t));
}
atom = new DefaultAtom(createPredicate(predicate, terms.length), list);
this.atomSet.add(atom);
}
use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.
the class AbstractNFC method init.
@Override
public void init(VarSharedData[] vars, Map<Variable, Integer> map) {
this.data = new VarData[vars.length];
for (int i = 0; i < vars.length; ++i) {
this.data[vars[i].level] = new VarData();
this.data[vars[i].level].candidats = new AcceptableCandidats[vars.length];
this.data[vars[i].level].tmp = new HashSet<Term>();
this.data[vars[i].level].toCheckAfterAssignment = new LinkedList<Atom>();
for (Atom a : vars[i].preAtoms) {
int cpt = 0;
boolean toAdd = true;
for (Variable t : a.getVariables()) {
if (map.containsKey(t)) {
if (t.equals(vars[i].value))
++cpt;
else
toAdd = false;
}
}
if (toAdd || cpt > 1) {
this.data[vars[i].level].toCheckAfterAssignment.add(a);
}
}
AcceptableCandidats previous = new AcceptableCandidats();
for (VarSharedData z : vars[i].preVars) {
AcceptableCandidats ac = new AcceptableCandidats();
ac.candidats = new TreeSet<Term>();
ac.previous = previous;
previous = ac;
this.data[vars[i].level].candidats[z.level] = ac;
}
this.data[vars[i].level].last = previous;
}
}
Aggregations