Search in sources :

Example 1 with OWLDataPropertyExpression

use of org.semanticweb.owlapi.model.OWLDataPropertyExpression 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 2 with OWLDataPropertyExpression

use of org.semanticweb.owlapi.model.OWLDataPropertyExpression in project graal by graphik-team.

the class OWLAPIUtils method classExpressionDisjunctiveNormalForm.

/**
 * disjunctive normal form
 *
 * @param classExpression
 * @return a {@link OWLClassExpression} in disjunctive normal form equivalents to the specified one
 */
public static OWLClassExpression classExpressionDisjunctiveNormalForm(OWLClassExpression classExpression) {
    if (classExpression instanceof OWLObjectUnionOf) {
        Set<OWLClassExpression> union = new TreeSet<>();
        for (OWLClassExpression element : OWLAPIUtils.getObjectUnionOperands(classExpression)) {
            element = classExpressionDisjunctiveNormalForm(element);
            for (OWLClassExpression e : OWLAPIUtils.getObjectUnionOperands(element)) {
                union.add(e);
            }
        }
        return new OWLObjectUnionOfImpl(union);
    } else if (classExpression instanceof OWLObjectIntersectionOf) {
        List<Set<OWLClassExpression>> conjunctions = new LinkedList<>();
        conjunctions.add(new TreeSet<OWLClassExpression>());
        for (OWLClassExpression element : OWLAPIUtils.getObjectIntersectionOperands(classExpression)) {
            element = classExpressionDisjunctiveNormalForm(element);
            if (element instanceof OWLObjectUnionOf) {
                List<Set<OWLClassExpression>> tmp = new LinkedList<>();
                for (Set<OWLClassExpression> conj : conjunctions) {
                    for (OWLClassExpression e : OWLAPIUtils.getObjectUnionOperands(element)) {
                        Set<OWLClassExpression> newConj = new TreeSet<>(conj);
                        newConj.add(classExpressionDisjunctiveNormalForm(e));
                        tmp.add(newConj);
                    }
                }
                conjunctions = tmp;
            } else {
                for (Set<OWLClassExpression> conj : conjunctions) {
                    for (OWLClassExpression e : OWLAPIUtils.getObjectIntersectionOperands(element)) {
                        conj.add(e);
                    }
                }
            }
        }
        Set<OWLClassExpression> union = new TreeSet<>();
        if (conjunctions.size() > 1) {
            for (Set<OWLClassExpression> conj : conjunctions) {
                union.add(new OWLObjectIntersectionOfImpl(conj));
            }
            return new OWLObjectUnionOfImpl(union);
        } else {
            return new OWLObjectIntersectionOfImpl(conjunctions.get(0));
        }
    } else if (classExpression instanceof OWLObjectSomeValuesFrom) {
        OWLObjectSomeValuesFrom expr = (OWLObjectSomeValuesFrom) classExpression;
        OWLObjectPropertyExpression prop = expr.getProperty();
        OWLClassExpression filler = classExpressionDisjunctiveNormalForm(expr.getFiller());
        if (filler instanceof OWLObjectUnionOf) {
            Set<OWLClassExpression> union = new TreeSet<>();
            for (OWLClassExpression e : OWLAPIUtils.getObjectUnionOperands(filler)) {
                e = classExpressionDisjunctiveNormalForm(e);
                union.add(new OWLObjectSomeValuesFromImpl(prop, e));
            }
            return new OWLObjectUnionOfImpl(union);
        }
        return new OWLObjectSomeValuesFromImpl(prop, filler);
    } else if (classExpression instanceof OWLDataSomeValuesFrom) {
        OWLDataSomeValuesFrom expr = (OWLDataSomeValuesFrom) classExpression;
        OWLDataPropertyExpression prop = expr.getProperty();
        OWLDataRange filler = dataRangeDisjunctiveNormalForm(expr.getFiller());
        if (filler instanceof OWLDataUnionOf) {
            Set<OWLClassExpression> union = new TreeSet<>();
            for (OWLDataRange e : OWLAPIUtils.getDataUnionOperands(filler)) {
                e = dataRangeDisjunctiveNormalForm(e);
                union.add(new OWLDataSomeValuesFromImpl(prop, e));
            }
            return new OWLObjectUnionOfImpl(union);
        }
        return new OWLDataSomeValuesFromImpl(prop, filler);
    } else if (classExpression instanceof OWLObjectOneOf) {
        OWLObjectOneOf expr = (OWLObjectOneOf) classExpression;
        if (expr.getIndividuals().size() <= 1) {
            return expr;
        }
        Set<OWLClassExpression> union = new TreeSet<>();
        for (OWLIndividual i : expr.getIndividuals()) {
            Set<OWLIndividual> individuals = Collections.singleton(i);
            union.add(new OWLObjectOneOfImpl(individuals));
        }
        return new OWLObjectUnionOfImpl(union);
    } else if (classExpression instanceof OWLObjectAllValuesFrom) {
        OWLObjectAllValuesFrom expr = (OWLObjectAllValuesFrom) classExpression;
        return new OWLObjectAllValuesFromImpl(expr.getProperty(), classExpressionDisjunctiveNormalForm(expr.getFiller()));
    } else if (classExpression instanceof OWLDataAllValuesFrom) {
        OWLDataAllValuesFrom expr = (OWLDataAllValuesFrom) classExpression;
        return new OWLDataAllValuesFromImpl(expr.getProperty(), dataRangeDisjunctiveNormalForm(expr.getFiller()));
    } else if (classExpression instanceof OWLObjectComplementOf) {
        OWLObjectComplementOf expr = (OWLObjectComplementOf) classExpression;
        return new OWLObjectComplementOfImpl(classExpressionDisjunctiveNormalForm(expr.getOperand()));
    } else if (classExpression instanceof OWLObjectMinCardinality) {
        OWLObjectMinCardinality c = (OWLObjectMinCardinality) classExpression;
        return new OWLObjectMinCardinalityImpl(c.getProperty(), c.getCardinality(), classExpressionDisjunctiveNormalForm(c.getFiller()));
    } else if (classExpression instanceof OWLDataMinCardinality) {
        OWLDataMinCardinality c = (OWLDataMinCardinality) classExpression;
        return new OWLDataMinCardinalityImpl(c.getProperty(), c.getCardinality(), dataRangeDisjunctiveNormalForm(c.getFiller()));
    } else if (classExpression instanceof OWLObjectMaxCardinality) {
        OWLObjectMaxCardinality c = (OWLObjectMaxCardinality) classExpression;
        return new OWLObjectMaxCardinalityImpl(c.getProperty(), c.getCardinality(), classExpressionDisjunctiveNormalForm(c.getFiller()));
    } else if (classExpression instanceof OWLDataMaxCardinality) {
        OWLDataMaxCardinality c = (OWLDataMaxCardinality) classExpression;
        return new OWLDataMaxCardinalityImpl(c.getProperty(), c.getCardinality(), dataRangeDisjunctiveNormalForm(c.getFiller()));
    } else if (classExpression instanceof OWLObjectExactCardinality) {
        OWLObjectExactCardinality c = (OWLObjectExactCardinality) classExpression;
        return new OWLObjectExactCardinalityImpl(c.getProperty(), c.getCardinality(), classExpressionDisjunctiveNormalForm(c.getFiller()));
    } else if (classExpression instanceof OWLDataExactCardinality) {
        OWLDataExactCardinality c = (OWLDataExactCardinality) classExpression;
        return new OWLDataExactCardinalityImpl(c.getProperty(), c.getCardinality(), dataRangeDisjunctiveNormalForm(c.getFiller()));
    }
    return classExpression;
}
Also used : OWLObjectOneOf(org.semanticweb.owlapi.model.OWLObjectOneOf) OWLObjectComplementOfImpl(uk.ac.manchester.cs.owl.owlapi.OWLObjectComplementOfImpl) OWLDataMinCardinalityImpl(uk.ac.manchester.cs.owl.owlapi.OWLDataMinCardinalityImpl) TreeSet(java.util.TreeSet) Set(java.util.Set) OWLDataUnionOf(org.semanticweb.owlapi.model.OWLDataUnionOf) OWLDataAllValuesFrom(org.semanticweb.owlapi.model.OWLDataAllValuesFrom) OWLDataExactCardinality(org.semanticweb.owlapi.model.OWLDataExactCardinality) OWLDataRange(org.semanticweb.owlapi.model.OWLDataRange) OWLDataMaxCardinality(org.semanticweb.owlapi.model.OWLDataMaxCardinality) TreeSet(java.util.TreeSet) OWLDataMaxCardinalityImpl(uk.ac.manchester.cs.owl.owlapi.OWLDataMaxCardinalityImpl) OWLObjectPropertyExpression(org.semanticweb.owlapi.model.OWLObjectPropertyExpression) OWLDataSomeValuesFrom(org.semanticweb.owlapi.model.OWLDataSomeValuesFrom) OWLObjectMinCardinality(org.semanticweb.owlapi.model.OWLObjectMinCardinality) LinkedList(java.util.LinkedList) List(java.util.List) OWLObjectMaxCardinalityImpl(uk.ac.manchester.cs.owl.owlapi.OWLObjectMaxCardinalityImpl) OWLObjectUnionOfImpl(uk.ac.manchester.cs.owl.owlapi.OWLObjectUnionOfImpl) OWLDataMinCardinality(org.semanticweb.owlapi.model.OWLDataMinCardinality) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual) OWLDataPropertyExpression(org.semanticweb.owlapi.model.OWLDataPropertyExpression) OWLObjectComplementOf(org.semanticweb.owlapi.model.OWLObjectComplementOf) OWLObjectOneOfImpl(uk.ac.manchester.cs.owl.owlapi.OWLObjectOneOfImpl) OWLObjectSomeValuesFromImpl(uk.ac.manchester.cs.owl.owlapi.OWLObjectSomeValuesFromImpl) OWLObjectUnionOf(org.semanticweb.owlapi.model.OWLObjectUnionOf) OWLClassExpression(org.semanticweb.owlapi.model.OWLClassExpression) OWLObjectIntersectionOfImpl(uk.ac.manchester.cs.owl.owlapi.OWLObjectIntersectionOfImpl) OWLObjectMinCardinalityImpl(uk.ac.manchester.cs.owl.owlapi.OWLObjectMinCardinalityImpl) OWLDataSomeValuesFromImpl(uk.ac.manchester.cs.owl.owlapi.OWLDataSomeValuesFromImpl) OWLObjectAllValuesFrom(org.semanticweb.owlapi.model.OWLObjectAllValuesFrom) OWLObjectMaxCardinality(org.semanticweb.owlapi.model.OWLObjectMaxCardinality) OWLObjectSomeValuesFrom(org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom) OWLDataAllValuesFromImpl(uk.ac.manchester.cs.owl.owlapi.OWLDataAllValuesFromImpl) OWLObjectExactCardinality(org.semanticweb.owlapi.model.OWLObjectExactCardinality) OWLObjectExactCardinalityImpl(uk.ac.manchester.cs.owl.owlapi.OWLObjectExactCardinalityImpl) OWLDataExactCardinalityImpl(uk.ac.manchester.cs.owl.owlapi.OWLDataExactCardinalityImpl) OWLObjectIntersectionOf(org.semanticweb.owlapi.model.OWLObjectIntersectionOf) OWLObjectAllValuesFromImpl(uk.ac.manchester.cs.owl.owlapi.OWLObjectAllValuesFromImpl)

