Stanford nlp 关于中国模式中的斯坦福大学CoreNLP

Stanford nlp 关于中国模式中的斯坦福大学CoreNLP,stanford-nlp,Stanford Nlp,如何使用中文模型,我在我的类路径中下载“stanford-corenlp-3.5.2-models-chinese.jar”并复制 <dependency> <groupId>edu.stanford.nlp</groupId> <artifactId>stanford-corenlp</artifactId> <version>3.5.2</version> <classi

如何使用中文模型,我在我的类路径中下载“stanford-corenlp-3.5.2-models-chinese.jar”并复制

<dependency>
    <groupId>edu.stanford.nlp</groupId>
    <artifactId>stanford-corenlp</artifactId>
    <version>3.5.2</version>
    <classifier>models-chinese</classifier>
</dependency>
结果如下。但是它给出了以下错误,我如何解决这个问题

C:\stanford-corenlp-full-2015-04-20>java -cp "*" -Xmx1g edu.stanford.nlp.pipelin
e.StanfordCoreNLP -props StanfordCoreNLP-chinese.properties -annotators segment,
 ssplit -file input.txt
Registering annotator segment with class edu.stanford.nlp.pipeline.ChineseSegmen
terAnnotator
Adding annotator segment
Loading Segmentation Model ... Loading classifier from edu/stanford/nlp/models/s
egmenter/chinese/ctb.gz ... Loading Chinese dictionaries from 1 file:
  edu/stanford/nlp/models/segmenter/chinese/dict-chris6.ser.gz
Done. Unique words in ChineseDictionary is: 423200.
done [22.9 sec].

Ready to process: 1 files, skipped 0, total 1
Processing file C:\stanford-corenlp-full-2015-04-20\input.txt ... writing to C:\
stanford-corenlp-full-2015-04-20\input.txt.xml {
  Annotating file C:\stanford-corenlp-full-2015-04-20\input.txt Adding Segmentat
ion annotation ... INFO: TagAffixDetector: useChPos=false | useCTBChar2=true | u
sePKChar2=false
INFO: TagAffixDetector: building TagAffixDetector from edu/stanford/nlp/models/s
egmenter/chinese/dict/character_list and edu/stanford/nlp/models/segmenter/chine
se/dict/in.ctb
Loading character dictionary file from edu/stanford/nlp/models/segmenter/chinese
/dict/character_list
Loading affix dictionary from edu/stanford/nlp/models/segmenter/chinese/dict/in.
ctb
?]?X?u????j???\?L??o??????????e?D?u?s???????B?b?A??k?|???????????A?w?V?s?????A?
??@?U?^?n???C
?s?????????50?g?~???B?????b?A????s??u???X?u?\?L??o???????A???|???`?|?_????v?T?C
?]?A?????D?u?????B??D?u?q?s?y???H?w???O??~???t????{?A?L?k?X?u?C

--->
[?, ], ?, X, ?u????j???, \, ?L??o??????????e?D?u?s???????B?b?A??k?|???????????A?
w?V?s?????A???@?U?^?n???C, , , , ?s?????????, 50, ?, g?, ~, ???B?????b?A????s??u
???X?u?, \, ?L??o???????A???, |, ???, `, ?, |, ?_????v?T?C, , , , ?, ], ?, A????
?D?u???, ??, B??D?u?q, ?, s?y???H?w???O??, ~, ???t????, {, ?, A?L?k?X?u?C]

}
Processed 1 documents
Skipped 0 documents, error annotating 0 documents
Annotation pipeline timing information:
ChineseSegmenterAnnotator: 0.1 sec.
TOTAL: 0.1 sec. for 34 tokens at 485.7 tokens/sec.
Pipeline setup: 0.0 sec.
Total time for StanfordCoreNLP pipeline: 0.1 sec.

我编辑了您的问题,将命令更改为实际用于生成所示输出的命令。看起来您已经解决了前一个命令:

java -cp "*" -Xmx1g edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,ner,parse,dcoref -file input.txt input.xml
运行了英语分析管道,但这对中文文本不起作用

在v3.5.2中,对中文的CoreNLP支持仍然有点粗糙,希望在下一版本中会更流畅一些。但从这里开始,您需要:

  • 为中文指定属性文件,并提供相应的模型。(如果未指定属性文件,CoreNLP默认为英语):
    -props StanfordCoreNLP chinese.properties
  • 目前,中文分词不是注释器
    tokenize
    ,而是
    segment
    ,在
    StanfordCoreNLP Chinese.properties
    中指定为自定义注释器。(也许我们会在未来的版本中将两者统一起来……)
  • 当前的
    dcoref
    注释器仅适用于英语。有中文的相互参照,但没有完全融入管道。如前所述,如果您想使用它,您目前必须编写一些代码。所以,让我们删除它。(同样,这在未来应该得到更好的整合)
  • 在这一点上,一切正常,但您显示的难看的stderr输出是,默认情况下,分段器已打开VERBOSE,但您的输出字符编码不适合我们的中文输出。默认情况下,我们应该关闭VERBOSE,但您可以使用以下命令将其关闭:
    -segment.VERBOSE false
  • 我们没有中文的柠檬化器,所以不妨删除那个注释器
  • 而且,
    CoreNLP
    需要超过1GB的RAM。试试2GB
在这一点上,一切都应该是好的!使用命令:

java-cp“*”-Xmx2g edu.stanford.nlp.pipeline.StanfordCoreNLP-props StanfordCoreNLP-chinese.properties-annotators segment、ssplit、pos、ner、parse-segment.verbose false-file input.txt

您可以在
input.txt.xml
中获得输出。(我没有发布,因为它有几千行长……)

CoreNLP v3.8.0的更新:如果使用(2017年的最新版本)CoreNLP v3.8.0,则会有一些变化/进展:(i)我们现在对所有语言使用注释器
标记化
,不需要为中文加载自定义注释器;(ii)默认情况下正确关闭详细分段;(iii)[负面进展]要求在
ner
之前有
引理
注释者,即使这对中文来说是不可操作的;(iv)中文现在可以使用coreference,调用为
coref
,这需要注释者事先提及,其统计模型需要相当大的内存。把这些放在一起,您现在就可以很好地使用这个命令了:

java-cp“*”-Xmx3g edu.stanford.nlp.pipeline.StanfordCoreNLP-props StanfordCoreNLP-chinese.properties-annotators tokenize、ssplit、pos、引理、ner、parse、ention、coref-file input.txt

java -cp "*" -Xmx1g edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,ner,parse,dcoref -file input.txt input.xml