Search in sources :

Example 51 with Term

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;
}
Also used : Term(fr.lirmm.graphik.graal.api.core.Term) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 52 with Term

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>();
    }
}
Also used : LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) Term(fr.lirmm.graphik.graal.api.core.Term)

Example 53 with 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;
    }
}
Also used : DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Variable(fr.lirmm.graphik.graal.api.core.Variable) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) ParseError(fr.lirmm.graphik.graal.api.io.ParseError) Term(fr.lirmm.graphik.graal.api.core.Term)

Example 54 with Term

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

Example 55 with Term

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;
    }
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) Term(fr.lirmm.graphik.graal.api.core.Term) VarSharedData(fr.lirmm.graphik.graal.homomorphism.VarSharedData) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Aggregations

Term (fr.lirmm.graphik.graal.api.core.Term)173 Atom (fr.lirmm.graphik.graal.api.core.Atom)86 LinkedList (java.util.LinkedList)41 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)36 Test (org.junit.Test)35 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)34 Variable (fr.lirmm.graphik.graal.api.core.Variable)32 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)27 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)26 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)23 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)18 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)15 Rule (fr.lirmm.graphik.graal.api.core.Rule)15 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)14 TreeSet (java.util.TreeSet)12 Constant (fr.lirmm.graphik.graal.api.core.Constant)9 DBTable (fr.lirmm.graphik.graal.store.rdbms.util.DBTable)9 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9 TreeMap (java.util.TreeMap)8