Program: 144025
Project: 144025
Buggy source:
private void extendGroundingsAndAddToBuilder(Predicate groundingExtension,ProbabilisticSoftLogicProblem.Builder builder,ProbabilisticSoftLogicPredicateManager predicateManager,HashSet<String> groundingsAlreadyAdded,HashSet<Integer> newPredicates){
  boolean[] bodyNegations=new boolean[this.Body.size()];
  for (int i=0; i < this.Body.size(); ++i) {
    bodyNegations[i]=this.Body.get(i).IsNegated;
  }
  boolean[] headNegations=new boolean[this.Head.size()];
  for (int i=0; i < this.Head.size(); ++i) {
    headNegations[i]=this.Head.get(i).IsNegated;
  }
  List<List<String>> allArgumentGroundings=new ArrayList<>();
  for (  ArgumentGroundingSources argumentGroundingSource : this.ArgumentGroundingSources) {
    HashSet<String> argumentGroundings=new HashSet<>();
    for (    GroundingSource source : argumentGroundingSource.GroundingSources) {
      argumentGroundings.addAll(predicateManager.getArgumentGroundings(this.Body.get(source.IndexPredicate).Name,source.IndexArgument));
    }
    allArgumentGroundings.add(new ArrayList<>(argumentGroundings));
  }
  HashSet<String> visitedGroundings=new HashSet<>();
  for (int indexInsertion=0; indexInsertion < this.Body.size(); ++indexInsertion) {
    if (this.Body.get(indexInsertion).Name.equals(groundingExtension.Name) && this.Body.get(indexInsertion).Arguments.size() == groundingExtension.Arguments.size()) {
      HashMap<String,String> extensionGroundings=new HashMap<>();
      for (int indexExtensionArgument=0; indexExtensionArgument < groundingExtension.Arguments.size(); ++indexExtensionArgument) {
        extensionGroundings.put(this.Body.get(indexInsertion).Arguments.get(indexExtensionArgument),groundingExtension.Arguments.get(indexExtensionArgument));
      }
      String visitedKey=String.join("String_Node_Str",extensionGroundings.keySet());
      if (!visitedGroundings.add(visitedKey)) {
        continue;
      }
      List<List<String>> argumentValuesToTry=new ArrayList<>();
      for (      ArgumentGroundingSources sources : this.ArgumentGroundingSources) {
        String extensionVal=extensionGroundings.getOrDefault(sources.Name,null);
        if (extensionVal != null) {
          argumentValuesToTry.add(Arrays.asList(extensionVal));
        }
 else {
          HashSet<String> availableValues=new HashSet<>();
          for (          GroundingSource source : sources.GroundingSources) {
            availableValues.addAll(predicateManager.getArgumentGroundings(this.Body.get(source.IndexPredicate).Name,source.IndexPredicate));
          }
          argumentValuesToTry.add(new ArrayList<>(availableValues));
        }
      }
      CartesianProductIterator<String> argumentInstanceIterator=new CartesianProductIterator<>(argumentValuesToTry);
      for (      List<String> argumentInstance : argumentInstanceIterator) {
        HashMap<String,String> argumentToGrounding=new HashMap<>();
        StringBuilder groundingStringBuilder=new StringBuilder();
        for (int indexArgument=0; indexArgument < this.ArgumentGroundingSources.size(); ++indexArgument) {
          argumentToGrounding.put(this.ArgumentGroundingSources.get(indexArgument).Name,argumentInstance.get(indexArgument));
          if (indexArgument > 0) {
            groundingStringBuilder.append("String_Node_Str");
          }
          groundingStringBuilder.append(this.ArgumentGroundingSources.get(indexArgument).Name);
          groundingStringBuilder.append("String_Node_Str");
          groundingStringBuilder.append(argumentInstance.get(indexArgument));
        }
        String groundingString=groundingStringBuilder.toString();
        if (groundingsAlreadyAdded.contains(groundingString)) {
          continue;
        }
        if (!this.getIsGroundedOrderingAllowed(argumentToGrounding)) {
          continue;
        }
        Map.Entry<int[],boolean[]> bodyIdResult=Rule.getPredicateIds(this.Body,argumentToGrounding,predicateManager,false);
        double observedBodyConstant=0;
        for (int indexBody=0; indexBody < this.Body.size(); ++indexBody) {
          int bodyId=bodyIdResult.getKey()[indexBody];
          double observedValue=bodyId < 0 ? 0 : predicateManager.getObservedWeight(bodyId);
          if (!Double.isNaN(observedValue)) {
            if (this.Body.get(indexBody).IsNegated)             observedBodyConstant-=observedValue;
 else             observedBodyConstant+=observedValue - 1;
          }
        }
        if (observedBodyConstant + 1 <= 0) {
          continue;
        }
        groundingsAlreadyAdded.add(groundingString);
        Map.Entry<int[],boolean[]> headIdResult=Rule.getPredicateIds(this.Head,argumentToGrounding,predicateManager,true);
        for (int indexHead=0; indexHead < this.Head.size(); ++indexHead) {
          if (headIdResult.getValue()[indexHead]) {
            newPredicates.add(headIdResult.getKey()[indexHead]);
          }
        }
        if (Double.isNaN(this.Weight)) {
          builder.addRule(headIdResult.getKey(),bodyIdResult.getKey(),headNegations,bodyNegations,1,1000);
        }
 else {
          builder.addRule(headIdResult.getKey(),bodyIdResult.getKey(),headNegations,bodyNegations,this.Power,this.Weight);
        }
      }
    }
  }
}

