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);
}
}
}
}
}
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));
}
}
}
}
}
}
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;
}
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;
}
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");
}
}
Aggregations