簡體   English   中英

NLP ShiftReduce解析器拋出空指針,用於情感計算

[英]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模型並將其放在類路徑中。 模型類正在加載,但引發了空指針異常。 有什么想法和建議嗎?

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

如果我使用最新版本運行您的代碼,那么它對我edu/stanford/nlp/models/srparser/englishSR.ser.gz (在我將SR模型的路徑更改為edu/stanford/nlp/models/srparser/englishSR.ser.gz但我想您是故意更改了該路徑) 。

還要確保您下載的模型與您的CoreNLP版本兼容。 如果您下載了最新模型並嘗試將它們與較舊版本的CoreNLP結合使用,則很可能會遇到問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM