Program: 53379
Project: 53379
Buggy source:
/** 
 * Output Conll2003 format.
 * @param kaf the kaf document
 * @return the annotated named entities in conll03 format
 */
public String annotateNEsToCoNLL2003(KAFDocument kaf){
  List<Entity> namedEntityList=kaf.getEntities();
  Map<String,Integer> entityToSpanSize=new HashMap<String,Integer>();
  Map<String,String> entityToType=new HashMap<String,String>();
  for (  Entity ne : namedEntityList) {
    List<ixa.kaflib.Span<Term>> entitySpanList=ne.getSpans();
    for (    ixa.kaflib.Span<Term> spanTerm : entitySpanList) {
      Term neTerm=spanTerm.getFirstTarget();
      entityToSpanSize.put(neTerm.getId(),spanTerm.size());
      entityToType.put(neTerm.getId(),ne.getType());
    }
  }
  List<List<WF>> sentences=kaf.getSentences();
  StringBuilder sb=new StringBuilder();
  for (  List<WF> sentence : sentences) {
    int sentNumber=sentence.get(0).getSent();
    List<Term> sentenceTerms=kaf.getSentenceTerms(sentNumber);
    boolean previousIsEntity=false;
    for (int i=0; i < sentenceTerms.size(); i++) {
      Term thisTerm=sentenceTerms.get(i);
      if (entityToSpanSize.get(thisTerm.getId()) != null) {
        int neSpanSize=entityToSpanSize.get(thisTerm.getId());
        String neClass=entityToType.get(thisTerm.getId());
        String neType=this.convertToConLLTypes(neClass);
        if (neSpanSize > 1) {
          for (int j=0; j < neSpanSize; j++) {
            thisTerm=sentenceTerms.get(i + j);
            sb.append(thisTerm.getForm());
            sb.append("String_Node_Str");
            sb.append(thisTerm.getLemma());
            sb.append("String_Node_Str");
            sb.append(thisTerm.getMorphofeat());
            sb.append("String_Node_Str");
            if (j == 0 && previousIsEntity) {
              sb.append(BIO.BEGIN.toString());
            }
 else {
              sb.append(BIO.IN.toString());
            }
            sb.append(neType);
            sb.append("String_Node_Str");
          }
        }
 else {
          sb.append(thisTerm.getForm());
          sb.append("String_Node_Str");
          sb.append(thisTerm.getLemma());
          sb.append("String_Node_Str");
          sb.append(thisTerm.getMorphofeat());
          sb.append("String_Node_Str");
          if (previousIsEntity) {
            sb.append(BIO.BEGIN.toString());
          }
 else {
            sb.append(BIO.IN.toString());
          }
          sb.append(neType);
          sb.append("String_Node_Str");
        }
        previousIsEntity=true;
        i+=neSpanSize - 1;
      }
 else {
        sb.append(thisTerm.getForm());
        sb.append("String_Node_Str");
        sb.append(thisTerm.getLemma());
        sb.append("String_Node_Str");
        sb.append(thisTerm.getMorphofeat());
        sb.append("String_Node_Str");
        sb.append(BIO.OUT);
        sb.append("String_Node_Str");
        previousIsEntity=false;
      }
    }
    sb.append("String_Node_Str");
  }
  return sb.toString();
}

Fixed version (ground truth):
/** 
 * Output Conll2003 format.
 * @param kaf the kaf document
 * @return the annotated named entities in conll03 format
 */
public String annotateNEsToCoNLL2003(KAFDocument kaf){
  List<Entity> namedEntityList=kaf.getEntities();
  Map<String,Integer> entityToSpanSize=new HashMap<String,Integer>();
  Map<String,String> entityToType=new HashMap<String,String>();
  for (  Entity ne : namedEntityList) {
    List<ixa.kaflib.Span<Term>> entitySpanList=ne.getSpans();
    for (    ixa.kaflib.Span<Term> spanTerm : entitySpanList) {
      Term neTerm=spanTerm.getFirstTarget();
      entityToSpanSize.put(neTerm.getId(),spanTerm.size());
      entityToType.put(neTerm.getId(),ne.getType());
    }
  }
  List<List<WF>> sentences=kaf.getSentences();
  StringBuilder sb=new StringBuilder();
  for (  List<WF> sentence : sentences) {
    int sentNumber=sentence.get(0).getSent();
    List<Term> sentenceTerms=kaf.getSentenceTerms(sentNumber);
    boolean previousIsEntity=false;
    String previousType=null;
    for (int i=0; i < sentenceTerms.size(); i++) {
      Term thisTerm=sentenceTerms.get(i);
      if (entityToSpanSize.get(thisTerm.getId()) != null) {
        int neSpanSize=entityToSpanSize.get(thisTerm.getId());
        String neClass=entityToType.get(thisTerm.getId());
        String neType=this.convertToConLLTypes(neClass);
        if (neSpanSize > 1) {
          for (int j=0; j < neSpanSize; j++) {
            thisTerm=sentenceTerms.get(i + j);
            sb.append(thisTerm.getForm());
            sb.append("String_Node_Str");
            sb.append(thisTerm.getLemma());
            sb.append("String_Node_Str");
            sb.append(thisTerm.getMorphofeat());
            sb.append("String_Node_Str");
            if (j == 0 && previousIsEntity && previousType.equalsIgnoreCase(neType)) {
              sb.append(BIO.BEGIN.toString());
            }
 else {
              sb.append(BIO.IN.toString());
            }
            sb.append(neType);
            sb.append("String_Node_Str");
          }
          previousType=neType;
        }
 else {
          sb.append(thisTerm.getForm());
          sb.append("String_Node_Str");
          sb.append(thisTerm.getLemma());
          sb.append("String_Node_Str");
          sb.append(thisTerm.getMorphofeat());
          sb.append("String_Node_Str");
          if (previousIsEntity && previousType.equalsIgnoreCase(neType)) {
            sb.append(BIO.BEGIN.toString());
          }
 else {
            sb.append(BIO.IN.toString());
          }
          sb.append(neType);
          sb.append("String_Node_Str");
        }
        previousIsEntity=true;
        previousType=neType;
        i+=neSpanSize - 1;
      }
 else {
        sb.append(thisTerm.getForm());
        sb.append("String_Node_Str");
        sb.append(thisTerm.getLemma());
        sb.append("String_Node_Str");
        sb.append(thisTerm.getMorphofeat());
        sb.append("String_Node_Str");
        sb.append(BIO.OUT);
        sb.append("String_Node_Str");
        previousIsEntity=false;
        previousType=BIO.OUT.toString();
      }
    }
    sb.append("String_Node_Str");
  }
  return sb.toString();
}