Nltk: DependencyGraphまたはStanfordParserAPIが「/」を含む文で問題

作成日 2016年11月18日  ·  31コメント  ·  ソース: nltk/nltk

ユーザーは、この文に対してNLTKでスタンフォードのDependencyParser APIを使用すると、この文がスローされ、 AssertionErrorスローされると報告しました。

十代の人生の夢の世界への洞察とサイバーカルチャーを通じた電子表現のすべてのために、この映画は、2時間半の実行時間からまとまりのある物語を引き出したいと思っている人に四分の一を与えません。

コード:

>>> from nltk.parse.stanford import StanfordDependencyParser                                                                                       >>> dep_parser=StanfordDependencyParser(model_path="edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz")                                        
>>> sent = 'for all of its insights into the dream world of teen life , and its electronic expression through cyber culture , the film gives no quarter to anyone seeking to pull a cohesive story out of its 2 1/2-hour running time . '
>>> dep_parser.raw_parse(sent)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/nltk/parse/stanford.py", line 132, in raw_parse
    return next(self.raw_parse_sents([sentence], verbose))
  File "/Library/Python/2.7/site-packages/nltk/parse/stanford.py", line 150, in raw_parse_sents
    return self._parse_trees_output(self._execute(cmd, '\n'.join(sentences), verbose))
  File "/Library/Python/2.7/site-packages/nltk/parse/stanford.py", line 91, in _parse_trees_output
    res.append(iter([self._make_tree('\n'.join(cur_lines))]))
  File "/Library/Python/2.7/site-packages/nltk/parse/stanford.py", line 339, in _make_tree
    return DependencyGraph(result, top_relation_label='root')
  File "/Library/Python/2.7/site-packages/nltk/parse/dependencygraph.py", line 84, in __init__
    top_relation_label=top_relation_label,
  File "/Library/Python/2.7/site-packages/nltk/parse/dependencygraph.py", line 328, in _parse
    assert cell_number == len(cells)
AssertionError

おそらく、 DependencyGraphが出力を読み取っている方法、またはスタンフォードの出力に一貫性がない可能性があります。

NLTK + Stanfordツールのセットアップの詳細については、 https: //gist.github.com/alvations/e1df0ba227e542955a8a#stanford-parserを参照して

bug dependency parsing pleaseverify

最も参考になるコメント

@dimazest問題は解決しました。 いつもあなたの助けと忍耐に感謝します!

全てのコメント31件

こんにちは@alvationsこれに関する更新はありますか?
ありがとう

@ hoavt-54#1249の新しいインターフェイスを使用して、問題の原因となっているのがスタンフォード側なのかDependencyGraphコードなのかをすばやく確認する方法があると思います。 今日は少し忙しいですが、誰か他の人がチェックして、これに戻ることができるかもしれません。

私は見ることができます、どういうわけか私はこの問題を見逃しました。

@dimazestこんにちは、私はちょうどこのエラーに遭遇しました。 これをどのように修正すればよいですか?

@tessloclあなたの文章は何ですか? 代わりにCoreNLP(nltk / parse / corenlp.py)を使用しようとしましたか?

@dimazestやったばかりで、別のエラーが発生しました:

Traceback (most recent call last):
  File "C:\Users\Admin\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 386, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "C:\Users\Admin\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 382, in _make_request
    httplib_response = conn.getresponse()
  File "C:\Users\Admin\Anaconda3\lib\http\client.py", line 1198, in getresponse
    response.begin()
  File "C:\Users\Admin\Anaconda3\lib\http\client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "C:\Users\Admin\Anaconda3\lib\http\client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "C:\Users\Admin\Anaconda3\lib\socket.py", line 576, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Admin\Anaconda3\lib\site-packages\requests\adapters.py", line 423, in send
    timeout=timeout
  File "C:\Users\Admin\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 649, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:\Users\Admin\Anaconda3\lib\site-packages\requests\packages\urllib3\util\retry.py", line 347, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "C:\Users\Admin\Anaconda3\lib\site-packages\requests\packages\urllib3\packages\six.py", line 686, in reraise
    raise value
  File "C:\Users\Admin\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "C:\Users\Admin\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 388, in _make_request
    self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
  File "C:\Users\Admin\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 308, in _raise_timeout
    raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
