V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
bmos
V2EX  ›  Python

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

  •  
  •   bmos · 2018-10-26 09:52:27 +08:00 · 1003 次点击
    这是一个创建于 2006 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在看《 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 中使用都对参数报错?
    坐等高人解答,谢谢。
    1 条回复    2018-10-26 11:15:48 +08:00
    Wolfx
        1
    Wolfx  
       2018-10-26 11:15:48 +08:00
    itbook.download/topic/e51dbdd1b6ba498badc3d477d777d000 换本书看看呢 .......
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   976 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 21:57 · PVG 05:57 · LAX 14:57 · JFK 17:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.