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)
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:
Open http://localhost:9000/ to make sure that the server is running.
Now you are ready to use NLTK corenlp client:
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.
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.