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