if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
projection.addProjectionElement((Variable)graphConstraint);
}
final Union union = new Union();
final InMemoryDistinct memoryDistinct = new InMemoryDistinct();
try {
final Filter filter = new Filter("(" + subject + " != " + object + ")");
final ReplaceVar replaceVar = new ReplaceVar();
replaceVar.addSubstitution(object, subject);
final Variable variable = this.getVariable(subject.toString(), object.toString(), "interimVariable");
replaceVar.addSubstitution(variable, object);
if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
replaceVar.addSubstitution((Variable)graphConstraint, (Variable)graphConstraint);
}
final ReplaceVar replaceVari = new ReplaceVar();
replaceVari.addSubstitution(subject, subject);
replaceVari.addSubstitution(object, variable);
if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
replaceVari.addSubstitution((Variable)graphConstraint, (Variable)graphConstraint);
}
startingOperator.addSucceedingOperator(new OperatorIDTuple(filter,0));
startingOperator.addSucceedingOperator(new OperatorIDTuple(union,1));
final Join intermediateJoinOperator = new Join();
replaceVar.addSucceedingOperator(new OperatorIDTuple(memoryDistinct,0));
memoryDistinct.addSucceedingOperator(new OperatorIDTuple(intermediateJoinOperator,1));
filter.addSucceedingOperator(new OperatorIDTuple(intermediateJoinOperator,0));
filter.addSucceedingOperator(new OperatorIDTuple(replaceVar,0));
intermediateJoinOperator.addSucceedingOperator(new OperatorIDTuple(replaceVari,0));
replaceVari.addSucceedingOperator(new OperatorIDTuple(replaceVar,0));
replaceVari.addSucceedingOperator(new OperatorIDTuple(union,1));