// 5. Ergebniss aller Regeln in einem Result zusammenfuehren
BasicOperator[] finalResults;
if (obj.getConclusion() == null) {
finalResults = new BasicOperator[1];
finalResults[0] = new Result();
} else {
finalResults = this.patternFromConclusion(obj.getConclusion());
}
for(final BasicOperator finalResult: finalResults){
// Verbindungen zum Endergebniss herstellen
for (final BasicOperator subOperator : subOperators) {
// Result immer auf linker Seite, damit keine Linksrekursion
// auftreten kann
if(!(finalResult instanceof TriplePattern && subOperator instanceof ConstructPredicate)
&&!(finalResult instanceof PredicatePattern && (subOperator instanceof Construct || subOperator instanceof Generate))){
if (!subOperator.getSucceedingOperators().isEmpty()) {
final OperatorIDTuple temp = subOperator.getSucceedingOperators().get(0);
subOperator.getSucceedingOperators().set(0,new OperatorIDTuple(finalResult, 0));
finalResult.addPrecedingOperator(subOperator);
subOperator.addSucceedingOperator(temp);
} else {
subOperator.setSucceedingOperator(new OperatorIDTuple(finalResult, 0));
finalResult.addPrecedingOperator(subOperator);
}
}
}
}
for(int i=0; i<finalResults.length; i++){
BasicOperator finalResult = finalResults[i];
if (subOperators.isEmpty()) {
// Root verweist auf EmptyIndex und der direkt auf Result
if (finalResult instanceof PredicatePattern || finalResult instanceof TriplePattern) {
finalResult.removeFromOperatorGraph();
finalResult = null;
}
final EmptyIndexScan empty = new EmptyIndexScan(finalResult == null ? null : new OperatorIDTuple(finalResult, 0));
this.indexScanCreator.getRoot().addSucceedingOperator(new OperatorIDTuple(empty, this.indexScanCreator.getRoot().getSucceedingOperators().size()));
empty.addPrecedingOperator(this.indexScanCreator.getRoot());
if (finalResult == null) {
finalResults[i] = empty;
}
}
}
if (this.booleanIndex != null
&& this.booleanIndex.getSucceedingOperators().isEmpty()){
this.indexScanCreator.getRoot().removeSucceedingOperator(this.booleanIndex);
this.booleanIndex.removePrecedingOperator(this.indexScanCreator.getRoot());
}
if(finalResults.length==1 && (finalResults[0] instanceof Result)){
return finalResults[0];
}
// Falls Conclusion vorhanden, noch Result anhaengen, zum Sammeln der Ergebnisse
final Result result = new Result();
final BasicOperator makeBooleanResultOrResult;
if (obj.getConclusion() != null && obj.getConclusion().getVariables().isEmpty()) {
makeBooleanResultOrResult = new MakeBooleanResult();
makeBooleanResultOrResult.addSucceedingOperator(result);
result.addPrecedingOperator(makeBooleanResultOrResult);
} else {
makeBooleanResultOrResult = result;
}
for(final BasicOperator finalResult: finalResults){