Search in sources :

Example 11 with InMemoryAtomSet

use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.

the class OWLAxiomParser method visit.

// /////////////////////////////////////////////////////////////////////////
// HasKey
// /////////////////////////////////////////////////////////////////////////
@Override
public Iterable<? extends Object> visit(OWLHasKeyAxiom arg) {
    // =(Y, Z) :- C(Y), C(Z), p1(Y, X1), p1(Z, X1), ..., pn(Y, Xn), pn(Z,
    // Xn).
    Collection<Rule> rules = GraalUtils.<Rule>createCollection();
    freeVarGen.setIndex(2);
    InMemoryAtomSet head = GraalUtils.createAtomSet(DefaultAtomFactory.instance().create(equalityPredicate, glueVarX, glueVarY));
    OWLClassExpression classExpression = OWLAPIUtils.classExpressionDisjunctiveNormalForm(arg.getClassExpression());
    for (Pair<OWLClassExpression, OWLClassExpression> pair : MathUtils.selfCartesianProduct(OWLAPIUtils.getObjectUnionOperands(classExpression))) {
        InMemoryAtomSet body = pair.getLeft().accept(classVisitorX);
        body.addAll(pair.getRight().accept(classVisitorY));
        for (OWLObjectPropertyExpression pe : arg.getObjectPropertyExpressions()) {
            Term var = freeVarGen.getFreshSymbol();
            body.addAll(pe.accept(new OWLPropertyExpressionVisitorImpl(glueVarX, var)));
            body.addAll(pe.accept(new OWLPropertyExpressionVisitorImpl(glueVarY, var)));
        }
        for (OWLDataPropertyExpression pe : arg.getDataPropertyExpressions()) {
            Term var = freeVarGen.getFreshSymbol();
            body.add(DefaultAtomFactory.instance().create(GraalUtils.createPredicate(pe), glueVarX, var));
            body.add(DefaultAtomFactory.instance().create(GraalUtils.createPredicate(pe), glueVarY, var));
        }
        rules.add(DefaultRuleFactory.instance().create(body, head));
    }
    return rules;
}
Also used : OWLDataPropertyExpression(org.semanticweb.owlapi.model.OWLDataPropertyExpression) OWLObjectPropertyExpression(org.semanticweb.owlapi.model.OWLObjectPropertyExpression) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) OWLClassExpression(org.semanticweb.owlapi.model.OWLClassExpression) Term(fr.lirmm.graphik.graal.api.core.Term)

Example 12 with InMemoryAtomSet

use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.

the class OWLAxiomParser method visit.

@Override
public Iterable<? extends Object> visit(OWLSymmetricObjectPropertyAxiom arg) {
    InMemoryAtomSet body = arg.getProperty().accept(propertyVisitorXY);
    InMemoryAtomSet head = arg.getProperty().accept(propertyVisitorYX);
    return Collections.singleton(DefaultRuleFactory.instance().create(body, head));
}
Also used : InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)

Example 13 with InMemoryAtomSet

use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.

the class OWLAxiomParser method visit.

@Override
public Iterable<? extends Object> visit(OWLNegativeObjectPropertyAssertionAxiom arg) {
    freeVarGen.setIndex(0);
    Term a = GraalUtils.createTerm(arg.getSubject());
    Term b = GraalUtils.createTerm(arg.getObject());
    InMemoryAtomSet atomset = arg.getProperty().accept(new OWLPropertyExpressionVisitorImpl(a, b));
    return Collections.singleton(new DefaultNegativeConstraint(atomset));
}
Also used : DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Term(fr.lirmm.graphik.graal.api.core.Term)

Example 14 with InMemoryAtomSet

use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.

the class OWLAxiomParser method visit.

@Override
public Iterable<? extends Object> visit(OWLTransitiveObjectPropertyAxiom arg) {
    InMemoryAtomSet body = arg.getProperty().accept(propertyVisitorXY);
    body.addAll(arg.getProperty().accept(propertyVisitorYZ));
    InMemoryAtomSet head = arg.getProperty().accept(propertyVisitorXZ);
    return Collections.singleton(DefaultRuleFactory.instance().create(body, head));
}
Also used : InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)

Example 15 with InMemoryAtomSet

use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.

the class OWLAxiomParser method disjointPropertiesAxiom.

private Iterable<? extends Object> disjointPropertiesAxiom(Iterable<? extends OWLPropertyExpression> properties) {
    Collection<Rule> rules = GraalUtils.<Rule>createCollection();
    InMemoryAtomSet a, a1, a2;
    Iterator<? extends OWLPropertyExpression> it1, it2;
    it1 = properties.iterator();
    while (it1.hasNext()) {
        OWLPropertyExpression propExpr = (OWLPropertyExpression) it1.next();
        a1 = propExpr.accept(propertyVisitorXY);
        it1.remove();
        it2 = properties.iterator();
        while (it2.hasNext()) {
            OWLPropertyExpression next = (OWLPropertyExpression) it2.next();
            a2 = next.accept(propertyVisitorXY);
            a = GraalUtils.createAtomSet();
            a.addAll(a1);
            a.addAll(a2);
            rules.add(new DefaultNegativeConstraint(a));
        }
    }
    return rules;
}
Also used : OWLPropertyExpression(org.semanticweb.owlapi.model.OWLPropertyExpression) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) SWRLRule(org.semanticweb.owlapi.model.SWRLRule)

Aggregations

InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)122 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)40 Atom (fr.lirmm.graphik.graal.api.core.Atom)38 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)35 Test (org.junit.Test)35 Term (fr.lirmm.graphik.graal.api.core.Term)31 Rule (fr.lirmm.graphik.graal.api.core.Rule)25 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)23 LinkedList (java.util.LinkedList)22 DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)21 Variable (fr.lirmm.graphik.graal.api.core.Variable)19 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)10 DefaultNegativeConstraint (fr.lirmm.graphik.graal.core.DefaultNegativeConstraint)10 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)9 Theory (org.junit.experimental.theories.Theory)9 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)8 DefaultConjunctiveQueryWithNegatedParts (fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts)8 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)8 OWL2Parser (fr.lirmm.graphik.graal.io.owl.OWL2Parser)7 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)6