Program: 63062
Project: 63062
Buggy source:
/** 
 * Add annotations from the CAS, which is controlled by the window size, to the VDocument  {@link VDocument}
 * @param aJcas The JCAS object containing annotations
 * @param vdoc A VDocument containing annotations for the given layer
 * @param aState Data model for brat annotations
 * @param aColoringStrategy the coloring strategy to render this layer
 */
@Override public void render(JCas aJcas,VDocument vdoc,AnnotatorState aState,ColoringStrategy aColoringStrategy,AnnotationLayer layer,RecommendationService recommendationService,LearningRecordService learningRecordService,AnnotationSchemaService aAnnotationService,FeatureSupportRegistry aFsRegistry){
  if (aJcas == null || recommendationService == null) {
    return;
  }
  int windowBegin=aState.getWindowBeginOffset();
  int windowEnd=aState.getWindowEndOffset();
  Predictions model=recommendationService.getPredictions(aState.getUser(),aState.getProject());
  if (model == null) {
    return;
  }
  List<List<AnnotationObject>> recommendations=model.getPredictions(DocumentMetaData.get(aJcas).getDocumentTitle(),layer,windowBegin,windowEnd,aJcas,false);
  String color=aColoringStrategy.getColor(null,null);
  String bratTypeName=TypeUtil.getUiTypeName(typeAdapter);
  List<VSpan> vspansWithoutRecommendations=new ArrayList<>(vdoc.spans(layer.getId()));
  List<LearningRecord> recordedAnnotations=learningRecordService.getAllRecordsByDocumentAndUserAndLayer(aState.getDocument(),aState.getUser().getUsername(),layer);
  for (  List<AnnotationObject> token : recommendations) {
    Map<String,Map<Long,AnnotationObject>> labelMap=new HashMap<>();
    for (    AnnotationObject ao : token) {
      if (ao.getAnnotation() != null) {
        if (isOverlapping(vspansWithoutRecommendations,ao.getOffset(),windowBegin,ao.getFeature())) {
          break;
        }
        if (isRejected(recordedAnnotations,ao)) {
          continue;
        }
        if (!labelMap.containsKey(ao.getAnnotation()) || !labelMap.get(ao.getAnnotation()).containsKey(ao.getRecommenderId()) || labelMap.get(ao.getAnnotation()).get(ao.getRecommenderId()).getConfidence() < ao.getConfidence()) {
          Map<Long,AnnotationObject> confidencePerClassifier;
          if (labelMap.get(ao.getAnnotation()) == null) {
            confidencePerClassifier=new HashMap<>();
          }
 else {
            confidencePerClassifier=labelMap.get(ao.getAnnotation());
          }
          confidencePerClassifier.put(ao.getRecommenderId(),ao);
          labelMap.put(ao.getAnnotation(),confidencePerClassifier);
        }
      }
    }
    Map<String,Double> maxConfidencePerLabel=new HashMap<>();
    for (    String label : labelMap.keySet()) {
      double maxConfidence=0;
      for (      Entry<Long,AnnotationObject> classifier : labelMap.get(label).entrySet()) {
        if (classifier.getValue().getConfidence() > maxConfidence) {
          maxConfidence=classifier.getValue().getConfidence();
        }
      }
      maxConfidencePerLabel.put(label,maxConfidence);
    }
    List<String> filtered=maxConfidencePerLabel.entrySet().stream().sorted((e1,e2) -> Double.compare(e2.getValue(),e1.getValue())).limit(recommendationService.getMaxSuggestions(aState.getUser())).map(Entry::getKey).collect(Collectors.toList());
    for (    String label : labelMap.keySet()) {
      if (!filtered.contains(label)) {
        continue;
      }
      AnnotationObject prediction=token.stream().filter(p -> p.getAnnotation().equals(label)).max(Comparator.comparingInt(TokenObject::getId)).orElse(null);
      if (prediction == null) {
        continue;
      }
      VID vid=new VID(RecommendationEditorExtension.BEAN_NAME,layer.getId(),(int)prediction.getRecommenderId(),prediction.getId(),VID.NONE,VID.NONE);
      boolean first=true;
      Map<Long,AnnotationObject> confidencePerClassifier=labelMap.get(label);
      for (      Long recommenderId : confidencePerClassifier.keySet()) {
        AnnotationObject ao=confidencePerClassifier.get(recommenderId);
        if (first) {
          AnnotationFeature feature=aAnnotationService.getFeature(ao.getFeature(),layer);
          String annotation=aFsRegistry.getFeatureSupport(feature).renderFeatureValue(feature,ao.getAnnotation());
          Map<String,String> featureAnnotation=new HashMap<>();
          featureAnnotation.put(ao.getFeature(),annotation);
          VSpan v=new VSpan(layer,vid,bratTypeName,new VRange(ao.getOffset().getBeginCharacter() - windowBegin,ao.getOffset().getEndCharacter() - windowBegin),featureAnnotation,Collections.emptyMap(),color);
          vdoc.add(v);
          first=false;
        }
        vdoc.add(new VComment(vid,VCommentType.INFO,ao.getClassifier()));
        if (ao.getConfidence() != -1) {
          vdoc.add(new VComment(vid,VCommentType.INFO,String.format("String_Node_Str",ao.getConfidence())));
        }
        if (ao.getDescription() != null && !ao.getDescription().isEmpty()) {
          vdoc.add(new VComment(vid,VCommentType.INFO,"String_Node_Str" + ao.getDescription()));
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Add annotations from the CAS, which is controlled by the window size, to the VDocument  {@link VDocument}
 * @param aJcas The JCAS object containing annotations
 * @param vdoc A VDocument containing annotations for the given layer
 * @param aState Data model for brat annotations
 * @param aColoringStrategy the coloring strategy to render this layer
 */
@Override public void render(JCas aJcas,VDocument vdoc,AnnotatorState aState,ColoringStrategy aColoringStrategy,AnnotationLayer layer,RecommendationService recommendationService,LearningRecordService learningRecordService,AnnotationSchemaService aAnnotationService,FeatureSupportRegistry aFsRegistry){
  if (aJcas == null || recommendationService == null) {
    return;
  }
  int windowBegin=aState.getWindowBeginOffset();
  int windowEnd=aState.getWindowEndOffset();
  Predictions model=recommendationService.getPredictions(aState.getUser(),aState.getProject());
  if (model == null) {
    return;
  }
  List<List<AnnotationObject>> recommendations=model.getPredictions(DocumentMetaData.get(aJcas).getDocumentTitle(),layer,windowBegin,windowEnd,aJcas,false);
  String color=aColoringStrategy.getColor(null,null);
  String bratTypeName=TypeUtil.getUiTypeName(typeAdapter);
  List<VSpan> vspansWithoutRecommendations=new ArrayList<>(vdoc.spans(layer.getId()));
  List<LearningRecord> recordedAnnotations=learningRecordService.getAllRecordsByDocumentAndUserAndLayer(aState.getDocument(),aState.getUser().getUsername(),layer);
  for (  List<AnnotationObject> token : recommendations) {
    Map<String,Map<Long,AnnotationObject>> labelMap=new HashMap<>();
    for (    AnnotationObject ao : token) {
      boolean hasNoAnnotation=ao.getAnnotation() == null;
      boolean isOverlappingForFeature=isOverlappingForFeature(vspansWithoutRecommendations,ao.getOffset(),windowBegin,ao.getFeature());
      boolean isRejected=isRejected(recordedAnnotations,ao);
      if (hasNoAnnotation || isOverlappingForFeature || isRejected) {
        continue;
      }
      if (!labelMap.containsKey(ao.getAnnotation()) || !labelMap.get(ao.getAnnotation()).containsKey(ao.getRecommenderId()) || labelMap.get(ao.getAnnotation()).get(ao.getRecommenderId()).getConfidence() < ao.getConfidence()) {
        Map<Long,AnnotationObject> confidencePerClassifier;
        if (labelMap.get(ao.getAnnotation()) == null) {
          confidencePerClassifier=new HashMap<>();
        }
 else {
          confidencePerClassifier=labelMap.get(ao.getAnnotation());
        }
        confidencePerClassifier.put(ao.getRecommenderId(),ao);
        labelMap.put(ao.getAnnotation(),confidencePerClassifier);
      }
    }
    Map<String,Double> maxConfidencePerLabel=new HashMap<>();
    for (    String label : labelMap.keySet()) {
      double maxConfidence=0;
      for (      Entry<Long,AnnotationObject> classifier : labelMap.get(label).entrySet()) {
        if (classifier.getValue().getConfidence() > maxConfidence) {
          maxConfidence=classifier.getValue().getConfidence();
        }
      }
      maxConfidencePerLabel.put(label,maxConfidence);
    }
    List<String> filtered=maxConfidencePerLabel.entrySet().stream().sorted((e1,e2) -> Double.compare(e2.getValue(),e1.getValue())).limit(recommendationService.getMaxSuggestions(aState.getUser())).map(Entry::getKey).collect(Collectors.toList());
    for (    String label : labelMap.keySet()) {
      if (!filtered.contains(label)) {
        continue;
      }
      AnnotationObject prediction=token.stream().filter(p -> p.getAnnotation().equals(label)).max(Comparator.comparingInt(TokenObject::getId)).orElse(null);
      if (prediction == null) {
        continue;
      }
      VID vid=new VID(RecommendationEditorExtension.BEAN_NAME,layer.getId(),(int)prediction.getRecommenderId(),prediction.getId(),VID.NONE,VID.NONE);
      boolean first=true;
      Map<Long,AnnotationObject> confidencePerClassifier=labelMap.get(label);
      for (      Long recommenderId : confidencePerClassifier.keySet()) {
        AnnotationObject ao=confidencePerClassifier.get(recommenderId);
        if (first) {
          AnnotationFeature feature=aAnnotationService.getFeature(ao.getFeature(),layer);
          String annotation=aFsRegistry.getFeatureSupport(feature).renderFeatureValue(feature,ao.getAnnotation());
          Map<String,String> featureAnnotation=new HashMap<>();
          featureAnnotation.put(ao.getFeature(),annotation);
          VSpan v=new VSpan(layer,vid,bratTypeName,new VRange(ao.getOffset().getBeginCharacter() - windowBegin,ao.getOffset().getEndCharacter() - windowBegin),featureAnnotation,Collections.emptyMap(),color);
          vdoc.add(v);
          first=false;
        }
        vdoc.add(new VComment(vid,VCommentType.INFO,ao.getClassifier()));
        if (ao.getConfidence() != -1) {
          vdoc.add(new VComment(vid,VCommentType.INFO,String.format("String_Node_Str",ao.getConfidence())));
        }
        if (ao.getDescription() != null && !ao.getDescription().isEmpty()) {
          vdoc.add(new VComment(vid,VCommentType.INFO,"String_Node_Str" + ao.getDescription()));
        }
      }
    }
  }
}