protected void createMultipleOccurence(final ASTTripleSet tripleSet, final OperatorConnection connection, final Item graphConstraint) {
if(USE_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 Node predicateNode = tripleSet.jjtGetChild(1);
final BasicOperator startingOperator = predicateNode.accept(this, connection, graphConstraint, subject, object, subjectNode, objectNode);
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;