Using NLTK in Java

Discussion in 'Python' started by hussainsaiger@gmail.com, Sep 1, 2008.

  1. Guest

    I am trying to convert a python module (that contains the use of
    NLTK.Corpus) by jythonc. It is not able to include nltk dependencies
    within the java class it creates. So when i use this class in java, it
    fails to recognize nltk. Can anyone please let me know how should i
    use nltk in python/jython modules so i can use in Java.
     
    , Sep 1, 2008
    #1
    1. Advertising

  2. schrieb:
    > I am trying to convert a python module (that contains the use of
    > NLTK.Corpus) by jythonc. It is not able to include nltk dependencies
    > within the java class it creates. So when i use this class in java, it
    > fails to recognize nltk. Can anyone please let me know how should i
    > use nltk in python/jython modules so i can use in Java.


    If there are any binary dependencies, you are out of luck. It won't
    work. You would need to write a RPC-Server then, with technologies such
    as XMLRPC or CORBA.

    Diez
     
    Diez B. Roggisch, Sep 1, 2008
    #2
    1. Advertising

  3. Guest

    On 1 Sep, 11:55, "Diez B. Roggisch" <> wrote:
    > schrieb:
    >
    > > I am trying to convert a python module (that contains the use of
    > > NLTK.Corpus) by jythonc. It is not able to include nltk dependencies
    > > within the java class it creates. So when i use this class in java, it
    > > fails to recognize nltk. Can anyone please let me know how should i
    > > use nltk in python/jython modules so i can use in Java.

    >
    > If there are any binary dependencies, you are out of luck. It won't
    > work. You would need to write a RPC-Server then, with technologies such
    > as XMLRPC or CORBA.
    >
    > Diez


    So does that mean that Jython does not support nltk uptil now. I ask
    this because when I try to import nltk in Jython (which is assumed to
    replace Python), i get the same error. Its just nltk that I am not
    able to use. The rest of the jython functions and libraries work fine
    within Java.
     
    , Sep 1, 2008
    #3
  4. wrote:

    > On 1 Sep, 11:55, "Diez B. Roggisch" <> wrote:
    >> schrieb:
    >>
    >> > I am trying to convert a python module (that contains the use of
    >> > NLTK.Corpus) by jythonc. It is not able to include nltk dependencies
    >> > within the java class it creates. So when i use this class in java, it
    >> > fails to recognize nltk. Can anyone please let me know how should i
    >> > use nltk in python/jython modules so i can use in Java.

    >>
    >> If there are any binary dependencies, you are out of luck. It won't
    >> work. You would need to write a RPC-Server then, with technologies such
    >> as XMLRPC or CORBA.
    >>
    >> Diez

    >
    > So does that mean that Jython does not support nltk uptil now. I ask
    > this because when I try to import nltk in Jython (which is assumed to
    > replace Python), i get the same error. Its just nltk that I am not
    > able to use. The rest of the jython functions and libraries work fine
    > within Java.


    I don't know for sure - how about you post the error-message? Otherwise we
    can't assess the problem.

    Diez
     
    Diez B. Roggisch, Sep 1, 2008
    #4
  5. Guest

    On 1 Sep, 16:21, "Diez B. Roggisch" <> wrote:
    > wrote:
    > > On 1 Sep, 11:55, "Diez B. Roggisch" <> wrote:
    > >> schrieb:

    >
    > >> > I am trying to convert a python module (that contains the use of
    > >> > NLTK.Corpus) by jythonc. It is not able to include nltk dependencies
    > >> > within the java class it creates. So when i use this class in java, it
    > >> > fails to recognize nltk. Can anyone please let me know how should i
    > >> > use nltk in python/jython modules so i can use in Java.

    >
    > >> If there are any binary dependencies, you are out of luck. It won't
    > >> work. You would need to write a RPC-Server then, with technologies such
    > >> as XMLRPC or CORBA.

    >
    > >> Diez

    >
    > > So does that mean that Jython does not support nltk uptil now. I ask
    > > this because when I try to import nltk in Jython (which is assumed to
    > > replace Python), i get the same error. Its just nltk that I am not
    > > able to use. The rest of the jython functions and libraries work fine
    > > within Java.

    >
    > I don't know for sure - how about you post the error-message? Otherwise we
    > can't assess the problem.
    >
    > Diez- Hide quoted text -
    >
    > - Show quoted text -


    Hi,

    What i did was create a python file as:

    import nltk
    from java.util import Random

    class NLPPresentation(Random):
    def nextDouble(self):
    return 1
    def TagByBrown(self,sent):
    "@sig public String[] TagByBrown(String sent)"
    brown_a = nltk.corpus.brown.tagged_sents(categories='a')
    bigram_tagger = nltk.BigramTagger(brown_a, cutoff=0)
    lst = bigram_tagger.tag(sent.split())
    return lst

    I processed the following code through jythonc compiler to form a JAR
    file. I then imported this jar
    file into java ide (Java Builder). I then wrote the following program
    in java to access this python class:

    import org.python.core.PyException;
    import org.python.core.PyInteger;
    import org.python.core.PyObject;
    import org.python.util.PythonInterpreter;
    import java.util.Random;
    import org.nltk.*;
    import org.nltk.mallet.*;
    public class SimpleEmbedded extends NLPPresentation{
    public static void main(String[] args) throws PyException {
    SimpleEmbedded so = new SimpleEmbedded();
    String s = "he is a boy";
    so.Call(s);
    }
    public void Call(String s)
    {
    String[] arr = TagByBrown(s);
    System.out.println(arr[1]);
    }
    }

    When i compile the above java code, i get the following error:

    Exception in thread "main" Traceback (innermost last):
    File "C:\jython2.2.1\NLPPresentation.py", line 0, in main
    ImportError: no module named nltk

    Your comments are highly appreciated.
     
    , Sep 2, 2008
    #5
  6. Guest

    On Sep 1, 12:30 pm, :
    >in Jython (which is assumed to replace Python),


    I don't think so.

    Bye,
    bearophile
     
    , Sep 2, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. j_pennington_moore

    newbie NLTK question

    j_pennington_moore, Jul 20, 2004, in forum: Python
    Replies:
    0
    Views:
    323
    j_pennington_moore
    Jul 20, 2004
  2. Replies:
    1
    Views:
    295
    Fredrik Lundh
    Dec 22, 2004
  3. Tony Meyer
    Replies:
    6
    Views:
    1,394
  4. Sohail
    Replies:
    0
    Views:
    833
    Sohail
    Aug 12, 2010
  5. Using Raw Data in NLTK

    , Sep 7, 2012, in forum: Python
    Replies:
    1
    Views:
    202
    Terry Reedy
    Sep 7, 2012
Loading...

Share This Page