requests.packages.urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='localhost', port=9000): Read timed out. (read timeout=60)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\classifier\feature_extraction.py", line 473, in <module>
    print(feature_extraction(test_file_id))
  File "E:\classifier\feature_extraction.py", line 146, in feature_extraction
    for line in dep_parse:
  File "C:\Users\Admin\Anaconda3\lib\site-packages\nltk\parse\corenlp.py", line 279, in raw_parse_sents
    parsed_data = self.api_call(sentence, properties=default_properties)
  File "C:\Users\Admin\Anaconda3\lib\site-packages\nltk\parse\corenlp.py", line 247, in api_call
    timeout=60,
  File "C:\Users\Admin\Anaconda3\lib\site-packages\requests\sessions.py", line 535, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "C:\Users\Admin\Anaconda3\lib\site-packages\requests\sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\Admin\Anaconda3\lib\site-packages\requests\sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\Admin\Anaconda3\lib\site-packages\requests\adapters.py", line 499, in send
    raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='localhost', port=9000): Read timed out. (read timeout=60)

StanfordDependencyParserの部分のみを変更し、残りのコードは変更しませんでした。 ドキュメントを確認しましたが、CoreNLPのメソッドは同じだと思いますが、正しいですか? エラーは解析結果をループする次の行にあるため、解析は成功したようです。

cornlpサーバーを起動する必要があります。次のことを試してください。

with CoreNLPServer(port=9000) as server:
    parser = CoreNLPParser(url=server.url)
    parser.parse(...)

電話で入力しているので、ドキュメントが不足していることと、シャツの返信をお詫びします。

