use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet 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.api.core.InMemoryAtomSet in project graal by graphik-team.
the class OWLAxiomParser method visit.
// /////////////////////////////////////////////////////////////////////////
// ObjectPropertyAxiom
// /////////////////////////////////////////////////////////////////////////
@Override
public Iterable<? extends Object> visit(OWLSubObjectPropertyOfAxiom arg) {
InMemoryAtomSet a1, a2;
a1 = arg.getSubProperty().accept(propertyVisitorXY);
a2 = arg.getSuperProperty().accept(propertyVisitorXY);
return Collections.singleton(DefaultRuleFactory.instance().create(a1, a2));
}
use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet 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.api.core.InMemoryAtomSet in project graal by graphik-team.
the class EqualityUtils method generateQuery.
private static ConjunctiveQuery generateQuery(ConjunctiveQuery q, Substitution s, LinkedList<Atom> toRemove) {
if (toRemove.isEmpty()) {
return q;
}
List<Term> newAns = new LinkedList<Term>(q.getAnswerVariables());
newAns.removeAll(s.getTerms());
InMemoryAtomSet newAtomSet = DefaultAtomSetFactory.instance().create();
CloseableIteratorWithoutException<Atom> it = q.getAtomSet().iterator();
while (it.hasNext()) {
Atom a = it.next();
if (!toRemove.contains(a)) {
newAtomSet.add(s.createImageOf(a));
}
}
return DefaultConjunctiveQueryFactory.instance().create(newAtomSet, newAns);
}
use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.
the class ForwardCheckingTest method simpleFCTest1.
@Test
public void simpleFCTest1() throws HomomorphismException, IteratorException, ParseException, AtomSetException {
Profiler profiler = new CPUTimeProfiler();
InMemoryAtomSet data = new DefaultInMemoryGraphStore();
data.addAll(DlgpParser.parseAtomSet("p(a,b), q(b,c)."));
ConjunctiveQuery query = DlgpParser.parseQuery("?(X,Y,Z) :- p(X,Y), q(Y,Z).");
Homomorphism<ConjunctiveQuery, AtomSet> h = new BacktrackHomomorphism(new SimpleFC());
h.setProfiler(profiler);
CloseableIterator<Substitution> results = h.execute(query, data);
while (results.hasNext()) {
results.next();
}
results.close();
Assert.assertEquals(7, profiler.get("#calls"));
}
Aggregations