gpt4 book ai didi

python - PyLucene 的自定义停用词

转载 作者:太空宇宙 更新时间:2023-11-03 19:05:47 25 4
gpt4 key购买 nike

在 PyLucene 中,有一个名为 StopFilter 的过滤器,它根据给定的停用词过滤标记。调用示例如下:

result = StopFilter(True, result, StopAnalyzer.ENGLISH_STOP_WORDS_SET)

看起来替换停止词集的参数应该很容易,但这实际上有点具有挑战性:

>>> StopAnalyzer.ENGLISH_STOP_WORDS_SET

<Set: [but, be, with, such, then, for, no, will, not, are, and, their, if, this, on, into, a, or, there, in, that, they, was, is, it, an, the, as, at, these, by, to, of]>

这是一个Set,无法实现:

>>> Set()

NotImplementedError: ('instantiating java class', <type 'Set'>)

有人建议在其他地方使用 PyLucene 附带的 PythonSet,但事实证明这不是 Set 的实例,并且不能与一个StopFilter

如何为 StopFilter 提供一组新的停用词?

最佳答案

我在通过 pylucene 开发列表上的这个线程编写这个问题的过程中发现了这个问题的答案:

http://mail-archives.apache.org/mod_mbox/lucene-pylucene-dev/201202.mbox/thread

您可以使用自定义列表定义 StopFilter,如下所示:

mystops = HashSet(Arrays.asList(['a','b','c']))
result = StopFilter(True, result, mystops)

关于python - PyLucene 的自定义停用词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14761186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com