Nltk: Masalah DependencyGraph atau Stanford Parser API dengan kalimat dengan "/"

Dibuat pada 18 Nov 2016  ·  31Komentar  ·  Sumber: nltk/nltk

Seorang pengguna telah melaporkan bahwa kalimat ini melempar dan AssertionError saat menggunakan API DependencyParser Stanford di NLTK untuk kalimat ini:

untuk semua wawasannya tentang dunia impian kehidupan remaja, dan ekspresi elektroniknya melalui budaya dunia maya, film ini tidak memberikan seperempat bagi siapa pun yang ingin menarik cerita yang kohesif dari waktu tayang 2 1/2 jam.

Kode:

>>> 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

Mungkin, mungkin bagaimana DependencyGraph membaca keluaran atau keluaran Stanford tidak konsisten.

Detail lebih lanjut tentang penyiapan untuk alat NLTK + Stanford ada di https://gist.github.com/alvations/e1df0ba227e542955a8a#stanford -parser

bug dependency parsing pleaseverify

Komentar yang paling membantu

@dimaest Masalahnya sudah terpecahkan. Terima kasih atas bantuan dan kesabaran Anda selama ini!

Semua 31 komentar

Hai @alvations Ada pembaruan tentang ini?
Terima kasih

@ hoavt-54 Saya rasa ada cara cepat untuk memeriksa apakah itu sisi Stanford atau kode DependencyGraph menyebabkan masalah menggunakan antarmuka baru dari # 1249. Saya akan sedikit sibuk hari ini, tetapi mungkin orang lain dapat memeriksanya dan melanjutkannya.

Saya bisa melihatnya, entah bagaimana saya melewatkan masalah ini.

@dimazest Halo, Saya baru saja mengalami kesalahan ini. Bagaimana saya harus memperbaikinya?

@tesslocl apa kalimat Anda? Apakah Anda mencoba menggunakan CoreNLP (nltk / parse / corenlp.py) sebagai gantinya?

@dimazest baru saja saya lakukan dan saya mengalami kesalahan lain:

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)

Saya hanya mengubah bagian StanfordDependencyParser dan membiarkan sisa kode tidak berubah. Saya telah memeriksa dokumennya dan saya kira metode di CoreNLP sama, apakah saya benar? Parsing tampaknya berhasil karena kesalahan ada pada baris berikutnya di mana saya mengulang hasil parse.

Anda perlu memulai server cornlp, coba:

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

Saya minta maaf untuk dokumentasi yang hilang, dan untuk balasan kemeja, saat saya mengetik di ponsel saya.

