nltk: corenlp.py CoreNLPServer throws TypeError exception

Hello,

Here’s the code:

>>> s = nltk.parse.corenlp.CoreNLPServer(path_to_jar='/usr/local/share/stanford/stanford-corenlp-3.8.0.jar', path_to_models_jar='/usr/local/share/stanford/stanford-english-corenlp-2017-06-09-models.jar')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    s = nltk.parse.corenlp.CoreNLPServer(path_to_jar='/usr/local/share/stanford/stanford-corenlp-3.8.0.jar', path_to_models_jar='/usr/local/share/stanford/stanford-english-corenlp-2017-06-09-models.jar')
  File "/Users/adiep/feedback-sentiment/.env/src/nltk/nltk/parse/corenlp.py", line 69, in __init__
    key=lambda model_name: re.match(self._JAR, model_name)
TypeError: '>' not supported between instances of 'NoneType' and 'NoneType'

The max function is throwing this exception.

I think what’s happening is that key=lambda model_name: re.match(self._JAR, model_name) is returning NoneType because it didn’t match anything. So it fills the list of NoneType and max fails to sort it. I found that self._JAR and model_name evaluated to the following:

>>> type(re.match(r'stanford-corenlp-(\d+)\.(\d+)\.(\d+)\.jar', '/usr/local/share/stanford/stanford-corenlp-3.8.0.jar'))
<class 'NoneType'>

Thanks,

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21 (6 by maintainers)

Most upvoted comments

Good lord, now it’s working.

So overall, I had to change re.match to re.search.group and kill a floating corenlpserver in the background.

Maybe there should be some code to detect if there is other corenlpservers running? Don’t know if it’s even worth doing.

Hi, I’m sorry that there is no documentation. The API has changed, here are is what you need to do. Refer to #1510, it contains a long discussion on how to start a server.

The main change: NLTK does not start CoreNLP server, you need to start it. Refer to https://stanfordnlp.github.io/CoreNLP/corenlp-server.html for a detailed explanation, but the command should be something like:

# 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

Open http://localhost:9000/ to make sure that the server is running.

Now you are ready to use NLTK corenlp client:

tagger = CoreNLPNERTagger(url='http://localhost:9000')
tokens = tagger.tag(text)

Please let me know if it works.

Seems like if you don’t use with clauses, create servers objects, and don’t stop them, python deletes the object but not the actual server. What I was doing is that I was starting servers in my interpreter and forgetting to run s.stop().

Ok, so it was the proxy problem. I found that you can set NO_PROXY='localhost'.

Now I have the problem with the server refusing connects.

I am not sure why, but when I init the server object, it starts a server at port 9000. Edit: Turns out I had a corenlp server floating in the background. I just killed it and now it’s pinging port 9000.

>>> s = nltk.parse.corenlp.CoreNLPServer(verbose=True)
[Found stanford-corenlp-(\d+)\.(\d+)\.(\d+)\.jar: /usr/local/share/stanford/stanford-corenlp-3.8.0.jar]
[Found stanford-corenlp-(\d+)\.(\d+)\.(\d+)\.jar: /usr/local/share/stanford/stanford-corenlp-3.8.0.jar]
[Found stanford-corenlp-(\d+)\.(\d+)\.(\d+)-models\.jar: /usr/local/share/stanford/stanford-corenlp-3.8.0-models.jar]
>>> s.start()
[Found java: /usr/bin/java]
[Found java: /usr/bin/java]
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105c812b0>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105c814a8>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105c9c160>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105c9c2e8>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10368f5f8>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105c30160>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105c81908>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105c81400>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105cab8d0>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105cab6a0>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105c9c898>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105c9cd68>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105cb34a8>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105cb3438>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105cb3ba8>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105cabc50>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105cab400>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105cab8d0>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105cab940>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105d00e48>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105cb30b8>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105caba58>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105cabc50>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105cfee10>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105cfe828>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105d004a8>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105d00fd0>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105d090f0>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105cfe7f0>: Failed to establish a new connection: [Errno 61] Connection refused',))
HTTPConnectionPool(host='localhost', port=59023): Max retries exceeded with url: /live (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x105cab780>: Failed to establish a new connection: [Errno 61] Connection refused',))
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    s.start()
  File "/Users/adiep/feedback-sentiment/.env/src/nltk/nltk/parse/corenlp.py", line 150, in start
    'Could not connect to the server.'
nltk.parse.corenlp.CoreNLPServerError: Could not connect to the server.

Seems like what happening is that re.match is being feed the full path, it searches for the jar file at the beginning of the string, and always fails. I think it is suppose to be feed just the names of the jar files.