在python中使用Stanford Corenlp进行中文学习

2024-05-15 15:20:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用coreNLP的中文文本分割、POS和NER功能。我试图将windows 10上的official StanfordCoreNLP python packagepython 3.6一起使用。在

我不知道如何让CoreNLP用中文工作。我已经从official corenlp website下载了stanford-corenlp-full-2018-02-27.zip文件以及stanford-chinese-corenlp-2018-02-27-model.jar文件。部分问题是,斯坦福大学的CoreNLP似乎有数百个python包装器,包括nltkstanfordcorenlppy-corenlp等;这使得我很难找到我到底需要为任何特定的包做什么。我目前正在使用corenlp软件包。我怀疑解决方案是将Chinese.jar的语言或路径传递到分段器中。在

英语代码(来自官方网站):

import corenlp

text = "Chris wrote a simple sentence that he parsed with Stanford CoreNLP."
with corenlp.CoreNLPClient(annotators="tokenize ssplit".split()) as client:
     ann = client.annotate(text)
sentence = ann.sentence[0]
sentence.token[0].word
>>>"Chris"

尝试使用一个中文句子会产生POS或NER标记的记忆错误,以及标记化的编码(我相信)错误。在


Tags: 文件text标记posclientwithsentencejar
1条回答
网友
1楼 · 发布于 2024-05-15 15:20:58

corenlp-python充当CoreNLP Server的客户端。 为了方便起见,调用客户机将启动一个default server,它提供英语NLP任务。在

您可以自己start the server,配置中文支持:

java -Xmx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -serverProperties StanfordCoreNLP-chinese.properties -port 9000 -timeout 15000

使用python客户机时,告诉它不需要启动default server

^{pr2}$

相关问题 更多 >