final Union union = new Union();
final TriggerOneTime trigger = new TriggerOneTime();
while (it.hasNext()) {
final Triple t = it.next();
BasicOperator lastOperator = union;
for (int i = 0; i < 3; i++) {
if (tp.getPos(i).isVariable()) {
final AddBinding add = new AddBinding(
(Variable) tp.getPos(i), t
.getPos(i));
add
.addSucceedingOperator(new OperatorIDTuple(
lastOperator, 0));
// Not completely correct, but for
// the succeeding optimization steps
// enough!
add
.setUnionVariables((HashSet<Variable>) tp
.getVariables().clone());
add.setIntersectionVariables(add
.getUnionVariables());
lastOperator.addPrecedingOperator(add);
lastOperator = add;
}
}
trigger.addSucceedingOperator(new OperatorIDTuple(
lastOperator, 0));
}
if (trigger.getSucceedingOperators().size() > 0) {
trigger.setPrecedingOperators(tp
.getPrecedingOperators());
for (final BasicOperator po : tp
.getPrecedingOperators()) {
po.addSucceedingOperator(new OperatorIDTuple(
trigger, 0));
}
BasicOperator lo = union;
if (union.getPrecedingOperators().size() == 1
&& isOntologyTriplePattern == ISONTOLOGYTRIPLEPATTERN.YES) {
lo = union.getPrecedingOperators().get(0);
}
lo.setSucceedingOperators(tp
.getSucceedingOperators());
for (final OperatorIDTuple so : tp
.getSucceedingOperators()) {
so.getOperator().addPrecedingOperator(lo);
}
}
if (tp.getPrecedingOperators().size() != 1) {
System.err
.println("Something is wrong! Triple pattern has not exactly one preceding operator!");
}
for (final OperatorIDTuple so : tp
.getSucceedingOperators()) {
so.getOperator().removePrecedingOperator(tp);
}
// if (isOntologyTriplePattern ==
// ISONTOLOGYTRIPLEPATTERN.YES) {
// then delete the old triple pattern
final BasicOperator po = tp.getPrecedingOperators()
.get(0);
po.removeSucceedingOperator(tp);
// } else {
// // otherwise do not delete old triple pattern and
// // make the union operator its succeeding operator!
// tp.setSucceedingOperator(new OperatorIDTuple(union,
// union.getPrecedingOperators().size()));