Search in sources :

Example 36 with LinkedListAtomSet

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;
}
Also used : LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) OWLClassExpression(org.semanticweb.owlapi.model.OWLClassExpression) OWLDataAllValuesFrom(org.semanticweb.owlapi.model.OWLDataAllValuesFrom) OWLObjectMaxCardinality(org.semanticweb.owlapi.model.OWLObjectMaxCardinality) OWLDataRange(org.semanticweb.owlapi.model.OWLDataRange) LinkedList(java.util.LinkedList) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) OWLDataMaxCardinality(org.semanticweb.owlapi.model.OWLDataMaxCardinality) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) Pair(org.apache.commons.lang3.tuple.Pair)

Example 37 with LinkedListAtomSet

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;
}
Also used : InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 38 with LinkedListAtomSet

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();
}
Also used : DefaultConjunctiveQueryWithNegatedParts(fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) Test(org.junit.Test)

Example 39 with LinkedListAtomSet

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();
}
Also used : DefaultConjunctiveQueryWithNegatedParts(fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 40 with LinkedListAtomSet

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();
}
Also used : DefaultConjunctiveQueryWithNegatedParts(fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) Test(org.junit.Test)

Aggregations

LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)52 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)35 Atom (fr.lirmm.graphik.graal.api.core.Atom)28 LinkedList (java.util.LinkedList)19 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)18 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)17 Term (fr.lirmm.graphik.graal.api.core.Term)17 DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)11 Theory (org.junit.experimental.theories.Theory)11 DefaultConjunctiveQuery (fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery)9 Test (org.junit.Test)9 Variable (fr.lirmm.graphik.graal.api.core.Variable)8 DefaultConjunctiveQueryWithNegatedParts (fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts)8 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)7 Rule (fr.lirmm.graphik.graal.api.core.Rule)6 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)5 SubstitutionIterator2AtomIterator (fr.lirmm.graphik.graal.core.stream.SubstitutionIterator2AtomIterator)5 SqlHomomorphism (fr.lirmm.graphik.graal.store.rdbms.homomorphism.SqlHomomorphism)5 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)4 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)4