NLP Shift reduce 解析器为情绪计算抛出空指针异常

NLP Shift reduce parser is throwing null pointer Exception for Sentiment calculation

我正在尝试使用 nlp 分析情绪。我使用的 stanford-nlp 版本是 3.4.1。我有一些垃圾数据要处理,使用默认 PCFG 文件处理似乎需要大约 45 秒。

示例如下:

String text = "Nm n n 4 n n bkj nun4hmnun Onn njnb hm5bn nm55m nbbh n mnrrnut but n rym4n nbn 4nn65 m nun m n nn nun 4nm 5 gm n my b bb b b rtmrt55tmmm5tttn b b bb g bn nn n h r ret n nun bn d. B bbbbbbbbbbr bung NHnhn nn nk, v v v n gain t g 4gnyhimmigration ndn nb NVnb bin uny 7 nbbbbbnn vv bbvb ninn njnj n4 nm n km n n n cb j bun. Nhfnt bn nn. N hm nn nun m bum my b mmmnbjk nn n by nn nun nun n nun nn bn n nhn n nn n n m NH nb4mnm mkn 4 n n n n hm r b rnfngg4d in b nut mmmkmmm5 bbjn n n ij BBM 8u8i by nun n.nn hm n. n4n By 4n4n bunny RN bny hm j mi. Nymmn FBT not mn n n nm g by n n nnm? Rnyb vCard n5 Yu nn n n n n nt .nm mn nt n nb n n n n by y5nnnhyyh h b b nt njj n m f4n re";
Properties props = new Properties();

props.setProperty("annotators","tokenize, ssplit, pos,parse,sentiment");

StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
Annotation annotation = pipeline.process(text);

根据此处的建议,我再次尝试使用 shift-reduce 解析器。

Properties props = new Properties();
                    props.setProperty("annotators","tokenize, ssplit, pos,parse,sentiment");
props.put("parse.model", "com/example/nlp/englishSR.ser.gz");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
Annotation annotation = pipeline.process(text);

我必须下载 shift-reduce 模型并将其放在 class 路径中。模型 class 正在加载,但抛出空指针异常。有什么想法和建议吗?

您使用的是 3.4.1 版而不是最新版本,是否有特定原因?

如果我 运行 你的代码是最新版本的,它对我有用(在我将 SR 模型的路径更改为 edu/stanford/nlp/models/srparser/englishSR.ser.gz 之后,但我假设你是故意更改该路径的)。

还要确保您下载的模型与您的 CoreNLP 版本兼容。如果您下载了最新的模型并尝试将它们与旧版本的 CoreNLP 一起使用,那么您很可能 运行 会遇到问题。