@dimazest Saya sangat menghargai bantuan dan balasan cepat Anda. Tapi kesalahan tetap ada :(

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

Saya mencoba googling tetapi saya tidak tahu cara kerja soket ...

Anda dapat mencoba port lain: CoreNLPServer (port = 9001), misalnya atau hanya CoreNLPServer () maka port gratis harus dipilih.

@dimazest Saya sudah mencoba 9001 sampai dengan 9010 dan juga tanda kurung kosong dan ini yang saya dapatkan setiap saat:

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.

Mengingat saya berada di China, saya tetap menggunakan VPN saya saat menjalankannya, tetapi tetap tidak berhasil. Apa masalah saya di sini?

Apakah Anda punya corenlp .jars? Anda harus memiliki server corenlp yang berjalan secara lokal.

Dapatkah Anda menjalankan contoh ini https://github.com/nltk/nltk/pull/1249#pullrequestreview -18096061

Saya memiliki toples di bawah direktori E:\classifier\stanford\stanford-corenlp-full-2016-10-31 dan saya kira ini adalah yang Anda rujuk:

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

Dan direktori telah disetel ke variabel lingkungan CLASSPATH.

Saya dapat menjalankan contoh di command prompt windows dan ini adalah outputnya:

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

Dan ketika saya menjalankan baris ini server.start() peringatan keamanan windows muncul dan saya pikir itu adalah kesalahan firewall selama ini jadi saya pergi ke pengaturan firewall untuk mengizinkan Java (TM) Platform SE biner melalui firewall. Saya pikir ini akan menyelesaikan masalah tetapi ketika saya membuka kembali editor dan menjalankan kode, saya masih mendapatkan kesalahan yang sama:

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.

Setelah Anda memulai server, dapatkah Anda mengakses http: // localhost : 9000 di browser Anda?

Anda juga dapat memulai server sendiri, lihat https://stanfordnlp.github.io/CoreNLP/corenlp-server.html

Yang pertama sedang berjalan, dan Anda dapat mengaksesnya melalui browser, Anda harus dapat menggunakan parser:

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

Untuk mengetahuinya saya menjalankan contoh di command prompt lagi tetapi kali ini saya mendapatkan kesalahan yang sudah dikenal

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.

... Dan saya tidak tahu apa yang terjadi di antaranya. Saya tidak mengubah konfigurasi apa pun.

Saya ingin memindahkan proyek ini ke Linux sejak lama tetapi saya terus mendapatkan kesalahan NLTK was unable to find ***.jar! Set the CLASSPATH environment variable di Linux. Saya telah menetapkan CLASSPATH di /etc/environment , /etc/profile , dan ~/.bash_profile dan bahkan mencoba menyalin toples itu ke $JAVA_HOME/lib/ tetapi masalahnya tetap ada. Haruskah saya membuka terbitan lain?

Apakah Anda dapat memulai server corenlp dari terminal (bukan dari python), periksa https://stanfordnlp.github.io/CoreNLP/corenlp-server.html untuk lebih jelasnya?

# 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

Kelihatannya tidak. Apakah saya melakukannya dengan benar?

Saya akhirnya mendapatkan modul Stanford tersebut untuk bekerja di Linux. Dengan baris kode yang sama, server CoreNLP tampaknya mulai tanpa masalah tetapi saya mendapatkan kesalahan lain pada baris di mana saya mengulang hasil parse.

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',))

FYI Linux dan Windows berbagi perangkat keras yang sama.

Oke, ada dua langkah yang terlibat:
1) Mulai proses Java CoreNLP. Ada dua cara, saya sarankan Anda untuk memulai secara manual, yaitu menggunakan perintah java -Xmx4g -cp ... . Apakah Anda berhasil? Anda seharusnya dapat mengakses server melalui browser dengan mengunjungi http: // localhost: 9000. Anda harus melihat di keluaran konsol, port apa yang digunakan.
2) Setelah server berjalan, Anda dapat membuat klien python CoreNLP parser = CoreNLPParser(url='http://localhost:9000') . Karena Anda telah memulai server Java CoreNLP sendiri, Anda tidak perlu memulainya dalam sesi python (jangan jalankan server = CoreNLPServer() )

Pesan kesalahan yang Anda posting menunjukkan bahwa server CoreNLP Java tidak berjalan.

Gagal:

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

Dan http: // localhost : 9000 menunjukkan kesalahan ERR_CONNECTION_REFUSED

Apakah Anda mencobanya dengan "*" sebagai jalur kelas: j ava -mx4g -cp "*" ... ?

Halo, sepertinya saya juga mengalami masalah ini. Kalimat saya adalah:
'Mungkin, kabel 2 21/2 kaki?', U 'Dan kualitasnya lebih murah daripada bagian pengisi daya yang dicolokkan micro usb ...'
Dan saya mencoba mencari tahu, tampaknya '/' menyebabkan kesalahan ini.

@caisinong Sudahkah Anda mencoba menggunakan antarmuka CoreNLP baru? Lihat komentar saya di atas.

@dimazest Maaf atas keterlambatannya. Saya baru saja melakukannya:

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

Saya dapat mengunjungi http: // localhost : 9000 sekarang, tetapi kembali ke editor saya masih mendapatkan kesalahan ini pada baris yang memulai server:

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.

Setelah Anda memulai server secara manual, Anda tidak perlu memulai server dalam kode.

Biarkan server tetap berjalan dan buat instance parser:

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

@dimaest Masalahnya sudah terpecahkan. Terima kasih atas bantuan dan kesabaran Anda selama ini!

Saya memiliki pengalaman serupa. Memulai server Stanford CorenNLP dalam kode itu berantakan dan hanya boleh digunakan untuk tujuan pengujian. Mungkin kita harusnya tidak mengungkapkannya kepada pengguna.

Saya senang semuanya berhasil. Memang, server harus dimulai di luar kode Python.

Ditambal dan diselesaikan dengan CoreNLP API =)

@dimazest Hai ... jika teks berisi \ atau / solusi untuk Assertion Error adalah hanya menggunakan Core NLP? saya menggunakan stanford-parser-full-2017-06-09
Kalimat yang digunakan untuk parsing adalah 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 Ya, gunakan nltk.parse.corenlp.CoreNLPParser .

@alvations terima kasih banyak: +1:

Apakah halaman ini membantu?
0 / 5 - 0 peringkat

Masalah terkait

goodmami picture goodmami  ·  4Komentar

stevenbird picture stevenbird  ·  3Komentar

alvations picture alvations  ·  4Komentar

Chris00 picture Chris00  ·  3Komentar

stevenbird picture stevenbird  ·  4Komentar