Python中pylucene的AttributeSource类参数问题求助,熟悉lucene或Java的大佬请进

在看《 Lucene In Action 》一书,在第四章同义词搜索遇到了问题。
书中源码 SynonymFilter.java 有一段
private AttributeSource.State current;

restoreState(current);

current = captureState();
查看了 java 源码,State 是内部类。restoreState,captureState 都是 AttributeSource 中的函数:
public final void restoreState(State state)
public final State captureState()
没有找到 pylucene 中如何使用,尝试了一下:
current = AttributeSource.State()
AttributeSource.restoreState(current)
current = AttributeSource.captureState()
但是报错:
>>> AttributeSource.restoreState(current)
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
TypeError: descriptor ‘restoreState’ requires a ‘AttributeSource’ object but received a ‘AttributeSource$State’

>>> AttributeSource.captureState()
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
TypeError: descriptor ‘captureState’ of ‘AttributeSource’ object needs an argument

>>> AttributeSource.captureState(current)
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
TypeError: descriptor ‘captureState’ requires a ‘AttributeSource’ object but received a 'At tributeSource$State’

在 stackoverflow 中只找到这样的用法 current=AttributeSource.State,显然类型更不对。
其实对这个类的用处还没有搞明白,但是对这个参数报错真是疑惑。java 中分别是 State 类型和不需要参数,为什么在 pylucene 中使用都对参数报错?
坐等高人解答,谢谢。
Python中pylucene的AttributeSource类参数问题求助,熟悉lucene或Java的大佬请进


2 回复

我无法理解你的问题。


itbook.download/topic/e51dbdd1b6ba498badc3d477d777d000 换本书看看呢 …

回到顶部