【问题标题】:NLP Shift reduce parser is throwing null pointer Exception for Sentiment calculationNLP Shift reduce 解析器为 Sentiment 计算抛出空指针异常
【发布时间】:2015-05-24 07:15:38
【问题描述】:

我正在尝试使用 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 模型并将其放入类路径中。模型类正在加载,但它抛出了一个空指针异常。有什么想法和建议吗?

【问题讨论】:

    标签: nlp stanford-nlp sentiment-analysis shift-reduce


    【解决方案1】:

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

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

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

    【讨论】:

    • 谢谢塞巴斯汀。是的,这是模型版本错误的问题。当我更改为模型的正确版本时,它工作正常。我拿了 3.4.1 因为我们的大多数应用程序都在 jdk1.7 上,最新的是 1.8。感谢大家的帮助
    猜你喜欢
    • 2012-02-04
    • 2013-04-09
    • 1970-01-01
    • 2014-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多