Search in sources :

Example 1 with DefaultInMemoryGraphStore

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

the class TestUtil method getAtomSet.

public static AtomSet[] getAtomSet() {
    if (neo4jStore != null) {
        neo4jStore.close();
    }
    try {
        if (defaultRDBMSStore != null) {
            defaultRDBMSStore.close();
        }
        if (plainTableRDBMSStore != null) {
            plainTableRDBMSStore.close();
        }
        defaultRDBMSStore = new AdHocRdbmsStore(new HSQLDBDriver(DEFAULT_RDBMS_TEST, null));
        plainTableRDBMSStore = new NaturalRDBMSStore(new HSQLDBDriver(PLAIN_TABLE_RDBMS_TEST, null));
        defaultRDBMSStore.clear();
        plainTableRDBMSStore.clear();
        rm(NEO4J_TEST);
        neo4jStore = new Neo4jStore(NEO4J_TEST);
        if (sailStore != null) {
            sailStore.close();
        }
        try {
            sailStore = new RDF4jStore(new SailRepository(new MemoryStore()));
        } catch (AtomSetException e) {
            Assert.assertTrue("Error while creating SailStore", false);
        }
        return new AtomSet[] { new DefaultInMemoryGraphStore(), new LinkedListAtomSet(), defaultRDBMSStore, plainTableRDBMSStore, neo4jStore, sailStore };
    } catch (SQLException e) {
        throw new Error(e);
    } catch (AtomSetException e) {
        throw new Error(e);
    }
}
Also used : Neo4jStore(fr.lirmm.graphik.graal.store.gdb.Neo4jStore) RDF4jStore(fr.lirmm.graphik.graal.store.triplestore.rdf4j.RDF4jStore) SailRepository(org.eclipse.rdf4j.repository.sail.SailRepository) SQLException(java.sql.SQLException) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) IOError(java.io.IOError) NaturalRDBMSStore(fr.lirmm.graphik.graal.store.rdbms.natural.NaturalRDBMSStore) AdHocRdbmsStore(fr.lirmm.graphik.graal.store.rdbms.adhoc.AdHocRdbmsStore) MemoryStore(org.eclipse.rdf4j.sail.memory.MemoryStore) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) HSQLDBDriver(fr.lirmm.graphik.graal.store.rdbms.driver.HSQLDBDriver) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)

Example 2 with DefaultInMemoryGraphStore

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

the class BackjumpTest method test1.

/*
	 * X1 --(p15)--> X5 --(p56)--> X6 \ (p12)--> X2 --(p24)--> X4 \ (p23)--> X3
	 * 
	 * solutions: X1 X2 X3 X4 X5 X6 
	 *            b  b  c  d  a  a 
	 *            b  b  d  d  a  a 
	 *            b  d  a  a  a  a
	 */
@Test
public void test1() throws HomomorphismException, IteratorException, ParseException, AtomSetException {
    InMemoryAtomSet data = new DefaultInMemoryGraphStore();
    data.addAll(DlgpParser.parseAtomSet("p12(a,a), p12(b,b), p12(b,c), p12(b,d)."));
    data.addAll(DlgpParser.parseAtomSet("p23(a,a), p23(b,c), p23(b,d), p23(c,a), p23(d,a)."));
    data.addAll(DlgpParser.parseAtomSet("p24(a,a), p24(b,d), p24(d,a)."));
    data.addAll(DlgpParser.parseAtomSet("p15(b,a), p15(b,b)."));
    data.addAll(DlgpParser.parseAtomSet("p56(a,a)."));
    ConjunctiveQuery query = DlgpParser.parseQuery("?(X1,X2,X3,X4,X5,X6) :- p12(X1,X2), p23(X2,X3), p24(X2,X4), p15(X1,X5), p56(X5,X6).");
    BCC bcc = new BCC();
    Homomorphism<ConjunctiveQuery, AtomSet> h = new BacktrackHomomorphism(bcc.getBCCScheduler(), AllDomainBootstrapper.instance(), NoForwardChecking.instance(), bcc.getBCCBackJumping());
    h.setProfiler(new CPUTimeProfiler());
    CloseableIterator<Substitution> results = h.execute(query, data);
    int i = 0;
    while (results.hasNext()) {
        results.next();
        ++i;
    }
    Assert.assertEquals(3, i);
    Assert.assertEquals(49, h.getProfiler().get("#calls"));
}
Also used : BCC(fr.lirmm.graphik.graal.homomorphism.bbc.BCC) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) CPUTimeProfiler(fr.lirmm.graphik.util.profiler.CPUTimeProfiler) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Test(org.junit.Test)

Example 3 with DefaultInMemoryGraphStore

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

the class ForwardCheckingTest method NFC2Test.

@Test
public void NFC2Test() throws HomomorphismException, IteratorException, ParseException {
    Profiler profiler = new CPUTimeProfiler();
    Predicate[] predicates = { new Predicate("p2", 2), new Predicate("p3", 3), new Predicate("p4", 4) };
    InMemoryAtomSet data = new DefaultInMemoryGraphStore();
    TestUtil.addNAtoms(data, 13, predicates, 5, new Random(0));
    ConjunctiveQuery query = DlgpParser.parseQuery("?(X5,X6,X7,X8) :- p4(X5,X6,X7,X8), p4(X8,X7,X6,X5), p3(X7,X8,X9), p2(X7,X11).");
    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();
    Assert.assertEquals(1, profiler.get("#calls"));
}
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 4 with DefaultInMemoryGraphStore

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

the class ForwardCheckingTest method FCTest2.

@Test
public void FCTest2() throws HomomorphismException, IteratorException, ParseException, AtomSetException {
    Profiler profiler = new CPUTimeProfiler();
    InMemoryAtomSet data = new DefaultInMemoryGraphStore();
    data.addAll(DlgpParser.parseAtomSet("p(a,b), p(a,c), q(a,a), q(a,b)."));
    ConjunctiveQuery query = DlgpParser.parseQuery("?(X,Y,Z) :- p(X,Z), q(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();
    Assert.assertEquals(7, profiler.get("#calls"));
}
Also used : NFC2(fr.lirmm.graphik.graal.homomorphism.forward_checking.NFC2) 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 5 with DefaultInMemoryGraphStore

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

the class ForwardCheckingTest method test1.

@Test
public void test1() throws HomomorphismException, IteratorException, ParseException, AtomSetException {
    InMemoryAtomSet data = new DefaultInMemoryGraphStore();
    data.addAll(DlgpParser.parseAtomSet("p(a,b)."));
    ConjunctiveQuery query = DlgpParser.parseQuery("?(X,Y,Z) :- p(X,Y), p(X,Z).");
    Homomorphism<ConjunctiveQuery, AtomSet> h = new BacktrackHomomorphism(new NFC2());
    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) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) 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