{"record":{"id":"d336e516ddc7c3dd","repo":"stanfordnlp/CoreNLP","slug":"expected-a-rerankingparserquery","errorCode":null,"errorMessage":"Expected a RerankingParserQuery","messagePattern":"Expected a RerankingParserQuery","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/dvparser/ParseAndPrintMatrices.java","lineNumber":112,"sourceCode":"    }\n\n    String[] newArgs = unusedArgs.toArray(new String[unusedArgs.size()]);\n    LexicalizedParser parser = LexicalizedParser.loadModel(modelPath, newArgs);\n    DVModel model = DVParser.getModelFromLexicalizedParser(parser);\n\n    File outputFile = new File(outputPath);\n    FileSystem.checkNotExistsOrFail(outputFile);\n    FileSystem.mkdirOrFail(outputFile);\n\n    int count = 0;\n    if (inputPath != null) {\n      Reader input = new BufferedReader(new FileReader(inputPath));\n      DocumentPreprocessor processor = new DocumentPreprocessor(input);\n      for (List<HasWord> sentence : processor) {\n        count++; // index from 1\n        ParserQuery pq = parser.parserQuery();\n        if (!(pq instanceof RerankingParserQuery)) {\n          throw new IllegalArgumentException(\"Expected a RerankingParserQuery\");\n        }\n        RerankingParserQuery rpq = (RerankingParserQuery) pq;\n        if (!rpq.parse(sentence)) {\n          throw new RuntimeException(\"Unparsable sentence: \" + sentence);\n        }\n        RerankerQuery reranker = rpq.rerankerQuery();\n        if (!(reranker instanceof DVModelReranker.Query)) {\n          throw new IllegalArgumentException(\"Expected a DVModelReranker\");\n        }\n        DeepTree deepTree = ((DVModelReranker.Query) reranker).getDeepTrees().get(0);\n        IdentityHashMap<Tree, SimpleMatrix> vectors = deepTree.getVectors();\n\n        for (Map.Entry<Tree, SimpleMatrix> entry : vectors.entrySet()) {\n          log.info(entry.getKey() + \"   \" +  entry.getValue());\n        }\n\n        FileWriter fout = new FileWriter(outputPath + File.separator + \"sentence\" + count + \".txt\");\n        BufferedWriter bout = new BufferedWriter(fout);","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/dvparser/ParseAndPrintMatrices.java#L94-L130","documentation":"ParseAndPrintMatrices.main() requires the parser's ParserQuery to be a RerankingParserQuery so it can extract deep trees and print matrices. If the parser was loaded without DV reranker options, parserQuery() returns a plain ParserQuery and this IllegalArgumentException is thrown before parsing the sentence.","triggerScenarios":"Running main() with a LexicalizedParser loaded from a plain (non-DV) model, so pq instanceof RerankingParserQuery is false for the first sentence from DocumentPreprocessor.","commonSituations":"Pointing -model at englishPCFG.ser.gz instead of a DVParser-serialized model; dropping the unused-args pass-through to loadModel; editing the tool to load a different model type.","solutions":["Load a DVParser-serialized model with LexicalizedParser.loadModel(modelPath, newArgs) so reranker options apply","Confirm the model was produced by DVParser (it stores the reranker configuration)","If parsing arbitrary text, ensure the whole pipeline (options) that attaches the DVModelReranker is preserved"],"exampleFix":"// before\nLexicalizedParser parser = LexicalizedParser.loadModel(\"englishPCFG.ser.gz\");\n// after\nLexicalizedParser parser = LexicalizedParser.loadModel(\"dvparser.ser.gz\", newArgs);","handlingStrategy":"validation","validationCode":"ParserQuery pq = parser.parserQuery();\nif (!(pq instanceof RerankingParserQuery)) {\n  throw new IllegalStateException(\"Parser not configured with DV reranker; load DVParser-serialized model with newArgs\");\n}","typeGuard":"boolean isRerankingQuery(ParserQuery pq) {\n  return pq instanceof RerankingParserQuery;\n}","tryCatchPattern":"try {\n  processSentences(parser, inputPath);\n} catch (IllegalArgumentException e) {\n  System.err.println(\"Model lacks reranker: \" + e.getMessage());\n}","preventionTips":["Validate parser configuration before the sentence loop","Load only DVParser-produced model files","Keep the loadModel(modelPath, newArgs) call intact when refactoring"],"tags":["java","dvparser","type-mismatch"],"backgroundTag":"incompatible-source-type","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}