Search in sources :

Example 16 with DefaultInMemoryGraphStore

use of fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore in project graal by graphik-team.

the class KBBuilderTest method testSetStore.

/**
 * Test method for {@link fr.lirmm.graphik.graal.kb.KBBuilder#setStore(fr.lirmm.graphik.graal.api.store.Store)}.
 */
@Test
public void testSetStore() {
    // Given
    KBBuilder kbb = new KBBuilder();
    Store store = new DefaultInMemoryGraphStore();
    // When
    kbb.setStore(store);
    KnowledgeBase kb = kbb.build();
    // Then
    Assert.assertTrue(kb.getFacts() == store);
}
Also used : KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) Store(fr.lirmm.graphik.graal.api.store.Store) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) Test(org.junit.Test)

Example 17 with DefaultInMemoryGraphStore

use of fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore in project graal by graphik-team.

the class ConjunctiveQueryFixedBugTest method GraphAtomSetQuery.

/**
 * Query using an DefaultInMemoryGraphAtomSet.
 *
 * @param h
 * @param store
 */
@Theory
public void GraphAtomSetQuery(Homomorphism<ConjunctiveQuery, AtomSet> h, AtomSet store) {
    try {
        InMemoryAtomSet atomset = new DefaultInMemoryGraphStore();
        atomset.add(DlgpParser.parseAtom("<P>(X)."));
        ConjunctiveQuery query = new DefaultConjunctiveQuery(atomset);
        CloseableIterator<Substitution> subReader;
        subReader = h.execute(query, store);
        Assert.assertFalse(subReader.hasNext());
        subReader.close();
    } catch (Exception e) {
        Assert.assertTrue(e.getMessage(), false);
    }
}
Also used : DefaultConjunctiveQuery(fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) DefaultConjunctiveQuery(fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) IteratorException(fr.lirmm.graphik.util.stream.IteratorException) Theory(org.junit.experimental.theories.Theory)

Example 18 with DefaultInMemoryGraphStore

use of fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore in project graal by graphik-team.

the class ForwardCheckingTest method simpleFCTest1.

@Test
public void simpleFCTest1() throws HomomorphismException, IteratorException, ParseException, AtomSetException {
    Profiler profiler = new CPUTimeProfiler();
    InMemoryAtomSet data = new DefaultInMemoryGraphStore();
    data.addAll(DlgpParser.parseAtomSet("p(a,b), q(b,c)."));
    ConjunctiveQuery query = DlgpParser.parseQuery("?(X,Y,Z) :- p(X,Y), q(Y,Z).");
    Homomorphism<ConjunctiveQuery, AtomSet> h = new BacktrackHomomorphism(new SimpleFC());
    h.setProfiler(profiler);
    CloseableIterator<Substitution> results = h.execute(query, data);
    while (results.hasNext()) {
        results.next();
    }
    results.close();
    Assert.assertEquals(7, profiler.get("#calls"));
}
Also used : SimpleFC(fr.lirmm.graphik.graal.homomorphism.forward_checking.SimpleFC) Profiler(fr.lirmm.graphik.util.profiler.Profiler) CPUTimeProfiler(fr.lirmm.graphik.util.profiler.CPUTimeProfiler) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) CPUTimeProfiler(fr.lirmm.graphik.util.profiler.CPUTimeProfiler) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Test(org.junit.Test)

Example 19 with DefaultInMemoryGraphStore

use of fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore in project graal by graphik-team.

the class ForwardCheckingTest method NFC2Test2.

@Test
public void NFC2Test2() throws HomomorphismException, IteratorException, ParseException {
    Profiler profiler = new CPUTimeProfiler();
    Predicate[] predicates = { new Predicate("p", 2), new Predicate("q", 2), new Predicate("r", 2) };
    InMemoryAtomSet data = new DefaultInMemoryGraphStore();
    TestUtil.addNAtoms(data, 32, predicates, 5, new Random(0));
    ConjunctiveQuery query = DlgpParser.parseQuery("?(X,Y,Z) :- p(X,Y), q(X,Z), r(Y,Z).");
    Homomorphism<ConjunctiveQuery, AtomSet> h = new BacktrackHomomorphism(new NFC2());
    h.setProfiler(profiler);
    CloseableIterator<Substitution> results = h.execute(query, data);
    while (results.hasNext()) {
        results.next();
    }
    results.close();
}
Also used : NFC2(fr.lirmm.graphik.graal.homomorphism.forward_checking.NFC2) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) CPUTimeProfiler(fr.lirmm.graphik.util.profiler.CPUTimeProfiler) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) Profiler(fr.lirmm.graphik.util.profiler.Profiler) CPUTimeProfiler(fr.lirmm.graphik.util.profiler.CPUTimeProfiler) Random(java.util.Random) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Test(org.junit.Test)

Example 20 with DefaultInMemoryGraphStore

use of fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore in project graal by graphik-team.

the class EqualityUtilsTest method testQuery1.

@Test
public void testQuery1() throws HomomorphismException, IteratorException, AtomSetException {
    ConjunctiveQuery q = DlgpParser.parseQuery("?(X,Y) :- b(X), Y=a.");
    InMemoryAtomSet store = new DefaultInMemoryGraphStore();
    store.addAll(DlgpParser.parseAtomSet("b(a),b(b)."));
    BacktrackHomomorphism h = new BacktrackHomomorphism();
    CloseableIterator<Substitution> results = h.execute(q, store);
    while (results.hasNext()) {
        results.next();
    }
    results.close();
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Test(org.junit.Test)

Aggregations

DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)29 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)21 Test (org.junit.Test)21 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)18 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)11 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)11 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)10 Atom (fr.lirmm.graphik.graal.api.core.Atom)8 DefaultConjunctiveQueryWithNegatedParts (fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts)8 Rule (fr.lirmm.graphik.graal.api.core.Rule)5 NFC2 (fr.lirmm.graphik.graal.homomorphism.forward_checking.NFC2)5 CPUTimeProfiler (fr.lirmm.graphik.util.profiler.CPUTimeProfiler)5 LinkedList (java.util.LinkedList)5 Variable (fr.lirmm.graphik.graal.api.core.Variable)4 KnowledgeBase (fr.lirmm.graphik.graal.api.kb.KnowledgeBase)4 Profiler (fr.lirmm.graphik.util.profiler.Profiler)4 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)3 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)3 RuleSet (fr.lirmm.graphik.graal.api.core.RuleSet)3 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)3