for (final BasicOperator bo : path) {
if (bo instanceof Generate) {
triple = new Item[3];
final Generate generate = (Generate) bo;
for (int i = 0; i < 3; i++) {
Item item = generate.getValueOrVariable()[i];
if (item.isVariable()) {
if (bindings.get(item) != null) {
item = bindings.get(item);
}
}
triple[i] = item;
}
// is a constant triple generated?
if (!triple[0].isVariable() && !triple[1].isVariable()
&& !triple[2].isVariable()) {
disconnect.add(path.get(1));
final Generate generateInstead = new Generate(triple);
final LinkedList<OperatorIDTuple> llo = new LinkedList<OperatorIDTuple>();
llo.addAll(bo.getSucceedingOperators());
// delete path from the successors:
final int index = path.indexOf(new OperatorIDTuple(bo, -1));
final BasicOperator afterInPath = (index == path.size() - 1) ? path
.get(0)
: path.get(index + 1);
llo.remove(new OperatorIDTuple(afterInPath, -1));
generateInstead.setSucceedingOperators(llo);
instead.add(generateInstead);
return true;
}
}
if (bo instanceof TriplePattern) {
bindings = new HashMap<Variable, Item>();
final Item[] items = ((TriplePattern) bo).getItems();
int i = 0;
for (final Item item : items) {
if (item.isVariable()) {
bindings.put((Variable) item, triple[i]);
} else {
if (!((Literal) item).equals(triple[i])) {
if (!triple[i].isVariable()) {
System.out
.println("RuleEliminateInfinityLoop: The generated triple will not be consumed by the succeeding triple pattern!");
return false;
}
}
}
i++;
}
}
}
// is again the same triple generated as by the first call of the first
// generate?
if (path.get(0) instanceof Generate) {
triple = new Item[3];
final Generate generate = (Generate) path.get(0);
for (int i = 0; i < 3; i++) {
Item item = generate.getValueOrVariable()[i];
if (item.isVariable()) {
if (bindings.get(item) != null) {
item = bindings.get(item);
}
}
triple[i] = item;