Search in sources :

Example 71 with InMemoryAtomSet

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

the class Rules method getPieces.

/**
 * Compute and return the set of pieces of the head according to the
 * frontier. On Rules with Existential Variables: Walking the Decidability
 * Line Jean-François Baget, Michel Leclère, Marie-Laure Mugnier, Eric
 * Salvat
 *
 * @return a Collection ofInMemoryAtomSet representing the set of pieces of the head of the specified rule.
 */
public static Collection<InMemoryAtomSet> getPieces(Rule rule) {
    Set<Variable> existentials = rule.getExistentials();
    Collection<InMemoryAtomSet> pieces = new LinkedList<InMemoryAtomSet>();
    // compute equivalent classes
    EquivalentRelation<Term> classes = new TreeMapEquivalentRelation<Term>();
    CloseableIteratorWithoutException<Atom> it = rule.getHead().iterator();
    while (it.hasNext()) {
        Atom a = it.next();
        Term representant = null;
        for (Term t : a) {
            if (existentials.contains(t)) {
                if (representant == null)
                    representant = t;
                else
                    classes.mergeClasses(representant, t);
            }
        }
    }
    // init pieces for equivalent classes
    Map<Integer, InMemoryAtomSet> tmpPieces = new TreeMap<Integer, InMemoryAtomSet>();
    for (Term e : existentials) {
        if (tmpPieces.get(classes.getIdClass(e)) == null) {
            tmpPieces.put(classes.getIdClass(e), DefaultAtomSetFactory.instance().create());
        }
    }
    // Affect atoms to one pieces
    boolean isAffected;
    InMemoryAtomSet atomset;
    Term e;
    it = rule.getHead().iterator();
    while (it.hasNext()) {
        Atom a = it.next();
        isAffected = false;
        Iterator<Variable> it2 = existentials.iterator();
        while (it2.hasNext() && !isAffected) {
            e = it2.next();
            if (a.getTerms().contains(e)) {
                tmpPieces.get(classes.getIdClass(e)).add(a);
                isAffected = true;
            }
        }
        if (!isAffected) {
            // does not contain existential variable
            atomset = DefaultAtomSetFactory.instance().create();
            atomset.add(a);
            pieces.add(atomset);
        }
    }
    pieces.addAll(tmpPieces.values());
    return pieces;
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) Term(fr.lirmm.graphik.graal.api.core.Term) TreeMap(java.util.TreeMap) LinkedList(java.util.LinkedList) Atom(fr.lirmm.graphik.graal.api.core.Atom) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) TreeMapEquivalentRelation(fr.lirmm.graphik.util.TreeMapEquivalentRelation)

Example 72 with InMemoryAtomSet

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

the class Rules method computeSinglePiece.

/**
 * Generate a set of mono-piece rules equivalent of the specified rule.
 *
 * @param rule
 * @return a Collection of Rule which is a decomposition of the specified rule to single piece rules.
 */
public static Collection<Rule> computeSinglePiece(Rule rule) {
    String label = rule.getLabel();
    Collection<Rule> monoPiece = new LinkedList<Rule>();
    if (label.isEmpty()) {
        for (InMemoryAtomSet piece : getPieces(rule)) {
            monoPiece.add(DefaultRuleFactory.instance().create(rule.getBody(), piece));
        }
    } else {
        int i = -1;
        for (InMemoryAtomSet piece : getPieces(rule)) {
            monoPiece.add(DefaultRuleFactory.instance().create(label + "-p" + ++i, rule.getBody(), piece));
        }
    }
    return monoPiece;
}
Also used : InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) LinkedList(java.util.LinkedList)

Example 73 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(OWLReflexiveObjectPropertyAxiom arg) {
    InMemoryAtomSet head = arg.getProperty().accept(propertyVisiotrXX);
    InMemoryAtomSet body = GraalUtils.createAtomSet(new DefaultAtom(Predicate.TOP, glueVarX));
    return Collections.singleton(DefaultRuleFactory.instance().create(body, head));
}
Also used : DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)

Example 74 with InMemoryAtomSet

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

the class OWLAxiomParser method equivalentPropertiesAxiom.

private Iterable<? extends Object> equivalentPropertiesAxiom(Iterable<? extends OWLPropertyExpression> properties) {
    Collection<Rule> rules = GraalUtils.<Rule>createCollection();
    InMemoryAtomSet 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);
            rules.add(DefaultRuleFactory.instance().create(a1, a2));
            rules.add(DefaultRuleFactory.instance().create(a2, a1));
        }
    }
    return rules;
}
Also used : OWLPropertyExpression(org.semanticweb.owlapi.model.OWLPropertyExpression) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) SWRLRule(org.semanticweb.owlapi.model.SWRLRule)

Example 75 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(OWLAsymmetricObjectPropertyAxiom arg) {
    InMemoryAtomSet atomset = arg.getProperty().accept(propertyVisitorXY);
    atomset.addAll(arg.getProperty().accept(propertyVisitorYX));
    return Collections.singleton(new DefaultNegativeConstraint(atomset));
}
Also used : DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)

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