use of fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet in project graal by graphik-team.
the class OWLAxiomParser method mainProcess.
private Iterable<? extends Rule> mainProcess(OWLSubClassOfAxiom arg) {
Collection<Rule> objects = new LinkedList<Rule>();
InMemoryAtomSet body = null;
try {
body = arg.getSubClass().accept(this.classVisitorX);
} catch (UnsupportedConstructor e) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("[ " + arg.getSubClass() + "] is not supported as subClass. This axioms was skipped : " + arg);
}
return Collections.emptyList();
}
// RULES
InMemoryAtomSet head = null;
try {
if (arg.getSuperClass() instanceof OWLObjectMaxCardinality) {
OWLObjectMaxCardinality maxCard = (OWLObjectMaxCardinality) arg.getSuperClass();
body.addAll(maxCard.getProperty().accept(this.propertyVisitorXY));
body.addAll(maxCard.getProperty().accept(this.propertyVisitorXZ));
InMemoryAtomSet bodyTemplate = body;
head = GraalUtils.createAtomSet(DefaultAtomFactory.instance().create(Predicate.EQUALITY, glueVarY, glueVarZ));
OWLClassExpression expr = OWLAPIUtils.classExpressionDisjunctiveNormalForm(maxCard.getFiller());
for (Pair<OWLClassExpression, OWLClassExpression> pair : MathUtils.selfCartesianProduct(OWLAPIUtils.getObjectUnionOperands(expr))) {
body = new LinkedListAtomSet(bodyTemplate);
body.addAll(pair.getLeft().accept(classVisitorY));
body.addAll(pair.getRight().accept(classVisitorZ));
objects.add(DefaultRuleFactory.instance().create(body, head));
}
} else if (arg.getSuperClass() instanceof OWLDataMaxCardinality) {
OWLDataMaxCardinality maxCard = (OWLDataMaxCardinality) arg.getSuperClass();
Predicate p = GraalUtils.createPredicate(maxCard.getProperty());
body.add(DefaultAtomFactory.instance().create(p, glueVarX, glueVarY));
body.add(DefaultAtomFactory.instance().create(p, glueVarX, glueVarZ));
InMemoryAtomSet bodyTemplate = body;
head = GraalUtils.createAtomSet(DefaultAtomFactory.instance().create(Predicate.EQUALITY, glueVarY, glueVarZ));
OWLDataRange expr = OWLAPIUtils.dataRangeDisjunctiveNormalForm(maxCard.getFiller());
for (Pair<OWLDataRange, OWLDataRange> pair : MathUtils.selfCartesianProduct(OWLAPIUtils.getDataUnionOperands(expr))) {
body = new LinkedListAtomSet(bodyTemplate);
body.addAll(pair.getLeft().accept(dataRangeVisitorY));
body.addAll(pair.getRight().accept(dataRangeVisitorZ));
objects.add(DefaultRuleFactory.instance().create(body, head));
}
} else if (arg.getSuperClass() instanceof OWLDataAllValuesFrom) {
OWLDataAllValuesFrom allvalues = (OWLDataAllValuesFrom) arg.getSuperClass();
Predicate p = GraalUtils.createPredicate(allvalues.getProperty());
body.add(DefaultAtomFactory.instance().create(p, glueVarX, glueVarY));
head = allvalues.getFiller().accept(dataRangeVisitorY);
objects.add(DefaultRuleFactory.instance().create(body, head));
} else {
head = arg.getSuperClass().accept(this.classVisitorX);
objects.add(DefaultRuleFactory.instance().create(body, head));
}
} catch (UnsupportedConstructor e) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("[ " + e.getConstructor() + "] is not supported here. This axioms was skipped : " + arg);
}
objects = Collections.emptyList();
}
return objects;
}
use of fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet in project graal by graphik-team.
the class OWL2Parser method removeUselessTopInHead.
private static InMemoryAtomSet removeUselessTopInHead(InMemoryAtomSet atomset) {
InMemoryAtomSet newAtomset = new LinkedListAtomSet();
CloseableIteratorWithoutException<Atom> it = atomset.iterator();
Atom a;
while (it.hasNext()) {
a = it.next();
if (!a.getPredicate().equals(Predicate.TOP)) {
newAtomset.add(a);
}
}
return newAtomset;
}
use of fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet in project graal by graphik-team.
the class HomomorphismTest method test2.
@Test
public void test2() throws HomomorphismException, IteratorException, AtomSetException {
InMemoryAtomSet data = new DefaultInMemoryGraphStore();
data.addAll(DlgpParser.parseAtomSet("p(a,b), q(b)."));
InMemoryAtomSet positivePart = new LinkedListAtomSet();
positivePart.addAll(DlgpParser.parseAtomSet("p(a,b)."));
InMemoryAtomSet negatedPart = new LinkedListAtomSet();
negatedPart.addAll(DlgpParser.parseAtomSet("q(b)."));
DefaultConjunctiveQueryWithNegatedParts query = new DefaultConjunctiveQueryWithNegatedParts(positivePart, Collections.singletonList(negatedPart));
BacktrackHomomorphismWithNegatedParts h = new BacktrackHomomorphismWithNegatedParts();
CloseableIterator<Substitution> res = h.execute(query, data);
Assert.assertFalse(res.hasNext());
res.close();
}
use of fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet in project graal by graphik-team.
the class HomomorphismTest method test11.
@Test
public void test11() throws HomomorphismException, IteratorException, AtomSetException {
InMemoryAtomSet data = new DefaultInMemoryGraphStore();
data.addAll(DlgpParser.parseAtomSet("p(a,b)."));
InMemoryAtomSet positivePart = new LinkedListAtomSet();
positivePart.addAll(DlgpParser.parseAtomSet("p(a,b)."));
LinkedList<InMemoryAtomSet> parts = new LinkedList<InMemoryAtomSet>();
InMemoryAtomSet negatedPart = new LinkedListAtomSet();
negatedPart.addAll(DlgpParser.parseAtomSet("q(a)."));
parts.add(negatedPart);
negatedPart = new LinkedListAtomSet();
negatedPart.addAll(DlgpParser.parseAtomSet("q(b)."));
parts.add(negatedPart);
DefaultConjunctiveQueryWithNegatedParts query = new DefaultConjunctiveQueryWithNegatedParts(positivePart, parts);
BacktrackHomomorphismWithNegatedParts h = new BacktrackHomomorphismWithNegatedParts();
CloseableIterator<Substitution> res = h.execute(query, data);
Assert.assertTrue(res.hasNext());
res.next();
Assert.assertFalse(res.hasNext());
res.close();
}
use of fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet in project graal by graphik-team.
the class HomomorphismTest method test.
@Test
public void test() throws HomomorphismException, IteratorException, AtomSetException {
InMemoryAtomSet data = new DefaultInMemoryGraphStore();
data.addAll(DlgpParser.parseAtomSet("p(a,b)."));
InMemoryAtomSet positivePart = new LinkedListAtomSet();
positivePart.addAll(DlgpParser.parseAtomSet("p(a,b)."));
InMemoryAtomSet negatedPart = new LinkedListAtomSet();
negatedPart.addAll(DlgpParser.parseAtomSet("q(b)."));
DefaultConjunctiveQueryWithNegatedParts query = new DefaultConjunctiveQueryWithNegatedParts(positivePart, Collections.singletonList(negatedPart));
BacktrackHomomorphismWithNegatedParts h = new BacktrackHomomorphismWithNegatedParts();
CloseableIterator<Substitution> res = h.execute(query, data);
Assert.assertTrue(res.hasNext());
res.next();
Assert.assertFalse(res.hasNext());
res.close();
}
Aggregations