Search in sources :

Example 76 with Predicate

use of fr.lirmm.graphik.graal.api.core.Predicate in project graal by graphik-team.

the class AtomTest method equalsTest.

@Test
public void equalsTest() {
    Predicate predicate = new Predicate("pred", 3);
    Term[] terms = new Term[3];
    terms[0] = new DefaultVariable("X");
    terms[1] = new DefaultConstant("a");
    terms[2] = new DefaultConstant("b");
    Atom atom = new DefaultAtom(predicate, Arrays.asList(terms));
    Assert.assertTrue("Atom not equals itself", atom.equals(atom));
    Assert.assertTrue("Atom not equals it clone", atom.equals(new DefaultAtom(atom)));
    Predicate otherPred = new Predicate("otherPred", 3);
    Term[] otherTerms = new Term[3];
    otherTerms[0] = new DefaultVariable("Y");
    otherTerms[1] = new DefaultConstant("b");
    otherTerms[2] = new DefaultConstant("b");
    Atom other = new DefaultAtom(otherPred, Arrays.asList(terms));
    Assert.assertFalse("Atom equals an other atom with other predicate", atom.equals(other));
    other = new DefaultAtom(predicate, Arrays.asList(otherTerms));
    Assert.assertFalse("Atom equals an other atom with other terms", atom.equals(other));
    other = new DefaultAtom(atom);
    other.setPredicate(otherPred);
    Assert.assertFalse("Atom equals a copy with modified predicate", predicate.equals(other));
    other = new DefaultAtom(atom);
    other.setTerm(2, terms[0]);
    Assert.assertFalse("Atom equals a copy with modified terms", atom.equals(other));
}
Also used : DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Term(fr.lirmm.graphik.graal.api.core.Term) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Atom(fr.lirmm.graphik.graal.api.core.Atom) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) Test(org.junit.Test)

Example 77 with Predicate

use of fr.lirmm.graphik.graal.api.core.Predicate in project graal by graphik-team.

the class BreadthFirstChase method dispatchNewData.

// /////////////////////////////////////////////////////////////////////////
// PRIVATE CLASS
// /////////////////////////////////////////////////////////////////////////
protected void dispatchNewData(Collection<Atom> newData) throws ChaseException {
    for (Atom a : newData) {
        Predicate p = a.getPredicate();
        for (Rule r : ruleSet.getRulesByBodyPredicate(p)) {
            if (linearRuleCheck(r)) {
                AtomSet set = nextRulesToCheck.get(r);
                if (set == null) {
                    set = new DefaultInMemoryGraphStore();
                    nextRulesToCheck.put(r, set);
                }
                try {
                    set.add(a);
                } catch (AtomSetException e) {
                    throw new ChaseException("Exception while adding data into a tmp store", e);
                }
            } else {
                nextRulesToCheck.put(r, atomSet);
            }
        }
    }
}
Also used : AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) Rule(fr.lirmm.graphik.graal.api.core.Rule) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) ChaseException(fr.lirmm.graphik.graal.api.forward_chaining.ChaseException) Atom(fr.lirmm.graphik.graal.api.core.Atom) Predicate(fr.lirmm.graphik.graal.api.core.Predicate)

Aggregations

Predicate (fr.lirmm.graphik.graal.api.core.Predicate)77 Atom (fr.lirmm.graphik.graal.api.core.Atom)35 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)28 Term (fr.lirmm.graphik.graal.api.core.Term)27 Test (org.junit.Test)25 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)16 LinkedList (java.util.LinkedList)16 Theory (org.junit.experimental.theories.Theory)14 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)9 Rule (fr.lirmm.graphik.graal.api.core.Rule)9 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)9 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)7 DefaultURI (fr.lirmm.graphik.util.DefaultURI)7 TreeSet (java.util.TreeSet)7 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)6 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)6 RuleSet (fr.lirmm.graphik.graal.api.core.RuleSet)6 Variable (fr.lirmm.graphik.graal.api.core.Variable)6 ConversionException (fr.lirmm.graphik.util.stream.converter.ConversionException)6 Pair (org.apache.commons.lang3.tuple.Pair)6