mxd*_*xdg 5 python nlp nltk stanford-nlp
我正在尝试按照此处的示例通过 NLTK 使用斯坦福解析器。
我遵循示例的前两行(带有必要的导入)
from nltk.parse.corenlp import CoreNLPDependencyParser
dep_parser = CoreNLPDependencyParser(url='http://localhost:9000')
parse, = dep_parser.raw_parse('The quick brown fox jumps over the lazy dog.')
Run Code Online (Sandbox Code Playgroud)
但我收到一条错误消息:
[...] Failed to establish a new connection: [Errno 61] Connection refused"
Run Code Online (Sandbox Code Playgroud)
我意识到尝试连接到作为构造函数输入给出的 url 一定是一个问题。
dep_parser = CoreNLPDependencyParser(url='http://localhost:9000')
Run Code Online (Sandbox Code Playgroud)
如果不是这个,我应该连接到哪个网址?如果这是正确的,问题是什么?
您需要首先在 上下载并运行 CoreNLP 服务器localhost:9000。
1) 从https://stanfordnlp.github.io/CoreNLP/download.html下载 CoreNLP
2) 将文件解压到某个目录,然后在该目录中运行以下命令来启动服务器
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000
Run Code Online (Sandbox Code Playgroud)
参考: https: //stanfordnlp.github.io/CoreNLP/corenlp-server.html
上面代码的结果就像
>>> print(parse.to_conll(4))
The DT 4 det
quick JJ 4 amod
brown JJ 4 amod
fox NN 5 nsubj
jumps VBZ 0 ROOT
over IN 9 case
the DT 9 det
lazy JJ 9 amod
dog NN 5 nmod
. . 5 punct
Run Code Online (Sandbox Code Playgroud)
也可以通过NLTK API启动服务器(需要CORENLP_HOME先配置环境变量)
os.environ["CORENLP_HOME"] = "dir"
client = corenlp.CoreNLPClient()
# do something
client.stop()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2223 次 |
| 最近记录: |