ncbi-nlp / NegBio

:newspaper: High-performance tool for negation and uncertainty detection in radiology reports
Other
158 stars 42 forks source link

jpype fails when using negbio in flask #27

Closed staplet3 closed 5 years ago

staplet3 commented 5 years ago

Hey guys, I wrapped NegBio in a flask app and had JPype fail within the Stanford Dependencies python library. I had to modify the JPypeBackend.py file to attach the thread to the JVM. I know you don't maintain this source code, but just a heads up. Changes start on line 45:

num_thread = jpype.isThreadAttachedToJVM()
if num_thread is not 1:
     jpype.attachThreadToJVM()

JPypeBackend.py.zip Attached the modified file here

yfpeng commented 5 years ago

Thank you! I have added your comment on the Wiki page.

kaushikacharya commented 5 years ago

I think the proper usage would be

if not jpype.isThreadAttachedToJVM():
            jpype.attachThreadToJVM()

as isThreadAttachedToJVM() returns boolean https://jpype.readthedocs.io/en/devel/api.html#jpype.isThreadAttachedToJVM https://github.com/jpype-project/jpype/blob/master/jpype/_core.py#L211

Otherwise as the following shows, jpype.isThreadAttachedToJVM() is not 1 will always return True irrespective of whether the function returns True or False.

>>> False is not 1
True
>>> True is not 1
True
>>> False is not 0
True
>>> True is not 0
True
yfpeng commented 5 years ago

Thank you! I have updated the wiki.