Program: 53362
Project: 53362
Buggy source:
/** 
 * Classify Named Entities creating the entities layer in the  {@link KAFDocument} using statistical models, post-processing and/ordictionaries only.
 * @param kaf the kaf document to be used for annotation
 * @throws IOException throws exception if problems with the kaf document
 */
public final void annotateNEs(final KAFDocument kaf) throws IOException {
  List<Span> allSpans=null;
  List<List<WF>> sentences=kaf.getSentences();
  for (  List<WF> sentence : sentences) {
    String[] tokens=new String[sentence.size()];
    String[] tokenIds=new String[sentence.size()];
    for (int i=0; i < sentence.size(); i++) {
      tokens[i]=sentence.get(i).getForm();
      tokenIds[i]=sentence.get(i).getId();
    }
    if (statistical) {
      if (clearFeatures.equalsIgnoreCase("String_Node_Str") && tokens[0].startsWith("String_Node_Str")) {
        nameFinder.clearAdaptiveData();
      }
      Span[] statSpans=nameFinder.nercToSpans(tokens);
      allSpans=Lists.newArrayList(statSpans);
    }
    if (postProcess) {
      Span[] dictSpans=dictFinder.nercToSpansExact(tokens);
      SpanUtils.postProcessDuplicatedSpans(allSpans,dictSpans);
      SpanUtils.concatenateSpans(allSpans,dictSpans);
    }
    if (dictTag) {
      Span[] dictOnlySpans=dictFinder.nercToSpansExact(tokens);
      allSpans=Lists.newArrayList(dictOnlySpans);
    }
    if (lexerFind) {
      String sentenceText=StringUtils.getStringFromTokens(tokens);
      StringReader stringReader=new StringReader(sentenceText);
      BufferedReader sentenceReader=new BufferedReader(stringReader);
      numericLexerFinder=new NumericNameFinder(sentenceReader,nameFactory);
      Span[] numericSpans=numericLexerFinder.nercToSpans(tokens);
      SpanUtils.concatenateSpans(allSpans,numericSpans);
    }
    Span[] allSpansArray=NameFinderME.dropOverlappingSpans(allSpans.toArray(new Span[allSpans.size()]));
    List<Name> names=new ArrayList<Name>();
    if (statistical) {
      names=nameFinder.getNamesFromSpans(allSpansArray,tokens);
    }
 else {
      names=dictFinder.getNamesFromSpans(allSpansArray,tokens);
    }
    for (    Name name : names) {
      Integer startIndex=name.getSpan().getStart();
      Integer endIndex=name.getSpan().getEnd();
      List<Term> nameTerms=kaf.getTermsFromWFs(Arrays.asList(Arrays.copyOfRange(tokenIds,startIndex,endIndex)));
      ixa.kaflib.Span<Term> neSpan=KAFDocument.newTermSpan(nameTerms);
      List<ixa.kaflib.Span<Term>> references=new ArrayList<ixa.kaflib.Span<Term>>();
      references.add(neSpan);
      Entity neEntity=kaf.newEntity(references);
      neEntity.setType(name.getType());
    }
    if (clearFeatures.equalsIgnoreCase("String_Node_Str")) {
      nameFinder.clearAdaptiveData();
    }
  }
  nameFinder.clearAdaptiveData();
}

Fixed version (ground truth):
/** 
 * Classify Named Entities creating the entities layer in the  {@link KAFDocument} using statistical models, post-processing and/ordictionaries only.
 * @param kaf the kaf document to be used for annotation
 * @throws IOException throws exception if problems with the kaf document
 */
public final void annotateNEs(final KAFDocument kaf) throws IOException {
  List<Span> allSpans=null;
  List<List<WF>> sentences=kaf.getSentences();
  for (  List<WF> sentence : sentences) {
    String[] tokens=new String[sentence.size()];
    String[] tokenIds=new String[sentence.size()];
    for (int i=0; i < sentence.size(); i++) {
      tokens[i]=sentence.get(i).getForm();
      tokenIds[i]=sentence.get(i).getId();
    }
    if (statistical) {
      if (clearFeatures.equalsIgnoreCase("String_Node_Str") && tokens[0].startsWith("String_Node_Str")) {
        nameFinder.clearAdaptiveData();
      }
      Span[] statSpans=nameFinder.nercToSpans(tokens);
      allSpans=Lists.newArrayList(statSpans);
    }
    if (postProcess) {
      Span[] dictSpans=dictFinder.nercToSpansExact(tokens);
      SpanUtils.postProcessDuplicatedSpans(allSpans,dictSpans);
      SpanUtils.concatenateSpans(allSpans,dictSpans);
    }
    if (dictTag) {
      Span[] dictOnlySpans=dictFinder.nercToSpansExact(tokens);
      allSpans=Lists.newArrayList(dictOnlySpans);
    }
    if (lexerFind) {
      String sentenceText=StringUtils.getStringFromTokens(tokens);
      StringReader stringReader=new StringReader(sentenceText);
      BufferedReader sentenceReader=new BufferedReader(stringReader);
      numericLexerFinder=new NumericNameFinder(sentenceReader,nameFactory);
      Span[] numericSpans=numericLexerFinder.nercToSpans(tokens);
      SpanUtils.concatenateSpans(allSpans,numericSpans);
    }
    Span[] allSpansArray=NameFinderME.dropOverlappingSpans(allSpans.toArray(new Span[allSpans.size()]));
    List<Name> names=new ArrayList<Name>();
    if (statistical) {
      names=nameFinder.getNamesFromSpans(allSpansArray,tokens);
    }
 else {
      names=dictFinder.getNamesFromSpans(allSpansArray,tokens);
    }
    for (    Name name : names) {
      Integer startIndex=name.getSpan().getStart();
      Integer endIndex=name.getSpan().getEnd();
      List<Term> nameTerms=kaf.getTermsFromWFs(Arrays.asList(Arrays.copyOfRange(tokenIds,startIndex,endIndex)));
      ixa.kaflib.Span<Term> neSpan=KAFDocument.newTermSpan(nameTerms);
      List<ixa.kaflib.Span<Term>> references=new ArrayList<ixa.kaflib.Span<Term>>();
      references.add(neSpan);
      Entity neEntity=kaf.newEntity(references);
      neEntity.setType(name.getType());
    }
    if (clearFeatures.equalsIgnoreCase("String_Node_Str")) {
      nameFinder.clearAdaptiveData();
    }
  }
  if (statistical) {
    nameFinder.clearAdaptiveData();
  }
}