objectIsALiteral = true;
} else {
object = (Variable) itm;
}
final Node objectNode = tripleSet.jjtGetChild(2);
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);
}
final BasicOperator startingOperator =tripleSet.jjtGetChild(1).jjtGetChild(0).accept(this, connection, graphConstraint, subject, object, subjectNode, objectNode);
final InMemoryDistinct memoryDistinct = new InMemoryDistinct();
final Filter filter = new Filter("(" + subject + " != " + object + ")");
startingOperator.addSucceedingOperator(new OperatorIDTuple(filter,0));
startingOperator.addSucceedingOperator(connection.getOperatorIDTuple());
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(connection.getOperatorIDTuple());
if(subjectIsALiteral && !objectIsALiteral){
final Filter firstFilter = new Filter("(" + subject + " = " + realSubject +")");
final Filter secondFilter = new Filter("(" + subject + " = " + realSubject +")");
final Projection firstProjection = new Projection();
firstProjection.addProjectionElement(object);
if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
firstProjection.addProjectionElement((Variable)graphConstraint);
}
final Projection secondProjection = new Projection();
secondProjection.addProjectionElement(object);
if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
secondProjection.addProjectionElement((Variable)graphConstraint);
}
firstFilter.addSucceedingOperator(new OperatorIDTuple(firstProjection,0));
secondFilter.addSucceedingOperator(new OperatorIDTuple(secondProjection,0));
firstProjection.addSucceedingOperator(connection.getOperatorIDTuple());
secondProjection.addSucceedingOperator(connection.getOperatorIDTuple());
replaceVari.addSucceedingOperator(new OperatorIDTuple(secondFilter,0));
replaceVari.removeSucceedingOperator(connection.getOperatorIDTuple().getOperator());
startingOperator.addSucceedingOperator(new OperatorIDTuple(firstFilter,0));
startingOperator.removeSucceedingOperator(connection.getOperatorIDTuple().getOperator());
}
if(!subjectIsALiteral && objectIsALiteral){
final Filter firstFilter = new Filter("(" + object + " = " + realObject + ")");
final Filter secondFilter = new Filter("(" + object + " = " + realObject + ")");
final Projection firstProjection = new Projection();
firstProjection.addProjectionElement(subject);
if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
firstProjection.addProjectionElement((Variable)graphConstraint);
}
final Projection secondProjection = new Projection();
secondProjection.addProjectionElement(subject);
if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
secondProjection.addProjectionElement((Variable)graphConstraint);
}
firstFilter.addSucceedingOperator(new OperatorIDTuple(firstProjection,0));
secondFilter.addSucceedingOperator(new OperatorIDTuple(secondProjection,0));
firstProjection.addSucceedingOperator(connection.getOperatorIDTuple());
secondProjection.addSucceedingOperator(connection.getOperatorIDTuple());
replaceVari.addSucceedingOperator(new OperatorIDTuple(secondFilter,0));
replaceVari.removeSucceedingOperator(connection.getOperatorIDTuple().getOperator());
startingOperator.addSucceedingOperator(new OperatorIDTuple(firstFilter,0));
startingOperator.removeSucceedingOperator(connection.getOperatorIDTuple().getOperator());
}
if(subjectIsALiteral && objectIsALiteral){
final Filter firstFilter = new Filter("(" + object + " = " + realObject + ")");
final Filter secondFilter = new Filter("(" + subject + " = " + realSubject + ")");
final Filter thirdFilter = new Filter("(" + object + " = " + realObject + ")");
final Filter fourthFilter = new Filter("(" + subject + " = " + realSubject + ")");
final Projection firstProjection = new Projection();
firstProjection.addProjectionElement(subject);
if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
firstProjection.addProjectionElement((Variable)graphConstraint);
}
final Projection secondProjection = new Projection();
secondProjection.addProjectionElement(object);
if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
secondProjection.addProjectionElement((Variable)graphConstraint);
}
final Projection thirdProjection = new Projection();
thirdProjection.addProjectionElement(subject);
if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
thirdProjection.addProjectionElement((Variable)graphConstraint);
}
final Projection fourthProjection = new Projection();
fourthProjection.addProjectionElement(object);
if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
fourthProjection.addProjectionElement((Variable)graphConstraint);
}
firstFilter.addSucceedingOperator(new OperatorIDTuple(firstProjection,0));
secondFilter.addSucceedingOperator(new OperatorIDTuple(secondProjection,0));
thirdFilter.addSucceedingOperator(new OperatorIDTuple(thirdProjection,0));
fourthFilter.addSucceedingOperator(new OperatorIDTuple(fourthProjection,0));
firstProjection.addSucceedingOperator(new OperatorIDTuple(secondFilter, 0));
secondProjection.addSucceedingOperator(connection.getOperatorIDTuple());
thirdProjection.addSucceedingOperator(new OperatorIDTuple(fourthFilter, 0));
fourthProjection.addSucceedingOperator(connection.getOperatorIDTuple());
replaceVari.addSucceedingOperator(new OperatorIDTuple(thirdFilter,0));
replaceVari.removeSucceedingOperator(connection.getOperatorIDTuple().getOperator());
startingOperator.addSucceedingOperator(new OperatorIDTuple(firstFilter,0));
startingOperator.removeSucceedingOperator(connection.getOperatorIDTuple().getOperator());
}
}