[nltk-users] calling nltk from Java

1,962 views
Skip to first unread message

Hagai Cibulski

unread,
May 9, 2010, 4:24:27 AM5/9/10
to nltk-...@googlegroups.com

I want to call ntlk functions from a Java project.

I found various approaches like jythonc, PythonInterpreter, RPC, JNI, pipes, etc. and I'm a bit confused.

I tried calling nltk (2.0b8) from Jython (2.5.1), but without luck.

 

Has anyone actually succeeded in calling nltk from Java?

If so, could you please provide instructions?

 

Thanks,

Hagai

 

P.S Efficiency is also a consideration.

 

--
You received this message because you are subscribed to the Google Groups "nltk-users" group.
To post to this group, send email to nltk-...@googlegroups.com.
To unsubscribe from this group, send email to nltk-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nltk-users?hl=en.

Steven Bird

unread,
May 9, 2010, 10:53:53 PM5/9/10
to nltk-...@googlegroups.com
On 9 May 2010 18:24, Hagai Cibulski <hag...@gmail.com> wrote:
> Has anyone actually succeeded in calling nltk from Java?

NLTK is just a Python library. I think you want to be able to invoke
Python from Java, or how to invoke an executable program from Java,
something which is not at all specific to NLTK.

-Steven Bird

Renato Fabbri

unread,
May 9, 2010, 11:01:16 PM5/9/10
to nltk-...@googlegroups.com
Hagai,

I dont know how to do it (i've done similar stuff long ago). But i am
shure people on python-users mailing list or java-users mailing list
or even irc channels will be glad to help :)

best of luck,
rf

2010/5/9 Steven Bird <steve...@gmail.com>:
--
Linux User #479299
skype: fabbri.renato

Hagai Cibulski

unread,
May 10, 2010, 2:13:55 AM5/10/10
to nltk-...@googlegroups.com
Let me clarify my question.

My question is, has anyone actually succeeded in invoking Python code from
Java, that includes NLTK functions.
I know I can call Python functions from Java, i.e. using Jython. I guess the
standard library is supported and everything.
The problem is not Python but NLTK, which seems to have dependencies beyond
what Jython supports. In other words I suspect that NLTK is implementation
dependant on standard (non-Jython) Python.

When I tried to import nltk, using Jython I got the following error:
Traceback (most recent call last):
File "E:\Dev\workspace\NLP\src\Hello.py", line 2, in <module>
import nltk
File "C:\jython2.5.1\Lib\nltk\__init__.py", line 83, in <module>
from collocations import *
File "C:\jython2.5.1\Lib\nltk\collocations.py", line 38, in <module>
from nltk.util import ingrams
File "C:\jython2.5.1\Lib\nltk\util.py", line 12, in <module>
import pydoc
File "C:\jython2.5.1\Lib\pydoc.py", line 1812, in <module>
help = Helper(sys.stdin, sys.stdout)
File "C:\jython2.5.1\Lib\pydoc.py", line 1626, in __init__
execdir = os.path.dirname(sys.executable)
File "C:\jython2.5.1\Lib\ntpath.py", line 209, in dirname
return split(p)[0]
File "C:\jython2.5.1\Lib\ntpath.py", line 166, in split
d, p = splitdrive(p)
File "C:\jython2.5.1\Lib\ntpath.py", line 121, in splitdrive
if p[1:2] == ':':
TypeError: 'NoneType' object is unsubscriptable

Hagai

unread,
May 12, 2010, 11:21:21 AM5/12/10
to nltk-users
After consulting [Jython-users] about my Jython/NLTK problem, it seems
there is an NLTK fix missing from the latest nltk-2.0b8.
Is there a new release soon?
If not, how can I get a fix?

Thanks,
Hagai

P.S. My current Jython/NLTK problem:
When running program that tries to import the NLTK library using
Jython:
E:\Dev\workspace\NLP>C:\jython2.5.1\jython.bat src\Hello.py Traceback
(most recent call last):
File "src\Hello.py", line 1, in <module>
import nltk
...
File "C:\jython2.5.1\Lib\nltk\data.py", line 44, in <module>
from zlib import Z_SYNC_FLUSH
ImportError: cannot import name Z_SYNC_FLUSH

-----Original Message-----
From: alan.ken...@gmail.com [mailto:alan.ken...@gmail.com]
On Behalf Of Alan Kennedy
Sent: Tuesday, May 11, 2010 1:32 PM
To: Hagai Cibulski
Subject: Re: [Jython-users] using NLTK in Jython

[Hagai]
> I'm running the latest NLTK2.0b8.
> Just to make sure, I just downloaded it again from:
> http://nltk.googlecode.com/files/nltk-2.0b8.win32.msi
> and re-installed, but I still get the same error...

I see the problem: The NLTK project has not made a new release since
that bug was fixed: their last release was on February 5th, that bug
was fixed on March 9th.

I suggest you contact the NLTK people and ask them what's the best way
to install the latest code, or perhaps make a new release.

The following *should* work, but I'm not getting into supporting NLTK.

Download revision 8507 of data.py

http://code.google.com/p/nltk/source/detail?spec=svn8553&r=8507

And place it in the following location.

C:\jython2.5.1\Lib\nltk\data.py

HTH,

Alan.


On 10 מאי, 06:01, Renato Fabbri <renato.fab...@gmail.com> wrote:
> Hagai,
>
> I dont know how to do it (i've done similar stuff long ago). But i am
> shure people on python-users mailing list or java-users mailing list
> or even irc channels will be glad to help :)
>
> best of luck,
> rf
>
> 2010/5/9 Steven Bird <stevenbi...@gmail.com>:
>
>
>
>
>
> > On 9 May 2010 18:24, Hagai Cibulski <hag...@gmail.com> wrote:
> >> Has anyone actually succeeded in calling nltk from Java?
>
> > NLTK is just a Python library.  I think you want to be able to invoke
> > Python from Java, or how to invoke an executable program from Java,
> > something which is not at all specific to NLTK.
>
> > -Steven Bird
>
> > --
> > You received this message because you are subscribed to the Google Groups "nltk-users" group.
> > To post to this group, send email to nltk-...@googlegroups.com.
> > To unsubscribe from this group, send email to nltk-users+...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/nltk-users?hl=en.
Reply all
Reply to author
Forward
0 new messages