if(!subjectIsALiteral && !objectIsALiteral){
startingOperator.addSucceedingOperator(connection.getOperatorIDTuple());
}
else
if(subjectIsALiteral && !objectIsALiteral){
final Filter filter = new Filter("(" + subject + " = " + realSubject +")");
final Projection projection = new Projection();
projection.addProjectionElement(object);
if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
projection.addProjectionElement((Variable)graphConstraint);
}
filter.addSucceedingOperator(new OperatorIDTuple(projection,0));
projection.addSucceedingOperator(connection.getOperatorIDTuple());
startingOperator.addSucceedingOperator(new OperatorIDTuple(filter,0));
}
else
if(!subjectIsALiteral && objectIsALiteral){
final Filter filter = new Filter("(" + object + " = " + realObject + ")");
final Projection projection = new Projection();
projection.addProjectionElement(subject);
if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
projection.addProjectionElement((Variable)graphConstraint);
}
filter.addSucceedingOperator(new OperatorIDTuple(projection,0));
projection.addSucceedingOperator(connection.getOperatorIDTuple());
startingOperator.addSucceedingOperator(new OperatorIDTuple(filter,0));
}
else
if(subjectIsALiteral && objectIsALiteral){
final Filter firstFilter = new Filter("(" + object + " = " + realObject + ")");
final Filter secondFilter = 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);
}
firstFilter.addSucceedingOperator(new OperatorIDTuple(firstProjection,0));
firstProjection.addSucceedingOperator(new OperatorIDTuple(secondFilter, 0));
secondFilter.addSucceedingOperator(new OperatorIDTuple(secondProjection,0));
secondProjection.addSucceedingOperator(connection.getOperatorIDTuple());
startingOperator.addSucceedingOperator(new OperatorIDTuple(firstFilter,0));
}
}
catch( final Exception e){
e.printStackTrace();
System.out.println(e);
}
} else {
// alternative way to evaluate (...)?, (...)* and (...)+ without using the Closure and PathLengthZero operators!
try{
Variable subject;
Variable object;
Item realSubject = null;
Item realObject = null;
boolean subjectIsALiteral = false;
boolean objectIsALiteral = false;
Item itm = getItem(tripleSet.jjtGetChild(0));
if (!itm.isVariable()){
subject = this.getVariable(getItem(tripleSet.jjtGetChild(0)).toString(), getItem(tripleSet.jjtGetChild(2)).toString(), "interimSubject");
realSubject = itm;
subjectIsALiteral = true;
} else {
subject = (Variable) itm;
}
final Node subjectNode = tripleSet.jjtGetChild(0);
itm = getItem(tripleSet.jjtGetChild(2));
if (!itm.isVariable()){
object = this.getVariable(getItem(tripleSet.jjtGetChild(0)).toString(), getItem(tripleSet.jjtGetChild(2)).toString(), "interimObject");
realObject = itm;
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());