Search in sources :

Example 1 with Term

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

the class OWLAxiomParser method visit.

// /////////////////////////////////////////////////////////////////////////
// PropertyChain
// /////////////////////////////////////////////////////////////////////////
@Override
public Iterable<? extends Object> visit(OWLSubPropertyChainOfAxiom arg) {
    freeVarGen.setIndex(0);
    InMemoryAtomSet body = GraalUtils.createAtomSet();
    Term varX, varY, firstVarInChain;
    firstVarInChain = varX = freeVarGen.getFreshSymbol();
    for (OWLPropertyExpression pe : arg.getPropertyChain()) {
        varY = freeVarGen.getFreshSymbol();
        body.addAll(pe.accept(new OWLPropertyExpressionVisitorImpl(varX, varY)));
        varX = varY;
    }
    InMemoryAtomSet head = arg.getSuperProperty().accept(new OWLPropertyExpressionVisitorImpl(firstVarInChain, varX));
    return Collections.singleton(DefaultRuleFactory.instance().create(body, head));
}
Also used : OWLPropertyExpression(org.semanticweb.owlapi.model.OWLPropertyExpression) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Term(fr.lirmm.graphik.graal.api.core.Term)

Example 2 with Term

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

the class OWLAxiomParser method visit.

@Override
public Iterable<? extends Object> visit(OWLDifferentIndividualsAxiom arg) {
    Collection<Object> c = GraalUtils.<Object>createCollection();
    LinkedList<OWLIndividual> list = new LinkedList<OWLIndividual>(arg.getIndividualsAsList());
    Iterator<OWLIndividual> it1, it2;
    it1 = list.iterator();
    while (it1.hasNext()) {
        OWLIndividual individu1 = it1.next();
        it1.remove();
        Term t1 = GraalUtils.createTerm(individu1);
        it2 = list.iterator();
        while (it2.hasNext()) {
            OWLIndividual individu2 = it2.next();
            Term t2 = GraalUtils.createTerm(individu2);
            Atom a = new DefaultAtom(equalityPredicate, t1, t2);
            c.add(new DefaultNegativeConstraint(new LinkedListAtomSet(a)));
        }
    }
    return c;
}
Also used : DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) Term(fr.lirmm.graphik.graal.api.core.Term) LinkedList(java.util.LinkedList) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Atom(fr.lirmm.graphik.graal.api.core.Atom) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual)

Example 3 with Term

use of fr.lirmm.graphik.graal.api.core.Term 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 4 with Term

use of fr.lirmm.graphik.graal.api.core.Term 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 5 with Term

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

the class OWLAxiomParser method visit.

@Override
public Iterable<? extends Object> visit(OWLNegativeDataPropertyAssertionAxiom arg) {
    freeVarGen.setIndex(0);
    Term a = GraalUtils.createTerm(arg.getSubject());
    Term b = GraalUtils.createLiteral(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)

Aggregations

Term (fr.lirmm.graphik.graal.api.core.Term)173 Atom (fr.lirmm.graphik.graal.api.core.Atom)86 LinkedList (java.util.LinkedList)41 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)36 Test (org.junit.Test)35 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)34 Variable (fr.lirmm.graphik.graal.api.core.Variable)32 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)27 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)26 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)23 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)18 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)15 Rule (fr.lirmm.graphik.graal.api.core.Rule)15 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)14 TreeSet (java.util.TreeSet)12 Constant (fr.lirmm.graphik.graal.api.core.Constant)9 DBTable (fr.lirmm.graphik.graal.store.rdbms.util.DBTable)9 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9 TreeMap (java.util.TreeMap)8