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);
}
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);
}
}
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;
}
}
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();
}
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();
}
Aggregations