Fixed version (ground truth):
private void extendGroundingsAndAddToBuilder(Predicate groundingExtension,ProbabilisticSoftLogicProblem.Builder builder,ProbabilisticSoftLogicPredicateManager predicateManager,HashSet<String> groundingsAlreadyAdded,HashSet<Integer> newPredicates){
  boolean[] bodyNegations=new boolean[this.Body.size()];
  for (int i=0; i < this.Body.size(); ++i) {
    bodyNegations[i]=this.Body.get(i).IsNegated;
  }
  boolean[] headNegations=new boolean[this.Head.size()];
  for (int i=0; i < this.Head.size(); ++i) {
    headNegations[i]=this.Head.get(i).IsNegated;
  }
  List<List<String>> allArgumentGroundings=new ArrayList<>();
  for (  ArgumentGroundingSources argumentGroundingSource : this.ArgumentGroundingSources) {
    HashSet<String> argumentGroundings=new HashSet<>();
    for (    GroundingSource source : argumentGroundingSource.GroundingSources) {
      argumentGroundings.addAll(predicateManager.getArgumentGroundings(this.Body.get(source.IndexPredicate).Name,source.IndexArgument));
    }
    allArgumentGroundings.add(new ArrayList<>(argumentGroundings));
  }
  HashSet<String> visitedGroundings=new HashSet<>();
  for (int indexInsertion=0; indexInsertion < this.Body.size(); ++indexInsertion) {
    if (this.Body.get(indexInsertion).Name.equals(groundingExtension.Name) && this.Body.get(indexInsertion).Arguments.size() == groundingExtension.Arguments.size()) {
      HashMap<String,String> extensionGroundings=new HashMap<>();
      for (int indexExtensionArgument=0; indexExtensionArgument < groundingExtension.Arguments.size(); ++indexExtensionArgument) {
        extensionGroundings.put(this.Body.get(indexInsertion).Arguments.get(indexExtensionArgument),groundingExtension.Arguments.get(indexExtensionArgument));
      }
      String visitedKey=String.join("String_Node_Str",extensionGroundings.keySet());
      if (!visitedGroundings.add(visitedKey)) {
        continue;
      }
      List<List<String>> argumentValuesToTry=new ArrayList<>();
      for (      ArgumentGroundingSources sources : this.ArgumentGroundingSources) {
        String extensionVal=extensionGroundings.getOrDefault(sources.Name,null);
        if (extensionVal != null) {
          argumentValuesToTry.add(Arrays.asList(extensionVal));
        }
 else {
          HashSet<String> availableValues=new HashSet<>();
          for (          GroundingSource source : sources.GroundingSources) {
            availableValues.addAll(predicateManager.getArgumentGroundings(this.Body.get(source.IndexPredicate).Name,source.IndexArgument));
          }
          argumentValuesToTry.add(new ArrayList<>(availableValues));
        }
      }
      CartesianProductIterator<String> argumentInstanceIterator=new CartesianProductIterator<>(argumentValuesToTry);
      for (      List<String> argumentInstance : argumentInstanceIterator) {
        HashMap<String,String> argumentToGrounding=new HashMap<>();
        StringBuilder groundingStringBuilder=new StringBuilder();
        for (int indexArgument=0; indexArgument < this.ArgumentGroundingSources.size(); ++indexArgument) {
          argumentToGrounding.put(this.ArgumentGroundingSources.get(indexArgument).Name,argumentInstance.get(indexArgument));
          if (indexArgument > 0) {
            groundingStringBuilder.append("String_Node_Str");
          }
          groundingStringBuilder.append(this.ArgumentGroundingSources.get(indexArgument).Name);
          groundingStringBuilder.append("String_Node_Str");
          groundingStringBuilder.append(argumentInstance.get(indexArgument));
        }
        String groundingString=groundingStringBuilder.toString();
        if (groundingsAlreadyAdded.contains(groundingString)) {
          continue;
        }
        if (!this.getIsGroundedOrderingAllowed(argumentToGrounding)) {
          continue;
        }
        Map.Entry<int[],boolean[]> bodyIdResult=Rule.getPredicateIds(this.Body,argumentToGrounding,predicateManager,false);
        double observedBodyConstant=0;
        boolean pruneGrounding=false;
        for (int indexBody=0; indexBody < this.Body.size(); ++indexBody) {
          int bodyId=bodyIdResult.getKey()[indexBody];
          if (bodyId < 0) {
            pruneGrounding=true;
            break;
          }
          double observedValue=bodyId < 0 ? 0 : predicateManager.getObservedWeight(bodyId);
          if (!Double.isNaN(observedValue) && bodyId >= 0) {
            if (this.Body.get(indexBody).IsNegated)             observedBodyConstant-=observedValue;
 else             observedBodyConstant+=observedValue - 1;
          }
        }
        if (pruneGrounding || observedBodyConstant + 1 <= 0)         continue;
        groundingsAlreadyAdded.add(groundingString);
        Map.Entry<int[],boolean[]> headIdResult=Rule.getPredicateIds(this.Head,argumentToGrounding,predicateManager,true);
        for (int indexHead=0; indexHead < this.Head.size(); ++indexHead) {
          if (headIdResult.getValue()[indexHead]) {
            newPredicates.add(headIdResult.getKey()[indexHead]);
          }
        }
        if (Double.isNaN(this.Weight)) {
          builder.addRule(headIdResult.getKey(),bodyIdResult.getKey(),headNegations,bodyNegations,1,1000);
        }
 else {
          builder.addRule(headIdResult.getKey(),bodyIdResult.getKey(),headNegations,bodyNegations,this.Power,this.Weight);
        }
      }
    }
  }
}