有熟悉 lucene 的大佬吗, pylucene 中 AttributeSource 类参数问题求助,估计懂 Java 的也可以

2018-10-26 09:52:27 +08:00
 bmos
在看《 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 中使用都对参数报错?
坐等高人解答,谢谢。
1003 次点击
所在节点    Python
1 条回复
Wolfx
2018-10-26 11:15:48 +08:00
itbook.download/topic/e51dbdd1b6ba498badc3d477d777d000 换本书看看呢 .......

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/501283

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX