Search in sources :

Example 46 with Variable

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

the class AbstractAffectedPositionSet method step1.

/**
 * for each rule and for each existentially quantified variable occuring at
 * position p[i] in its head, p[i] is affected;
 */
protected void step1() {
    int i;
    Set<Variable> existentials;
    PredicatePosition predicatePosition;
    for (Rule rule : ruleSet) {
        existentials = rule.getExistentials();
        CloseableIteratorWithoutException<Atom> it = rule.getHead().iterator();
        while (it.hasNext()) {
            Atom atom = it.next();
            i = -1;
            for (Term t : atom) {
                ++i;
                if (existentials.contains(t)) {
                    predicatePosition = new PredicatePosition(atom.getPredicate(), i);
                    this.affectedPosition.add(predicatePosition);
                }
            }
        }
    }
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) PredicatePosition(fr.lirmm.graphik.graal.rulesetanalyser.util.PredicatePosition) Rule(fr.lirmm.graphik.graal.api.core.Rule) Term(fr.lirmm.graphik.graal.api.core.Term) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 47 with Variable

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

the class GraphPositionDependencies method init.

private void init() {
    int bodyTermIndex, headTermIndex;
    Set<Variable> existentials;
    for (Rule r : this.rules) {
        existentials = r.getExistentials();
        CloseableIteratorWithoutException<Atom> bodyIt = r.getBody().iterator();
        while (bodyIt.hasNext()) {
            Atom bodyAtom = bodyIt.next();
            bodyTermIndex = -1;
            for (Term bodyTerm : bodyAtom) {
                ++bodyTermIndex;
                if (r.getHead().getTerms().contains(bodyTerm)) {
                    CloseableIteratorWithoutException<Atom> headIt = r.getHead().iterator();
                    while (headIt.hasNext()) {
                        Atom headAtom = headIt.next();
                        headTermIndex = -1;
                        for (Term headTerm : headAtom) {
                            ++headTermIndex;
                            if (bodyTerm.equals(headTerm)) {
                                this.addEdge(new PredicatePosition(bodyAtom.getPredicate(), bodyTermIndex), new PredicatePosition(headAtom.getPredicate(), headTermIndex));
                            } else if (existentials.contains(headTerm)) {
                                this.addSpecialEdge(new PredicatePosition(bodyAtom.getPredicate(), bodyTermIndex), new PredicatePosition(headAtom.getPredicate(), headTermIndex));
                            }
                        }
                    }
                } else {
                    if (!this.graph.containsVertex(new PredicatePosition(bodyAtom.getPredicate(), bodyTermIndex))) {
                        this.graph.addVertex(new PredicatePosition(bodyAtom.getPredicate(), bodyTermIndex));
                    }
                }
            }
        }
    }
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) PredicatePosition(fr.lirmm.graphik.graal.rulesetanalyser.util.PredicatePosition) Rule(fr.lirmm.graphik.graal.api.core.Rule) Term(fr.lirmm.graphik.graal.api.core.Term) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 48 with Variable

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

the class OWLEquivalentClassExpressionVisitorImpl method visit.

@Override
public InMemoryAtomSet visit(OWLDataSomeValuesFrom arg) {
    Variable newGlueVariable = varGen.getFreshSymbol();
    InMemoryAtomSet atomset = arg.getProperty().accept(new OWLPropertyExpressionVisitorImpl(glueVariable, newGlueVariable));
    if (!arg.getFiller().equals(DF.getTopDatatype())) {
        atomset.addAll(arg.getFiller().accept(new OWLEquivalentDataRangeVisitorImpl(newGlueVariable)));
    }
    return atomset;
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)

Example 49 with Variable

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

the class RuleMLWriter method write.

@Override
public RuleMLWriter write(Rule rule) throws IOException {
    Set<Variable> existVar = rule.getExistentials();
    Set<Variable> universalVar = rule.getVariables();
    universalVar.removeAll(existVar);
    CloseableIteratorWithoutException<Atom> it = rule.getHead().iterator();
    if (it.hasNext()) {
        it.next();
    }
    boolean isAtomicHead = !it.hasNext();
    this.openBalise("Assert");
    this.writeLabel(rule.getLabel());
    this.openBalise("Forall");
    for (Term t : universalVar) {
        this.writeTerm(t);
    }
    this.openBalise("Implies");
    this.openBalise("if");
    this.openBalise("And");
    this.writeAtomSet(rule.getBody().iterator());
    this.closeBaliseWithReturnLine("And");
    this.closeBaliseWithReturnLine("if");
    this.openBalise("then");
    if (!existVar.isEmpty()) {
        this.openBalise("Exists");
        for (Term t : existVar) {
            this.writeTerm(t);
        }
    }
    if (!isAtomicHead) {
        this.openBalise("And");
    }
    this.writeAtomSet(rule.getHead().iterator());
    if (!isAtomicHead) {
        this.closeBaliseWithReturnLine("And");
    }
    if (!existVar.isEmpty()) {
        this.closeBaliseWithReturnLine("Exists");
    }
    this.closeBaliseWithReturnLine("then");
    this.closeBaliseWithReturnLine("Implies");
    this.closeBaliseWithReturnLine("Forall");
    this.closeBaliseWithReturnLine("Assert");
    return this;
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) Term(fr.lirmm.graphik.graal.api.core.Term) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 50 with Variable

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

the class RestrictedProductivityChecker method isValidDependency.

// /////////////////////////////////////////////////////////////////////////
// 
// /////////////////////////////////////////////////////////////////////////
@Override
public boolean isValidDependency(Rule r1, Rule r2, Substitution s) {
    InMemoryAtomSet b1 = s.createImageOf(r1.getBody());
    InMemoryAtomSet h1 = s.createImageOf(r1.getHead());
    InMemoryAtomSet b2 = s.createImageOf(r2.getBody());
    InMemoryAtomSet h2 = s.createImageOf(r2.getHead());
    InMemoryAtomSet f = new LinkedListAtomSet();
    f.addAll(b1.iterator());
    f.addAll(h1.iterator());
    f.addAll(b2.iterator());
    Set<Variable> fixedVariables = h2.getVariables();
    fixedVariables.retainAll(b2.getVariables());
    try {
        ConjunctiveQueryWithFixedVariables query = new ConjunctiveQueryWithFixedVariables(h2, fixedVariables);
        return !PureHomomorphism.instance().exist(query.getAtomSet(), f);
    } catch (HomomorphismException e) {
        // TODO treat this exception
        e.printStackTrace();
        throw new Error("Untreated exception");
    }
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) ConjunctiveQueryWithFixedVariables(fr.lirmm.graphik.graal.core.ConjunctiveQueryWithFixedVariables)

Aggregations

Variable (fr.lirmm.graphik.graal.api.core.Variable)57 Atom (fr.lirmm.graphik.graal.api.core.Atom)33 Term (fr.lirmm.graphik.graal.api.core.Term)32 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)25 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)19 LinkedList (java.util.LinkedList)15 Test (org.junit.Test)15 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)8 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)8 Constant (fr.lirmm.graphik.graal.api.core.Constant)7 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)6 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)6 Rule (fr.lirmm.graphik.graal.api.core.Rule)6 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)6 ConversionException (fr.lirmm.graphik.util.stream.converter.ConversionException)6 VarSharedData (fr.lirmm.graphik.graal.homomorphism.VarSharedData)5 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)4 DefaultConjunctiveQueryWithNegatedParts (fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts)4 HashMapSubstitution (fr.lirmm.graphik.graal.core.HashMapSubstitution)4 DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)4