@dimazest私はあなたの助けと迅速な返信に本当に感謝しています。 しかし、エラーが発生します:(

Traceback (most recent call last):
  File "E:\classifier\feature_extraction.py", line 474, in <module>
    print(feature_extraction(test_file_id))
  File "E:\classifier\feature_extraction.py", line 135, in feature_extraction
    with CoreNLPServer(port=9000) as server:
  File "C:\Users\Admin\Anaconda3\lib\site-packages\nltk\parse\corenlp.py", line 81, in __init__
    try_port(port)
  File "C:\Users\Admin\Anaconda3\lib\site-packages\nltk\parse\corenlp.py", line 35, in try_port
    sock.bind(('', port))
OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted

グーグルしてみましたが、ソケットの仕組みがわかりません...

他のポートを試すことができます。たとえば、CoreNLPServer(port = 9001)、またはCoreNLPServer()だけの場合は、空きポートを選択する必要があります。

@dimazest私は9001から9010までを試しましたが、括弧も空でした。これは毎回得られるものです。

Traceback (most recent call last):
  File "E:\classifier\feature_extraction.py", line 509, in <module>
    print(feature_extraction(test_file_id))
  File "E:\classifier\feature_extraction.py", line 136, in feature_extraction
    with CoreNLPServer() as server:
  File "C:\Users\Admin\Anaconda3\lib\site-packages\nltk\parse\corenlp.py", line 170, in __enter__
    self.start()
  File "C:\Users\Admin\Anaconda3\lib\site-packages\nltk\parse\corenlp.py", line 149, in start
    'Could not connect to the server.'
nltk.parse.corenlp.CoreNLPServerError: Could not connect to the server.

私が中国にいることを考えると、VPNを実行している間はVPNをオンのままにしましたが、それでも運がありません。 ここで私の問題は何でしょうか?

corenlp .jarsはありますか? corenlpサーバーをローカルで実行する必要があります。

この例を実行できますかhttps://github.com/nltk/nltk/pull/1249#pullrequestreview-18096061

私はディレクトリE:\classifier\stanford\stanford-corenlp-full-2016-10-31下にjarファイルを持っており、これらはあなたが参照しているものだと思います:

stanford-corenlp-3.7.0.jar
stanford-corenlp-3.7.0-javadoc.jar
stanford-corenlp-3.7.0-models.jar
stanford-corenlp-3.7.0-sources.jar

そして、ディレクトリはCLASSPATH環境変数に設定されています。

Windowsのコマンドプロンプトで例を実行できます。これが出力です。

Python 3.5.3 |Anaconda custom (64-bit)| (default, Feb 22 2017, 21:28:42) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from nltk.parse.corenlp import *
>>> global server
>>> server = CoreNLPServer()
>>> server.start()
>>> parser = CoreNLPParser(url='http://localhost:9000')
>>> sent = 'the quick brown fox jumps over the lazy dog'
>>> parser.raw_parse(sent)
<list_iterator object at 0x000001F0EFED69E8>
>>> fox_parsed = next(parser.raw_parse(sent))
>>> fox_parsed.pretty_print()
                     ROOT
                      |
                      NP
       _______________|_________
      |                         NP
      |                _________|___
      |               |             PP
      |               |     ________|___
      NP              NP   |            NP
  ____|__________     |    |     _______|____
 DT   JJ    JJ   NN  NNS   IN   DT      JJ   NN
 |    |     |    |    |    |    |       |    |
the quick brown fox jumps over the     lazy dog

そして、この行を実行すると、 server.start()のWindowsセキュリティアラートがポップアップし、これは常にファイアウォールの障害だと思っていたので、ファイアウォール設定に移動して、Java(TM)PlatformSEバイナリがファイアウォールを通過できるようにしました。 これで問題は解決すると思いましたが、エディターを再度開いてコードを実行すると、同じエラーが発生します。

Traceback (most recent call last):
  File "E:\classifier\feature_extraction.py", line 503, in <module>
    print(feature_extraction(test_file_id))
  File "E:\classifier\feature_extraction.py", line 130, in feature_extraction
    with CoreNLPServer() as server:
  File "C:\Users\Admin\Anaconda3\lib\site-packages\nltk\parse\corenlp.py", line 170, in __enter__
    self.start()
  File "C:\Users\Admin\Anaconda3\lib\site-packages\nltk\parse\corenlp.py", line 149, in start
    'Could not connect to the server.'
nltk.parse.corenlp.CoreNLPServerError: Could not connect to the server.

サーバーを起動したら、ブラウザでhttp:// localhost :9000にアクセスできますか?

サーバーを自分で起動することもできます。https://stanfordnlp.github.io/CoreNLP/corenlp-server.htmlを参照して

実行中で、ブラウザーからアクセスできる場合は、パーサーを使用できるはずです。

parser = CoreNLPParser(url='http://localhost:9000')
# and so on

それを見つけるために、コマンドプロンプトで例をもう一度実行しますが、今回はおなじみのエラーが発生します

Python 3.5.3 |Anaconda custom (64-bit)| (default, Feb 22 2017, 21:28:42) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from nltk.parse.corenlp import *
>>> global server
>>> server = CoreNLPServer()
>>> server.start()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Admin\Anaconda3\lib\site-packages\nltk\parse\corenlp.py", line 149, in start
    'Could not connect to the server.'
nltk.parse.corenlp.CoreNLPServerError: Could not connect to the server.
>>> server.start()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Admin\Anaconda3\lib\site-packages\nltk\parse\corenlp.py", line 149, in start
    'Could not connect to the server.'
nltk.parse.corenlp.CoreNLPServerError: Could not connect to the server.

...そして私はその間に何が起こったのか分かりません。 構成は変更していません。

このプロジェクトをずっと前にLinuxに移行したかったのですが、LinuxでNLTK was unable to find ***.jar! Set the CLASSPATH environment variableエラーが発生し続けます。 /etc/environment/etc/profile 、および~/.bash_profile CLASSPATHを設定し、それらのjarファイルを$JAVA_HOME/lib/コピーしようとしましたが、問題は解決しません。 別の問題を開く必要がありますか?

(Pythonからではなく)ターミナルからcorenlpサーバーを起動できますか?詳細については、 https: //stanfordnlp.github.io/CoreNLP/corenlp-server.htmlを確認してください。

# Run the server using all jars in the current directory (e.g., the CoreNLP home directory)
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000
E:\classifier\stanford\stanford-corenlp-full-2016-10-31>java -mx4g -cp "E:\classifier\stanford\stanford-corenlp-full-2016-10-31" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000
Error: Could not find or load main class edu.stanford.nlp.pipeline.StanfordCoreNLPServer

E:\classifier\stanford\stanford-corenlp-full-2016-10-31>java -Xmx4g -cp "E:\classifier\stanford\stanford-corenlp-full-2016-10-31" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -serverProperties StanfordCoreNLP-chinese.properties -port 9000 -timeout 15000
Error: Could not find or load main class edu.stanford.nlp.pipeline.StanfordCoreNLPServer

E:\classifier\stanford\stanford-corenlp-full-2016-10-31>java -mx4g -cp "E:\classifier\stanford\stanford-corenlp-full-2016-10-31" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -timeout 15000
Error: Could not find or load main class edu.stanford.nlp.pipeline.StanfordCoreNLPServer

そうではないようです。 私はそれを正しくやっていますか?

私はついにそれらのスタンフォードモジュールをLinux上で動作させるようになりました。 同じコード行で、CoreNLPサーバーは問題なく起動しているように見えますが、解析結果をループする行で他のエラーが発生します。

Traceback (most recent call last):
  File "/home/tesslo/anaconda3/lib/python3.5/site-packages/requests/packages/urllib3/connection.py", line 141, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/home/tesslo/anaconda3/lib/python3.5/site-packages/requests/packages/urllib3/util/connection.py", line 83, in create_connection
    raise err
  File "/home/tesslo/anaconda3/lib/python3.5/site-packages/requests/packages/urllib3/util/connection.py", line 73, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tesslo/anaconda3/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/home/tesslo/anaconda3/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 356, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/home/tesslo/anaconda3/lib/python3.5/http/client.py", line 1107, in request
    self._send_request(method, url, body, headers)
  File "/home/tesslo/anaconda3/lib/python3.5/http/client.py", line 1152, in _send_request
    self.endheaders(body)
  File "/home/tesslo/anaconda3/lib/python3.5/http/client.py", line 1103, in endheaders
    self._send_output(message_body)
  File "/home/tesslo/anaconda3/lib/python3.5/http/client.py", line 934, in _send_output
    self.send(msg)
  File "/home/tesslo/anaconda3/lib/python3.5/http/client.py", line 877, in send
    self.connect()
  File "/home/tesslo/anaconda3/lib/python3.5/site-packages/requests/packages/urllib3/connection.py", line 166, in connect
    conn = self._new_conn()
  File "/home/tesslo/anaconda3/lib/python3.5/site-packages/requests/packages/urllib3/connection.py", line 150, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
requests.packages.urllib3.exceptions.NewConnectionError: <requests.packages.urllib3.connection.HTTPConnection object at 0x7f110a9c4940>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tesslo/anaconda3/lib/python3.5/site-packages/requests/adapters.py", line 438, in send
    timeout=timeout
  File "/home/tesslo/anaconda3/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 649, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/home/tesslo/anaconda3/lib/python3.5/site-packages/requests/packages/urllib3/util/retry.py", line 388, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
requests.packages.urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=9000): Max retries exceeded with url: /?properties=%7B%22annotators%22%3A+%22tokenize%2Cpos%2Clemma%2Cssplit%2Cdepparse%22%2C+%22outputFormat%22%3A+%22json%22%2C+%22ssplit.isOneSentence%22%3A+%22true%22%7D (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7f110a9c4940>: Failed to establish a new connection: [Errno 111] Connection refused',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/media/tesslo/classifier/feature_extraction.py", line 503, in <module>
    print(feature_extraction(test_file_id))
  File "/media/tesslo/classifier/feature_extraction.py", line 142, in feature_extraction
    for line in dep_parse:
  File "/home/tesslo/anaconda3/lib/python3.5/site-packages/nltk/parse/corenlp.py", line 279, in raw_parse_sents
    parsed_data = self.api_call(sentence, properties=default_properties)
  File "/home/tesslo/anaconda3/lib/python3.5/site-packages/nltk/parse/corenlp.py", line 247, in api_call
    timeout=60,
  File "/home/tesslo/anaconda3/lib/python3.5/site-packages/requests/sessions.py", line 565, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/home/tesslo/anaconda3/lib/python3.5/site-packages/requests/sessions.py", line 518, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/tesslo/anaconda3/lib/python3.5/site-packages/requests/sessions.py", line 639, in send
    r = adapter.send(request, **kwargs)
  File "/home/tesslo/anaconda3/lib/python3.5/site-packages/requests/adapters.py", line 502, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=9000): Max retries exceeded with url: /?properties=%7B%22annotators%22%3A+%22tokenize%2Cpos%2Clemma%2Cssplit%2Cdepparse%22%2C+%22outputFormat%22%3A+%22json%22%2C+%22ssplit.isOneSentence%22%3A+%22true%22%7D (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7f110a9c4940>: Failed to establish a new connection: [Errno 111] Connection refused',))

参考までに、LinuxとWindowsは同じハードウェアを共有しています。

わかりました。2つのステップが含まれます。
1)CoreNLPJavaプロセスを開始します。 2つの方法があります。手動で開始することをお勧めします。つまり、 java -Xmx4g -cp ...コマンドを使用します。 成功しましたか? http:// localhost:9000にアクセスすると、ブラウザを介してサーバーにアクセスできるはずです。 コンソール出力に、使用されているポートが表示されます。
2)サーバーが実行されたら、CoreNLP pythonクライアントparser = CoreNLPParser(url='http://localhost:9000')を作成できます。 CoreNLP Javaサーバーを自分で起動したので、Pythonセッション内で起動する必要はありません( server = CoreNLPServer()実行しないでください)

