推荐学习书目
› 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 · Oct 26, 2018 · 1687 views
    This topic created in 2894 days ago, the information mentioned may be changed or developed.
    在看《 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 replies  •  2018-10-26 11:15:48 +08:00
    Wolfx
        1
    Wolfx  
       Oct 26, 2018
    itbook.download/topic/e51dbdd1b6ba498badc3d477d777d000 换本书看看呢 .......
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3187 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 10:42 · PVG 18:42 · LAX 03:42 · JFK 06:42
    ♥ Do have faith in what you're doing.