Search in sources :

Example 1 with AtomSet

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

the class OWL2ParserTest method assertionDataProperty.

@Test
public void assertionDataProperty() throws OWL2ParserException, IteratorException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:DatatypeProperty . " + ":i1 :p 7 ." + "");
    boolean found = false;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (!(o instanceof Prefix)) {
            AtomSet atomset = (AtomSet) o;
            Atom a = atomset.iterator().next();
            Assert.assertEquals(P, a.getPredicate());
            Iterator<Term> it = a.iterator();
            Assert.assertEquals(I1, it.next());
            Assert.assertEquals(L1, it.next());
            found = true;
        }
    }
    parser.close();
    Assert.assertTrue("Number of assertions found:", found);
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Prefix(fr.lirmm.graphik.util.Prefix) Term(fr.lirmm.graphik.graal.api.core.Term) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 2 with AtomSet

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

the class OWL2ParserTest method assertionWithExistential.

@Test
public void assertionWithExistential() throws OWL2ParserException {
    try {
        OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + ":p rdf:type owl:ObjectProperty . " + ":i1 :p [a :A] ." + "");
        int nbFacts = 0;
        int nbAtoms = 0;
        while (parser.hasNext()) {
            Object o = parser.next();
            if (o instanceof InMemoryAtomSet) {
                ++nbFacts;
                CloseableIterator<Atom> it = ((AtomSet) o).iterator();
                while (it.hasNext()) {
                    it.next();
                    ++nbAtoms;
                }
            }
        }
        parser.close();
        Assert.assertEquals("Number of facts found:", 1, nbFacts);
        Assert.assertEquals("Number of atoms found:", 2, nbAtoms);
    } catch (Throwable e) {
        Assert.fail("An exception was found: " + e);
    }
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 3 with AtomSet

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

the class DefaultKnowledgeBase method fesSaturate.

// /////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
// /////////////////////////////////////////////////////////////////////////
/**
 * Run saturation with a timeout at <code>timeout</code> milliseconds for this thread to die. A timeout of 0 means to wait forever.
 * @param timeout in milliseconds
 * @throws ChaseException
 * @throws TimeoutException
 */
protected void fesSaturate(long timeout) throws ChaseException, TimeoutException {
    if (!isFESSaturated) {
        GraphOfRuleDependencies grd = this.getFESGraphOfRuleDependencies();
        ChaseWithGRD<AtomSet> chase = new ChaseWithGRD<>(grd, this.store);
        chase.setProfiler(this.getProfiler());
        chase.execute(timeout);
        this.isFESSaturated = true;
    }
}
Also used : AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) ChaseWithGRD(fr.lirmm.graphik.graal.forward_chaining.ChaseWithGRD) GraphOfRuleDependencies(fr.lirmm.graphik.graal.api.core.GraphOfRuleDependencies) DefaultGraphOfRuleDependencies(fr.lirmm.graphik.graal.core.grd.DefaultGraphOfRuleDependencies)

Example 4 with AtomSet

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

the class DefaultKnowledgeBaseTest method testGetRuleNames.

/**
 * Test method for
 * {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#getRuleNames()}.
 * @throws ParseException
 */
@Test
public void testGetRuleNames() throws ParseException {
    Rule r1 = DlgpParser.parseRule("[R1] p(x) :- q(X).");
    Rule r2 = DlgpParser.parseRule("[R2] q(x) :- r(X).");
    AtomSet store = new DefaultInMemoryGraphStore();
    RuleSet ruleset = new LinkedListRuleSet();
    ruleset.add(r1);
    ruleset.add(r2);
    KnowledgeBase kb = new DefaultKnowledgeBase(store, ruleset);
    Assert.assertTrue(kb.getRuleNames().contains("R1"));
    Assert.assertTrue(kb.getRuleNames().contains("R2"));
    Assert.assertEquals(r1, kb.getRule("R1"));
    Assert.assertEquals(r2, kb.getRule("R2"));
    kb.close();
}
Also used : RuleSet(fr.lirmm.graphik.graal.api.core.RuleSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) Test(org.junit.Test)

Example 5 with AtomSet

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

the class DefaultKnowledgeBaseTest method testDefaultKnowledgeBaseAtomSetRuleSet.

/**
 * Test method for
 * {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#DefaultKnowledgeBase(fr.lirmm.graphik.graal.api.core.AtomSet, fr.lirmm.graphik.graal.api.core.RuleSet)}.
 * @throws AtomSetException
 * @throws ParseException
 */
@Test
public void testDefaultKnowledgeBaseAtomSetRuleSet() throws AtomSetException, ParseException {
    Atom aa = DlgpParser.parseAtom("q(a).");
    Atom ab = DlgpParser.parseAtom("q(b).");
    Atom ac = DlgpParser.parseAtom("q(c).");
    Rule r = DlgpParser.parseRule("[R1] p(x) :- q(X).");
    NegativeConstraint nc = DlgpParser.parseNegativeConstraint("[NC] ! :- q(X), p(X).");
    AtomSet store = new DefaultInMemoryGraphStore();
    store.add(aa);
    store.add(ab);
    store.add(ac);
    RuleSet ruleset = new LinkedListRuleSet();
    ruleset.add(r);
    ruleset.add(nc);
    KnowledgeBase kb = new DefaultKnowledgeBase(store, ruleset);
    Assert.assertTrue(kb.getOntology().contains(r));
    Assert.assertTrue(kb.getOntology().contains(nc));
    Assert.assertTrue(kb.getFacts().contains(aa));
    Assert.assertTrue(kb.getFacts().contains(ab));
    Assert.assertTrue(kb.getFacts().contains(ac));
    kb.close();
}
Also used : RuleSet(fr.lirmm.graphik.graal.api.core.RuleSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) Atom(fr.lirmm.graphik.graal.api.core.Atom) NegativeConstraint(fr.lirmm.graphik.graal.api.core.NegativeConstraint) Test(org.junit.Test)

Aggregations

AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)32 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)18 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)14 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)13 Test (org.junit.Test)13 RuleSet (fr.lirmm.graphik.graal.api.core.RuleSet)11 DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)11 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)11 Atom (fr.lirmm.graphik.graal.api.core.Atom)9 DefaultConjunctiveQuery (fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery)9 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)9 Rule (fr.lirmm.graphik.graal.api.core.Rule)7 RulesCompilation (fr.lirmm.graphik.graal.api.core.RulesCompilation)7 HomomorphismWithCompilation (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismWithCompilation)7 Theory (org.junit.experimental.theories.Theory)7 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)5 Term (fr.lirmm.graphik.graal.api.core.Term)5 ChaseException (fr.lirmm.graphik.graal.api.forward_chaining.ChaseException)5 CPUTimeProfiler (fr.lirmm.graphik.util.profiler.CPUTimeProfiler)5 TripleStore (fr.lirmm.graphik.graal.api.store.TripleStore)4