use of fr.lirmm.graphik.graal.api.core.AtomSet 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();
}
use of fr.lirmm.graphik.graal.api.core.AtomSet in project graal by graphik-team.
the class DefaultKnowledgeBase method saturate.
@Override
public void saturate() throws KnowledgeBaseException {
if (!this.isSaturated) {
boolean run = this.approach == Approach.SATURATION_ONLY;
if (!run) {
this.analyse();
run = this.analyse.isFES();
}
if (run) {
GraphOfRuleDependencies grd = this.analysedRuleSet.getGraphOfRuleDependencies();
ChaseWithGRD<AtomSet> chase = new ChaseWithGRD<>(grd, this.store);
chase.setProfiler(this.getProfiler());
try {
chase.execute();
} catch (ChaseException e) {
throw new KnowledgeBaseException(e);
}
this.isSaturated = true;
this.isFESSaturated = true;
this.isSemiSaturated = true;
} else {
throw new KnowledgeBaseException("There is no proof for FES decidability");
}
}
}
use of fr.lirmm.graphik.graal.api.core.AtomSet in project graal by graphik-team.
the class DefaultKnowledgeBaseTest method testDefaultKnowledgeBaseAtomSetParserOfObject.
/**
* Test method for
* {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#DefaultKnowledgeBase(fr.lirmm.graphik.graal.api.core.AtomSet, fr.lirmm.graphik.graal.api.io.Parser)}.
* @throws ParseException
* @throws AtomSetException
*/
@Test
public void testDefaultKnowledgeBaseAtomSetParserOfObject() throws ParseException, AtomSetException {
Atom aa = DlgpParser.parseAtom("q(a).");
Atom ab = DlgpParser.parseAtom("q(b).");
Atom ac = DlgpParser.parseAtom("q(c).");
Rule r = DlgpParser.parseRule("[R] p(X) :- q(X).");
NegativeConstraint nc = DlgpParser.parseNegativeConstraint("[NC] ! :- q(X), p(X).");
AtomSet store = new DefaultInMemoryGraphStore();
store.add(aa);
KnowledgeBase kb = new DefaultKnowledgeBase(store, new DlgpParser("[R] p(X) :- q(X). q(b). q(c). [NC] ! :- q(X), p(X)."));
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();
}
use of fr.lirmm.graphik.graal.api.core.AtomSet in project graal by graphik-team.
the class OWL2ParserTest method complexAssertionWithExistential.
@Test
public void complexAssertionWithExistential() throws OWL2ParserException {
try {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":A a owl:Class . " + ":B a owl:Class . " + ":p a owl:ObjectProperty . " + "_:x1 a :A. " + "_:y1 a :B. " + "_:x1 :p _:y1. " + "_:x2 a :A. " + "_:y2 a :B. " + "_:x2 :p _:y2. ");
int nbFacts = 0;
int nbAtoms = 0;
while (parser.hasNext()) {
Object o = parser.next();
if (o instanceof AtomSet) {
Term a0 = null, b0 = null, p0 = null, p1 = null;
++nbFacts;
CloseableIterator<Atom> it = ((AtomSet) o).iterator();
while (it.hasNext()) {
Atom a = it.next();
++nbAtoms;
if (a.getPredicate().equals(P)) {
p0 = a.getTerm(0);
p1 = a.getTerm(1);
} else if (a.getPredicate().equals(A)) {
a0 = a.getTerm(0);
} else if (a.getPredicate().equals(B)) {
b0 = a.getTerm(0);
}
}
Assert.assertEquals(p0, a0);
Assert.assertEquals(p1, b0);
}
}
parser.close();
Assert.assertEquals("Number of facts found:", 2, nbFacts);
Assert.assertEquals("Number of atoms found:", 6, 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 OWL2ParserTest method example6.
@Test
public void example6() throws OWL2ParserException {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + ":B rdf:type owl:Class . " + ":C rdf:type owl:Class . " + ":D rdf:type owl:Class . " + ":p rdf:type owl:ObjectProperty . " + ":q rdf:type owl:ObjectProperty . " + ":r rdf:type owl:ObjectProperty . " + "[owl:unionOf (" + " [owl:oneOf ( :i )] " + " [rdf:type owl:Restriction ;" + " owl:onProperty :p ;" + " owl:someValuesFrom :A]" + " )] " + " rdfs:subClassOf " + "[owl:intersectionOf ( " + " [rdf:type owl:Restriction ;" + " owl:onProperty :q ;" + " owl:someValuesFrom :B]" + " [owl:complementOf :C ] " + " [rdf:type owl:Restriction ;" + " owl:onProperty :r ;" + " owl:allValuesFrom :D]" + " )] . ");
int nbRules = 0;
while (parser.hasNext()) {
Object o = parser.next();
if (o instanceof Rule || o instanceof AtomSet) {
++nbRules;
}
}
parser.close();
Assert.assertEquals("Number of assertions found:", 6, nbRules);
}
Aggregations