stanfordnlp/CoreNLP · error · RuntimeException

unexpected element

Error message

unexpected element ${child}

What it means

toTimexCoreMaps walks the children of HeidelTime's XML output document and only knows how to handle Text nodes and TIMEX3 elements. Any other XML element in the output triggers this RuntimeException, since the annotator cannot compute character/token offsets for unknown element types.

Solutions

  1. Confirm the heideltime.jar and config.props under heideltime.path are the supported versions that emit only TIMEX3 tags
  2. Log/print the HeidelTime stdout right before parsing to see the unexpected element and its origin
  3. Ensure the document text passed to the annotator is plain text, not XML containing other tags
  4. Patch toTimexCoreMaps to skip or recursively handle non-TIMEX3 elements instead of throwing

Example fix

// before
} else {
  throw new RuntimeException("unexpected element " + child);
}
// after
} else {
  System.err.println("skipping unexpected element in HeidelTime output: " + child.getNodeName());
}
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check heideltime installation emits only TIMEX3 elements
String out = runHeidelTimeSample("Obama visited Paris on May 1, 2011.");
for (String tag : extractTagNames(out)) {
    if (!tag.equals("TIMEX3")) throw new IllegalStateException("unexpected HeidelTime tag: " + tag);
}

Prevention

When it happens

Trigger: The parsed HeidelTime output contains an element other than TIMEX3 (e.g. a different tag emitted by a different/newer heideltime.jar, or DOCTYPE/processing-instruction wrapped as Element-like nodes) while iterating the document element's children.

Common situations: Pointing the annotator at a heideltime.jar build whose output tags differ (e.g. TIMEX2 or custom tags); corrupted or hand-edited HeidelTime output; feeding the annotator XML that was not produced by HeidelTime.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/time/HeidelTimeAnnotator.java:254

                tokBegin = beginMap.get(charBegin + searchStep);
              }
              searchStep += 1;
            }
            searchStep = 1;
            Integer tokEnd = endMap.get(charEnd);
            while(tokEnd == null){
              tokEnd = endMap.get(charEnd - searchStep);
              if(tokEnd == null){
                tokEnd = endMap.get(charEnd + searchStep);
              }
              searchStep += 1;
            }
            timexMap.set(CoreAnnotations.TokenBeginAnnotation.class, tokBegin);
            timexMap.set(CoreAnnotations.TokenEndAnnotation.class, tokEnd);
          }
          timexMaps.add(timexMap);
        } else {
          throw new RuntimeException("unexpected element " + child);
        }
      } else {
        throw new RuntimeException("unexpected content " + content);
      }
    }
    return timexMaps;
  }

  @Override
  public Set<Class<? extends CoreAnnotation>> requires() {
    return Collections.unmodifiableSet(new ArraySet<>(Arrays.asList(
        CoreAnnotations.TextAnnotation.class,
        CoreAnnotations.TokensAnnotation.class,
        CoreAnnotations.CharacterOffsetBeginAnnotation.class,
        CoreAnnotations.CharacterOffsetEndAnnotation.class,
        CoreAnnotations.SentencesAnnotation.class
    )));
  }

View on GitHub (pinned to 1b7edd19c4)