You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pylucene-dev@lucene.apache.org by "Charles A. Benson" <ca...@u.washington.edu> on 2009/02/18 16:25:59 UTC
Passing value during Java object instantiation
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 ?
Thanks
Chuck
Re: Passing value during Java object instantiation
Posted by Andi Vajda <va...@apache.org>.
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)>]
>>>
Andi..
ps: the foo.txt file in the example above contains:
foo
bar
baz
Re: Passing value during Java object instantiation
Posted by Andi Vajda <va...@apache.org>.
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