投稿したエラーメッセージは、CoreNLPJavaサーバーが実行されていないことを示しています。

失敗しました:

tesslo<strong i="6">@TLU</strong>:/media/tesslo/classifier/stanford/stanford-corenlp-full-2016-10-31$ java -mx4g -cp "/media/tesslo/classifier/stanford/stanford-corenlp-full-2016-10-31" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000
Error: Could not find or load main class edu.stanford.nlp.pipeline.StanfordCoreNLPServer
tesslo<strong i="7">@TLU</strong>:/media/tesslo/classifier/stanford/stanford-corenlp-full-2016-10-31$ java -Xmx4g -cp "/media/tesslo/classifier/stanford/stanford-corenlp-full-2016-10-31" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -serverProperties StanfordCoreNLP-chinese.properties -port 9000 -timeout 15000
Error: Could not find or load main class edu.stanford.nlp.pipeline.StanfordCoreNLPServer
tesslo<strong i="8">@TLU</strong>:/media/tesslo/classifier/stanford/stanford-corenlp-full-2016-10-31$ java -mx4g -cp "/media/tesslo/classifier/stanford/stanford-corenlp-full-2016-10-31" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -timeout 15000
Error: Could not find or load main class edu.stanford.nlp.pipeline.StanfordCoreNLPServer

