use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet 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.InMemoryAtomSet in project graal by graphik-team.
the class JointlyAffectedPositionSet method step2.
/**
* for each rule and for each variable x that occurs only at affected
* positions in its body, all positions q[j] in its head where occurs x are
* affected.
*/
protected void step2() {
InMemoryAtomSet body;
boolean isAffected;
int i;
CloseableIteratorWithoutException<Atom> atomIt;
Iterator<Term> termIt;
Atom a;
Term t;
boolean fixPoint = false;
while (!fixPoint) {
fixPoint = true;
for (Rule rule : ruleSet) {
body = rule.getBody();
for (Variable term : rule.getBody().getVariables()) {
isAffected = true;
atomIt = body.iterator();
while (atomIt.hasNext() && isAffected) {
i = -1;
a = atomIt.next();
termIt = a.iterator();
while (termIt.hasNext() && isAffected) {
++i;
t = termIt.next();
if (term.equals(t)) {
if (!isAffected(a.getPredicate(), i)) {
isAffected = false;
}
}
}
}
if (isAffected) {
if (this.affectInHead(rule, term)) {
fixPoint = false;
}
}
}
}
}
}
use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.
the class AbstractRdbmsConjunctiveQueryTranslator method translate.
@Override
public Iterator<SQLQuery> translate(Rule rangeRestrictedRule) throws AtomSetException {
Collection<SQLQuery> queries = new LinkedList<SQLQuery>();
InMemoryAtomSet body = rangeRestrictedRule.getBody();
CloseableIterator<Atom> it = rangeRestrictedRule.getHead().iterator();
try {
while (it.hasNext()) {
Atom headAtom = it.next();
DBTable table = this.store.createPredicateTableIfNotExist(headAtom.getPredicate());
List<Term> terms = headAtom.getTerms();
ConjunctiveQuery query = DefaultConjunctiveQueryFactory.instance().create(body, terms);
SQLQuery selectQuery = this.translate(query);
if (!selectQuery.hasSchemaError()) {
queries.add(new SQLQuery(store.getDriver().getInsertOrIgnoreQuery(table, selectQuery.toString())));
}
}
} catch (IteratorException e) {
throw new AtomSetException(e);
} catch (SQLException e) {
throw new AtomSetException(e);
}
return queries.iterator();
}
use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.
the class ConjunctiveQueryWithCompilation method issue34.
@Theory
public void issue34(Homomorphism<ConjunctiveQuery, AtomSet> hh, RulesCompilationFactory factory, AtomSet store) throws Exception {
Assume.assumeTrue(hh instanceof HomomorphismWithCompilation);
HomomorphismWithCompilation<ConjunctiveQuery, AtomSet> h = (HomomorphismWithCompilation<ConjunctiveQuery, AtomSet>) hh;
store.add(DlgpParser.parseAtom("<Q>(a,b)."));
RuleSet rules = new LinkedListRuleSet();
rules.add(DlgpParser.parseRule("<P>(X,Y) :- <Q>(Y,X)."));
RulesCompilation comp = factory.create();
comp.compile(rules.iterator());
StaticChase.executeChase(store, rules);
InMemoryAtomSet query1 = new LinkedListAtomSet();
query1.add(DlgpParser.parseAtom("<P>(a,Y)."));
CloseableIterator<Substitution> results = h.execute(new DefaultConjunctiveQuery(query1), store, comp);
Assert.assertFalse(results.hasNext());
results.close();
}
use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet 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);
}
}
Aggregations