lucene-pylucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andi Vajda <va...@apache.org>
Subject Re: Passing value during Java object instantiation
Date Wed, 18 Feb 2009 19:20:46 GMT

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)>]

Andi..

ps: the foo.txt in the example above contains:
foo
bar
baz

Mime
View raw message