Search in sources :

Example 91 with Atom

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);
}
Also used : Atom(fr.lirmm.graphik.graal.api.core.Atom) Theory(org.junit.experimental.theories.Theory)

Example 92 with Atom

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

Example 93 with Atom

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

Example 94 with Atom

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;
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) DefaultHyperGraph(fr.lirmm.graphik.util.graph.DefaultHyperGraph) DefaultHyperEdge(fr.lirmm.graphik.util.graph.DefaultHyperEdge) DefaultHyperGraph(fr.lirmm.graphik.util.graph.DefaultHyperGraph) HyperGraph(fr.lirmm.graphik.util.graph.HyperGraph) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 95 with Atom

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

Aggregations

Atom (fr.lirmm.graphik.graal.api.core.Atom)269 Test (org.junit.Test)97 Term (fr.lirmm.graphik.graal.api.core.Term)86 Rule (fr.lirmm.graphik.graal.api.core.Rule)64 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)41 OWL2Parser (fr.lirmm.graphik.graal.io.owl.OWL2Parser)41 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)40 LinkedList (java.util.LinkedList)40 DefaultNegativeConstraint (fr.lirmm.graphik.graal.core.DefaultNegativeConstraint)36 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)35 Theory (org.junit.experimental.theories.Theory)35 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)34 Variable (fr.lirmm.graphik.graal.api.core.Variable)33 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)31 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)29 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)28 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)27 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)14 CloseableIteratorWithoutException (fr.lirmm.graphik.util.stream.CloseableIteratorWithoutException)14 OWL2ParserException (fr.lirmm.graphik.graal.io.owl.OWL2ParserException)13