Aggregations

OWLClassExpression (org.semanticweb.owlapi.model.OWLClassExpression)2 OWLDataPropertyExpression (org.semanticweb.owlapi.model.OWLDataPropertyExpression)2 OWLObjectPropertyExpression (org.semanticweb.owlapi.model.OWLObjectPropertyExpression)2 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)1 Rule (fr.lirmm.graphik.graal.api.core.Rule)1 Term (fr.lirmm.graphik.graal.api.core.Term)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 OWLDataAllValuesFrom (org.semanticweb.owlapi.model.OWLDataAllValuesFrom)1 OWLDataExactCardinality (org.semanticweb.owlapi.model.OWLDataExactCardinality)1 OWLDataMaxCardinality (org.semanticweb.owlapi.model.OWLDataMaxCardinality)1 OWLDataMinCardinality (org.semanticweb.owlapi.model.OWLDataMinCardinality)1 OWLDataRange (org.semanticweb.owlapi.model.OWLDataRange)1 OWLDataSomeValuesFrom (org.semanticweb.owlapi.model.OWLDataSomeValuesFrom)1 OWLDataUnionOf (org.semanticweb.owlapi.model.OWLDataUnionOf)1 OWLIndividual (org.semanticweb.owlapi.model.OWLIndividual)1 OWLObjectAllValuesFrom (org.semanticweb.owlapi.model.OWLObjectAllValuesFrom)1 OWLObjectComplementOf (org.semanticweb.owlapi.model.OWLObjectComplementOf)1