{"record":{"id":"8c2c66a2f95033e9","repo":"stanfordnlp/CoreNLP","slug":"can-only-parse-raw-text-if-a-tagger-is-specified","errorCode":null,"errorMessage":"Can only parse raw text if a tagger is specified, as the ShiftReduceParser cannot produce its own tags","messagePattern":"Can only parse raw text if a tagger is specified, as the ShiftReduceParser cannot produce its own tags","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/shiftreduce/ShiftReduceParser.java","lineNumber":176,"sourceCode":"  /** Return the Set of POS tags used in the model. */\n  public Set<String> tagSet() {\n    return model.tagSet();\n  }\n\n  @Override\n  public boolean requiresTags() {\n    return true;\n  }\n\n  @Override\n  public ParserQuery parserQuery() {\n    return new ShiftReduceParserQuery(this);\n  }\n\n  @Override\n  public Tree parse(String sentence) {\n    if (!getOp().testOptions.preTag) {\n      throw new UnsupportedOperationException(\"Can only parse raw text if a tagger is specified, as the ShiftReduceParser cannot produce its own tags\");\n    }\n    return super.parse(sentence);\n  }\n\n  @Override\n  public Tree parse(List<? extends HasWord> sentence) {\n    ShiftReduceParserQuery pq = new ShiftReduceParserQuery(this);\n    if (pq.parse(sentence)) {\n      return pq.getBestParse();\n    }\n    return ParserUtils.xTree(sentence);\n  }\n\n  @Override\n  public Tree parseTree(List<? extends HasWord> sentence) {\n    ShiftReduceParserQuery pq = new ShiftReduceParserQuery(this);\n    if (pq.parse(sentence)) {\n      return pq.getBestParse();","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/shiftreduce/ShiftReduceParser.java#L158-L194","documentation":"ShiftReduceParser.parse(String) accepts raw (untagged) text, but the parser cannot POS-tag sentences itself; it requires pre-tagged input. If the test option preTag is false — meaning no tagger was configured — calling the String overload cannot proceed and throws UnsupportedOperationException.","triggerScenarios":"Calling parser.parse(\"some raw sentence\") on a parser model loaded without a tagger (op.testOptions.preTag == false).","commonSituations":"Loading a serialized ShiftReduceParser model trained without a POS tagger and passing plain text; upgrading models or switching from a parser+tagger bundle to a bare parser while keeping raw-text call sites.","solutions":["Tag the sentence yourself and call parse(List<? extends HasWord>) with CoreLabels carrying tags","Load/parser-config with a tagger so preTag is enabled (e.g. specify -testOptions preTag with a tagger serialized path)","Use a parser model serialized together with its tagger"],"exampleFix":"// before\nTree t = parser.parse(\"The dog barked\");\n\n// after\nList<CoreLabel> tagged = tokenizerFactory.getTokenizer(new StringReader(\"The dog barked\")).tokenize();\n// ... set tags via a tagger ...\nTree t = parser.parse(tagged);","handlingStrategy":"type-guard","validationCode":"if (!parser.getOp().testOptions.preTag) {\n  throw new IllegalStateException(\"Supply tagged List<HasWord> instead of raw text\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  return parser.parse(rawSentence);\n} catch (UnsupportedOperationException e) {\n  return parser.parse(tagger.apply(tokenize(rawSentence)));\n}","preventionTips":["Always call the List<HasWord> overload unless the model bundles a tagger","Check testOptions.preTag at pipeline startup","Bundle the tagger with the serialized parser model"],"tags":["parser","pos-tagger","unsupported-operation","api-usage"],"backgroundTag":"unsupported-operation","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"}