473,785 Members | 2,841 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using NLTK in Java

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 '08 #1
5 11176
hu***********@g mail.com 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
Sep 1 '08 #2
On 1 Sep, 11:55, "Diez B. Roggisch" <de...@nospam.w eb.dewrote:
hussainsai...@g mail.com 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 '08 #3
hu***********@g mail.com wrote:
On 1 Sep, 11:55, "Diez B. Roggisch" <de...@nospam.w eb.dewrote:
>hussainsai...@ gmail.com 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
Sep 1 '08 #4
On 1 Sep, 16:21, "Diez B. Roggisch" <de...@nospam.w eb.dewrote:
hussainsai...@g mail.com wrote:
On 1 Sep, 11:55, "Diez B. Roggisch" <de...@nospam.w eb.dewrote:
hussainsai...@g mail.com 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(Stri ng sent)"
brown_a = nltk.corpus.bro wn.tagged_sents (categories='a' )
bigram_tagger = nltk.BigramTagg er(brown_a, cutoff=0)
lst = bigram_tagger.t ag(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 .PythonInterpre ter;
import java.util.Rando m;
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.prin tln(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 \NLPPresentatio n.py", line 0, in main
ImportError: no module named nltk

Your comments are highly appreciated.
Sep 2 '08 #5
On Sep 1, 12:30 pm, hussainsai...@g mail.com:
>in Jython (which is assumed to replace Python),
I don't think so.

Bye,
bearophile
Sep 2 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2632
by: Roberts | last post by:
Hi, I managed to get the Java extension working on php 4.3.10 after following various bits of advice from http://www.thelinuxpimp.com/main/modules.php?op=modload&name=News&file=article&sid=419 and http://uk.php.net/java I have some Java code which runs fine from Java at the command line when specifying certain JVM options -Xmx and -Xms. I am now calling this class from php but can't see any way of pasing the arguments to the JVM created...
1
5681
by: Hyunchan Kim | last post by:
To indent xml file, I made an instance of Transformer from Templates using following. <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xslt" version="1.0"> <xsl:output method="xml" indent="yes" xalan:indent-amount="4"/> <xsl:template match="/">
2
2188
by: dorin | last post by:
I wonder if anyone can help me with a problem using the DOM getElementById method. I am using the Xerces Java 2 library to parse an XML file and create and validate the DOM Document. I am able to access the Node objects using the getElementsByTagName method but whenever I try to us getElementsById the method just returns null. I'm trying to get a project working quickily for a paper and this is slowing me down greatly. Any advice...
1
2109
by: Ulf Nordlund | last post by:
I am using an XML schema to check (validate) the structure of an XML document. But since I cannot check everything I need using a schema, I am thinking of using XSL for more detailed checks (value comparisons etc.) in a second step. Validation using an XML schema is pretty straight forward: I simply define the schema document when parsing the XML to a DOM model in my Java code. Any validation problems comes out as exceptions (which I...
1
9802
by: vykkilynn | last post by:
My homework this week involved using the for statement to create loops that would display triangles. The only output we're allowed to use are forms of the print statements... i.e. print(), println(). I've gotten my code to display the first 2 triangles I need, but I cannot manage to "invert" the triangles for the second part... I need to create code that will make a triangle look like V ********* ******* ***** *** ...
1
1554
by: Sruthi | last post by:
please help me with a code to run user mode linux from java .
0
1090
by: abhilash12 | last post by:
is there any searchengine using with java for find word in ms word file pls help me
2
2505
by: sudankanakavel | last post by:
i need a random prime number generator which will generate prime numbers for given range for eg 22222 to 99999 operating system : windows language : java
3
2662
by: MSK | last post by:
Hi I am a newbie to ASP.NET and VBScript, currently I am designing a page to show all the mapped drives using client-side scripts.. I want to read all the mapped drive details (name and Remote Path) from the registry ("JKEY_CURRENT_USER\Network\") then I want to show this in list box like P: \\machine1\folder1 Z: \\mahcine2\folder2
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10330
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10153
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9952
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.