1

对如何通过节启动 corenlp 客户端感到非常困惑。我无法让它同时在我的 Windows pc 和 ubuntu pc 上工作。环境变量对我来说似乎没问题,因为在“使用命令启动服务器:java [...]”它在两个系统上都获得了正确的路径(如下所示)。

这是来自 Windows 的日志,我使用带有 python 3.7 和 anaconda 的 jupyter notebook。是的,Java 已安装,其版本为 1.8.0_261-b12

2020-08-23 16:19:39 INFO: Writing properties to tmp file: corenlp_server-cb875580c6b14b81.props
2020-08-23 16:19:39 INFO: Starting server with command: java -Xmx4G -cp C:\Users\mikol\stanza_corenlp\* edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 30000 -threads 5 -maxCharLength 100000 -quiet False -serverProperties corenlp_server-cb875580c6b14b81.props -annotators tokenize,ssplit,pos,lemma,ner,parse,depparse,coref -preload -outputFormat serialized
---------------------------------------------------------------------------
UnsupportedOperation                      Traceback (most recent call last)
<ipython-input-3-8480433fb1e5> in <module>
      4         annotators=['tokenize','ssplit','pos','lemma','ner', 'parse', 'depparse','coref'],
      5         timeout=30000,
----> 6         memory='4G') as client:
      7     ann = client.annotate(test_doc)
      8     print(ann)

C:\ProgramData\Anaconda3\lib\site-packages\stanza\server\client.py in __enter__(self)
    174 
    175     def __enter__(self):
--> 176         self.start()
    177         return self
    178 

C:\ProgramData\Anaconda3\lib\site-packages\stanza\server\client.py in start(self)
    146             self.server = subprocess.Popen(self.start_cmd,
    147                                            stderr=stderr,
--> 148                                            stdout=stderr)
    149 
    150     def atexit_kill(self):

C:\ProgramData\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    751         (p2cread, p2cwrite,
    752          c2pread, c2pwrite,
--> 753          errread, errwrite) = self._get_handles(stdin, stdout, stderr)
    754 
    755         # We wrap OS handles *before* launching the child, otherwise a

C:\ProgramData\Anaconda3\lib\subprocess.py in _get_handles(self, stdin, stdout, stderr)
   1084             else:
   1085                 # Assuming file-like object
-> 1086                 c2pwrite = msvcrt.get_osfhandle(stdout.fileno())
   1087             c2pwrite = self._make_inheritable(c2pwrite)
   1088 

UnsupportedOperation: fileno

两台机器上的错误代码看起来都一样,只是文件路径不同。

如果有人可以帮助我,我将不胜感激,如果没有 corenlp 工具,我在我的项目 atm 上无能为力。

4

1 回答 1

0

对于遇到相同问题的每个人,按重要性排序以及您应该首先尝试什么。如果它不起作用,则进入下一步。

  1. be_quiet=True在 python ex 中调用客户端时使用参数。

    from stanza.server import CoreNLPClient with CoreNLPClient( annotators=['tokenize','ssplit','pos',"ner"], timeout=30000, memory='2G',be_quiet=True) 作为客户端:

  2. 确保您安装了 64 位版本的 JAVA。可以使用 java -d64 从 cmd 检查,如果它给出错误,那么你没有 64 位 java。

  3. 为您的系统(非用户)添加一个新的/编辑环境变量变量名称:CORENLP_HOME 变量值:*** 安装 corenlp 的目录和语言模型***(例如英语,它没有开箱即用) )

编辑或添加环境后重新启动计算机。多变的

如果这些都没有帮助,那么您已经搞砸了,因此只需删除安装 corenlp 的整个文件夹并执行新安装,可以是与以前相同的路径。

我建议使用节命令进行安装

在 python 中只需执行以下这些命令,在 Jupyter 中即可:

import stanza
stanza.install_corenlp(dir="C:\\Users\\YOUR_USERNAME\\stanza_corenlp")
stanza.download_corenlp_models(model='english', version='4.1.0', dir="C:\\Users\\YOUR_USERNAME\\stanza_corenlp")

安装后编辑环境变量 CORENLP_HOME 使其与新的安装目录匹配,例如在我的情况下

CORENLP_HOME : C:\Users\YOUR_USERNAME\stanza_corenlp

对于调试,请尝试单独从 cmd 运行服务器启动命令。如果 java 本身没有启动您的服务器,那么从 python 调用它时您的服务器也不会启动。您可以尝试的示例命令是:

*** 在 -cp 之后使用 "" 并在其中将您的安装路径与 * 放在最后。

java -Xmx1512m -cp "C:\Users\YOUR_USERNAME\stanza_corenlp\*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 30000 -threads 2 -maxCharLength 100000 -quiet False -preload tokenize,ssplit,pos,lemma,ner

如果它会启动,那么你们都很好,你可以通过在浏览器中输入 localhost:9000 来检查它是否正常运行

它应该显示一个带有 corenlp 演示的页面。

于 2020-11-17T19:37:23.950 回答