{"record":{"id":"724122b7b661007c","repo":"stanfordnlp/CoreNLP","slug":"tokensregexnerannotator-error-header-does-not-con","errorCode":null,"errorMessage":"TokensRegexNERAnnotator ERROR: Header does not contain 'pattern': ","messagePattern":"TokensRegexNERAnnotator ERROR: Header does not contain 'pattern': ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/TokensRegexNERAnnotator.java","lineNumber":673,"sourceCode":"   *  @return the updated list of Entries\n   */\n  private static List<Entry> readEntries(String annotatorName,\n                                         String[] headerFields,\n                                         String[] annotationFieldnames,\n                                         List<Entry> entries,\n                                         TrieMap<String,Entry> seenRegexes,\n                                         String mappingFilename,\n                                         BufferedReader mapping,\n                                         Set<String> noDefaultOverwriteLabels,\n                                         boolean ignoreCase, Integer mappingFileIndex,\n                                         Map<Entry, Integer> entryToMappingFileNumber, boolean verbose) throws IOException {\n    int origEntriesSize = entries.size();\n    int isTokensRegex = 0;\n    int lineCount = 0;\n    Map<String,Integer> headerIndexMap = getHeaderIndexMap(headerFields);\n    int iPattern = getIndex(headerIndexMap, PATTERN_FIELD);\n    if (iPattern < 0) {\n      throw new IllegalArgumentException(\"TokensRegexNERAnnotator \" + annotatorName\n        + \" ERROR: Header does not contain 'pattern': \" + StringUtils.join(headerFields));\n    }\n    int iOverwrite = getIndex(headerIndexMap, OVERWRITE_FIELD);\n    int iPriority = getIndex(headerIndexMap, PRIORITY_FIELD);\n    int iWeight = getIndex(headerIndexMap, WEIGHT_FIELD);\n    int iGroup = getIndex(headerIndexMap, GROUP_FIELD);\n    int[] annotationCols = new int[annotationFieldnames.length];\n    int iLastAnnotationField = -1;\n    for (int i = 0; i < annotationFieldnames.length; i++) {\n      annotationCols[i] = getIndex(headerIndexMap, annotationFieldnames[i]);\n      if (annotationCols[i] < 0) {\n        throw new IllegalArgumentException(\"TokensRegexNERAnnotator \" + annotatorName\n            + \" ERROR: Header does not contain annotation field '\" + annotationFieldnames[i] + \"': \" + StringUtils.join(headerFields));\n      }\n      if (annotationCols[i] > iLastAnnotationField) {\n        iLastAnnotationField = annotationCols[i];\n      }\n    }","sourceCodeStart":655,"sourceCodeEnd":691,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/TokensRegexNERAnnotator.java#L655-L691","documentation":"readEntries requires the mapping file header to include a 'pattern' column (PATTERN_FIELD); if getIndex returns < 0 it throws IllegalArgumentException noting the header doesn't contain 'pattern'. The pattern column is mandatory because every entry is driven by a TokensRegex pattern.","triggerScenarios":"Providing a mapping file whose header row lacks 'pattern' — e.g. headers like 'word\tner' copied from the plain RegexNERAnnotator format instead of the TokensRegexNER format.","commonSituations":"Reusing a regexner mapping file with tokensregexner; header written with different casing or whitespace ('Pattern'); header accidentally deleted when editing the file.","solutions":["Add a 'pattern' column to the header row of the mapping file and provide a TokensRegex pattern in each row.","Check casing/spelling — the header field must be exactly 'pattern'.","If the file is a plain RegexNER mapping, either convert it or use the regexner annotator instead.","Compare against the shipped default mapping (edu/stanford/nlp/models/regexner/type_mappings.txt) for the expected format."],"exampleFix":"// header before\nword\tner\n// header after\npattern\tner\n[ { word:/(?i:microsoft)/ } ]\tORGANIZATION","handlingStrategy":"validation","validationCode":"String[] header = firstLine.split(\"\\t\", -1);\nif (!Arrays.asList(header).contains(\"pattern\")) {\n  throw new IllegalStateException(\"Mapping header missing required 'pattern' column: \" + String.join(\",\", header));\n}","typeGuard":null,"tryCatchPattern":"try { annotator = new TokensRegexNERAnnotator(name, props); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"Header does not contain 'pattern'\")) { convertToTokensRegexFormat(mappingPath); } else throw e; }","preventionTips":["Start every mapping file with a header line containing at least 'pattern' and the annotation field (default 'ner')","Don't reuse plain regexner mapping files with tokensregexner without conversion","Validate headers at deploy time with a startup check"],"tags":["nlp","mapping-file","missing-header-field","config-error"],"backgroundTag":"missing-required-config-field","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}