また、 http:// localhost :9000はERR_CONNECTION_REFUSEDエラーを示しています

"*"をクラスパスとして使用してみましたか:j ava -mx4g -cp "*" ...

こんにちは、私もこの問題に遭遇したようです。 私の文章は:
「たぶん、2 21/2フィートのコード?」、u「そして、マイクロUSBが差し込まれる充電器の部分よりも安価な品質です...」
そして、私は理解しようとしました、「/」がこのエラーを引き起こしているようです。

@caisinong新しいCoreNLPインターフェースを使用してみましたか? 上記の私のコメントを参照してください。

@dimazest遅れてすみません。 私はちょうど今しました:

tesslo<strong i="7">@TLU</strong>:/media/tesslo/classifier/stanford/stanford-corenlp-full-2016-10-31$ java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000
[main] INFO CoreNLP - --- StanfordCoreNLPServer#main() called ---
[main] INFO CoreNLP - setting default constituency parser
[main] INFO CoreNLP - warning: cannot find edu/stanford/nlp/models/srparser/englishSR.ser.gz
[main] INFO CoreNLP - using: edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz instead
[main] INFO CoreNLP - to use shift reduce parser download English models jar from:
[main] INFO CoreNLP - http://stanfordnlp.github.io/CoreNLP/download.html
[main] INFO CoreNLP -     Threads: 2
[main] INFO CoreNLP - Starting server...
[main] INFO CoreNLP - StanfordCoreNLPServer listening at /0:0:0:0:0:0:0:0:9000

これでhttp:// localhost :9000にアクセスできますが、エディターに戻ると、サーバーを起動している行でこのエラーが発生します。

Traceback (most recent call last):
  File "/media/tesslo/classifier/feature_extraction.py", line 503, in <module>
    print(feature_extraction(test_file_id))
  File "/media/tesslo/classifier/feature_extraction.py", line 130, in feature_extraction
    with CoreNLPServer() as server:
  File "/home/tesslo/anaconda3/lib/python3.5/site-packages/nltk/parse/corenlp.py", line 170, in __enter__
    self.start()
  File "/home/tesslo/anaconda3/lib/python3.5/site-packages/nltk/parse/corenlp.py", line 149, in start
    'Could not connect to the server.'
nltk.parse.corenlp.CoreNLPServerError: Could not connect to the server.

サーバーを手動で起動した後は、コードでサーバーを起動する必要あり

サーバーを実行し続け、パーサーをインスタンス化します。

parser = CoreNLPParser(url='http://localhost:9000')

@dimazest問題は解決しました。 いつもあなたの助けと忍耐に感謝します!

私も同じような経験があります。 コードでStanfordCorenNLPサーバーを起動するのは面倒であり、テスト目的でのみ使用する必要があります。 たぶん、それをユーザーに公開するべきではありません。

うまくいっていてうれしいです。 実際、サーバーはPythonコードの外部で起動する必要があります。

新しいCoreNLPAPIによってパッチが適用され、解決されました=)

@dimazestこんにちは...テキストに\または/場合、 Assertion Error解決策はコアNLPのみを使用することですか? stanford-parser-full-2017-06-09
構文解析に使用された文はIraqi security forces drove Islamic State fighters from the centre of a town just south of the militants\' main stronghold of Mosul on Saturday and reached within a few km (miles) of an airport on the edge of the city, a senior commander said.

@ kavin26はい、 nltk.parse.corenlp.CoreNLPParserを使用してください。

@alvationsどうもありがとうございました:+1:

このページは役に立ちましたか?
0 / 5 - 0 評価