{"record":{"id":"d706cb77ffc06b23","repo":"stanfordnlp/CoreNLP","slug":"docdate-regex-failed-to-match-against-docid","errorCode":null,"errorMessage":"DocDate regex failed to match against ${docID}","messagePattern":"DocDate regex failed to match against (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/edu/stanford/nlp/pipeline/DocDateAnnotator.java","lineNumber":116,"sourceCode":"      docID = \"\";\n    String foundDocDate;\n    if (useMappingFile) {\n      foundDocDate = docIDToDocDate.get(docID);\n      if (foundDocDate == null) {\n        log.warn(\"DocDate mapping file failed to match against \" + docID);\n        foundDocDate = \"\";\n      }\n    } else if (useFixedDate || usePresentDate) {\n      foundDocDate = fixedDate;\n    } else if (useRegex) {\n      Matcher m = fileDocDatePattern.matcher(docID);\n      if (m.matches()) {\n        foundDocDate = m.group(1);\n        if (foundDocDate.length() == 8 && DATE_NO_HYPHENS_PATTERN.matcher(foundDocDate).matches()) {\n          foundDocDate = addHyphensToDate(foundDocDate);\n        }\n      } else {\n        log.warn(\"DocDate regex failed to match against \" + docID);\n        foundDocDate = \"\";\n      }\n    } else {\n      foundDocDate = \"\";\n    }\n    // check date has proper format\n    Matcher properDateFormat = DATE_PROPER_FORMAT.matcher(foundDocDate);\n    if (properDateFormat.matches()) {\n      annotation.set(CoreAnnotations.DocDateAnnotation.class, foundDocDate);\n    }\n  }\n\n  /** helper for return current date **/\n  public String currentDate() {\n    return new SimpleDateFormat(\"yyyy-MM-dd\").format(Calendar.getInstance().getTime());\n  }\n\n  /** helper to add hyphens **/","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/DocDateAnnotator.java#L98-L134","documentation":"In regex mode, DocDateAnnotator applies a configured pattern to the document ID and expects to capture the date as group(1). When the pattern does not match the docID, it logs this warning and sets the doc date to the empty string, so temporal expressions will not be grounded to a document date.","triggerScenarios":"annotate() runs with useRegex enabled and the docID (possibly empty when no DocIDAnnotator ran) does not match docdate.pattern, e.g., a pattern like '.*_(\\d{8})\\.xml' against IDs without a date suffix.","commonSituations":"Pattern written for a different filename convention than the actual doc IDs; doc IDs missing entirely because the docid annotation key was never set; date formats in filenames differing (e.g., 20130514 vs 2013-05-14, or two-digit years).","solutions":["Print/log the actual docID values and adjust docdate.pattern to match the real naming convention.","Ensure the DocIDAnnotator (or equivalent) sets the document ID before DocDateAnnotator runs, otherwise the regex matches an empty string.","Broaden the regex (e.g., allow both hyphenated and non-hyphenated dates, optional extensions) — the annotator already normalizes 8-digit dates via addHyphensToDate.","Fall back to docdate.fixedDate or a mapping file if regex extraction is unreliable for the corpus."],"exampleFix":"// before: pattern expects YYYYMMDD but filenames use YYYY-MM-DD\nprops.setProperty(\"docdate.regex.pattern\", \".*?(\\\\d{8})\\\\.xml\");\n\n// after\nprops.setProperty(\"docdate.regex.pattern\", \".*?(\\\\d{4}-\\\\d{2}-\\\\d{2}|\\\\d{8})(?:\\\\.xml)?$\");","handlingStrategy":"fallback","validationCode":"// Test the docdate regex against your actual doc IDs before running the pipeline\nPattern p = Pattern.compile(props.getProperty(\"docdate.regex.pattern\"));\nfor (String docId : docIds) {\n  if (!p.matcher(docId).matches()) log.warn(\"docdate pattern fails for: \" + docId);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write the regex against real doc ID samples, including edge cases (no extension, short years)","Ensure doc IDs are populated (DocIDAnnotator) before regex extraction","Keep group(1) as the date capture — the pattern must contain a capturing group","Provide a fixed reference date as fallback when extraction fails"],"tags":["nlp","temporal","regex","configuration"],"backgroundTag":"invalid-regex-pattern","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"}