lucene-pylucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andi Vajda <>
Subject Re: Passing value during Java object instantiation
Date Wed, 18 Feb 2009 19:33:45 GMT

Sent again with hopefully not mangled formatting:

On Wed, 18 Feb 2009, Charles A. Benson wrote:

> Hello,
>> From my PyLucene code, I want to pass in a value when I instantiate my 
>> StopAnalyzer. In particular, I want to instantiate w/a file containing a 
>> list of stop words.. Everything I have tried so far is either kicked back 
>> by Python or Java. Is there a way to instantiate a Java File object from 
>> within Python/PyLucene ? Is there a more general way to handle this ?

Yes, use the Java File class:

     >>> from lucene import *
     >>> initVM(CLASSPATH)
     <jcc.JCCEnv object at 0x293a0>
     >>> File
     <type 'File'>
     >>> a= StopAnalyzer(File("foo.txt"))
     >>> list(a.tokenStream("foo", StringReader("the foo is bar")))
     [<Token: (the,0,3)>, <Token: (is,8,10)>]
     >>> list(StopAnalyzer().tokenStream("foo", StringReader("the foo is bar")))
     [<Token: (foo,4,7)>, <Token: (bar,11,14)>]


ps: the foo.txt file in the example above contains:

View raw message