brendano / stanford_corenlp_pywrapper

151 stars 59 forks source link

NoSuchMethodError when parsing #8

Closed Romainpaulus closed 9 years ago

Romainpaulus commented 10 years ago

I am following the README instructions with the Stanford CoreNLP version 3.4. The sockwarp instantiation works well and doesn't give any error, but the command p.parse_doc("hello world. how are you?") crashes with the following error:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(Z)V
    at com.google.common.collect.Lists.computeArrayListCapacity(Lists.java:105)
    at com.google.common.collect.Lists.newArrayList(Lists.java:98)
    at corenlp.Parse.addTokenBasics(Parse.java:143)
    at corenlp.Parse.processTextDocument(Parse.java:247)
    at corenlp.PipeCommandRunner.runCommand(PipeCommandRunner.java:128)
    at corenlp.PipeCommandRunner.socketServerLoop(PipeCommandRunner.java:172)
    at corenlp.PipeCommandRunner.main(PipeCommandRunner.java:96)
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-4-6b98ff410d82> in <module>()
----> 1 p.parse_doc("hello world. how are you?")

stanford_corenlp_pywrapper-0.1.0-py2.7.egg/stanford_corenlp_pywrapper/sockwrap.pyc in parse_doc(self, text, timeout)
    131     def parse_doc(self, text, timeout=PARSEDOC_TIMEOUT_SEC):
    132         cmd = "PARSEDOC\t%s" % json.dumps(text)
--> 133         return self.send_command_and_parse_result(cmd, timeout)
    134 
    135     def get_socket(self):

stanford_corenlp_pywrapper-0.1.0-py2.7.egg/stanford_corenlp_pywrapper/sockwrap.pyc in send_command_and_parse_result(self, cmd, timeout)
    142         try:
    143             self.ensure_proc_is_running()
--> 144             data = self.send_command_and_get_string_result(cmd, timeout)
    145             decoded = None
    146             try:

stanford_corenlp_pywrapper-0.1.0-py2.7.egg/stanford_corenlp_pywrapper/sockwrap.pyc in send_command_and_get_string_result(self, cmd, timeout)
    165         # java "long" is 8 bytes, which python struct calls "long long".
    166         # java default byte ordering is big-endian.
--> 167         size_info = struct.unpack('>Q', size_info_str)[0]
    168         data = sock.recv(size_info)
    169         return data

error: unpack requires a string argument of length 8
brendano commented 10 years ago

Hm, are you using a different version of the guava jar or something?

Romainpaulus commented 10 years ago

I am using guava version 13.0.1 as it appears in the README. Here is the full output of the socket initialization, I don't have any other guava version in my classpath:

INFO:StanfordSocketWrap:Starting pipe subprocess, and waiting for signal it's ready, with command:  exec java -Xmx4g -cp stanford_corenlp_pywrapper-0.1.0-py2.7.egg/stanford_corenlp_pywrapper/lib/piperunner.jar:stanford_corenlp_pywrapper-0.1.0-py2.7.egg/stanford_corenlp_pywrapper/lib/guava-13.0.1.jar:stanford_corenlp_pywrapper-0.1.0-py2.7.egg/stanford_corenlp_pywrapper/lib/jackson-all-1.9.11.jar:stanford-corenlp-full-2014-06-16/stanford-corenlp-3.4.jar:/stanford-corenlp-full-2014-06-16/stanford-corenlp-3.4-models.jar:stanford-corenlp-full-2014-06-16/stanford-srparser-2014-07-01-models.jar     corenlp.PipeCommandRunner --server 12340  --mode justparse
[Server] Using mode type: justparse
Adding annotator tokenize
Adding annotator ssplit

Adding annotator pos
Reading POS tagger model from edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger ... ^[[A^[[Adone [0,6 sec].
Adding annotator parse
Loading parser from serialized file edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz ...done [0,4 sec].
[Server] Started socket server on port 12340
INFO:StanfordSocketWrap:Successful ping. The server has started.
INFO:StanfordSocketWrap:Subprocess is ready.
Romainpaulus commented 10 years ago

Well, it seems like upgrading Guava from 13.0.1 to the latest one (18.0) fixed it. That's weird because I didn't have this problem on Ubuntu, only on Mac.

brendano commented 9 years ago

apart from ubuntu vs mac, do you know what java versions were involved with the two settings?

Romainpaulus commented 9 years ago

I don't really remember, sorry. I have java 1.8 on my mac, and I just noticed that it's not the recommended version for Stanford CoreNLP 3.4, so maybe that was the problem.