stanfordnlp/CoreNLP · warning

Failed to find end for

Error message

Failed to find end for ${tag}

What it means

In NERGUI.extract, after a start tag (e.g. <ORGANIZATION>) is matched in the text, the code searches for the corresponding closing end pattern after the match. If no end marker is found, the entity cannot be delimited, so a warning is logged instead of extracting the entity.

Solutions

  1. Inspect the input text for unbalanced start tags and repair the malformed markup.
  2. Ensure the endPattern for the tag matches your actual tag format (custom tag sets need matching end patterns).
  3. Pre-validate input: count occurrences of each start/end tag and reject unbalanced input before calling extract.

Example fix

// before
String text = "<ORGANIZATION> Stanford University"; // no end tag
// after
String text = "<ORGANIZATION> Stanford University </ORGANIZATION>";
Defensive patterns

Strategy: validation

Validate before calling

static boolean balanced(String text, String startTag, String endTag) {
  return countOccurrences(text, startTag) == countOccurrences(text, endTag);
}

Try / catch

Matcher m1 = endPattern.matcher(finalText);
if (!m1.find(m.end())) {
  log.warn("Skipping entity with unbalanced tags for " + tag);
  continue; // don't call m1.replaceFirst on an unfound match
}

Prevention

When it happens

Trigger: Running the NERGUI extract on text where a tag-opening pattern matches but the matching end pattern never occurs — i.e. a start tag for `tag` appears without its counterpart end tag.

Common situations: Hand-edited or truncated HTML fed to the GUI; custom tag formats whose end markers were stripped by sanitization; concatenating chunks so a start tag in one chunk has its end tag in another.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/1cdc390fcfdb508d. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ie/crf/NERGUI.java:587

      Pattern endPattern = Pattern.compile("</(" + tagPattern + ")>");

      String finalText = taggedContents;

      Matcher m = startPattern.matcher(finalText);
      while (m.find()) {
        String tag = m.group(1);
        Color col = tagToColorMap.get(tag);
        if (col != null) {
          String color = colorToHTML(col);
          String newTag = "<span style=\"background-color: " + color + "; color: white\">";
          finalText = m.replaceFirst(newTag);
          int start = m.start() + newTag.length();
          Matcher m1 = endPattern.matcher(finalText);
          if (m1.find(m.end())) {
            String entity = finalText.substring(start, m1.start());
            log.info(tag + ": " + entity);
          } else {
            log.warn("Failed to find end for " + tag);
          }
          finalText = m1.replaceFirst("</span>");
          m = startPattern.matcher(finalText);
        }
      }
      // System.out.println(finalText);
      editorPane.setText(finalText);
      editorPane.revalidate();
      editorPane.repaint();

      // log.info(finalText);
    }
    saveTaggedAs.setEnabled(true);
  }

  private AttributeSet getAttributeSet(String tag) {
    MutableAttributeSet attr = new SimpleAttributeSet();
    Color color = tagToColorMap.get(tag);

View on GitHub (pinned to 1b7edd19c4)