dmcc / PyStanfordDependencies

Python interface for converting Penn Treebank trees to Stanford Dependencies and Universal Depenencies
https://pypi.python.org/pypi/PyStanfordDependencies
68 stars 17 forks source link

JPypeBackend initialization returns AttributeError for CoreNLP >= 3.5.0 #9

Closed Tiepies closed 9 years ago

Tiepies commented 9 years ago

When initializing a JPypeBackend object, the puncFilter attribute is set to trees.PennTreebankLanguagePack().punctuationWordRejectFilter().accept (line 52 in JPypeBackend.py). However, for CoreNLP versions >= 3.5.0, this results in an AttributeError: 'edu.stanford.nlp.util.Filters$NegatedFilter' object has no attribute 'accept'.

The solution is to change the line to change line 52 to self.puncFilter = trees.PennTreebankLanguagePack().punctuationWordRejectFilter().test. That breaks compatibility with CoreNLP versions < 3.5.0. I worked out a hacky version check using java.util.jar.JarInputStream(stream).getManifest(). If you like to retain compatibility with older CoreNLP versions, I could fork and send a pull request. Otherwise it is a quick fix.

dmcc commented 9 years ago

Thanks for the report!

I've committed a potential fix with a different sort of hack. I tested JPypeBackend against CoreNLP versions 1.3.5, 3.3.0, 3.5.0, and 3.5.1 -- please reopen if it still doesn't work for you.