在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一组新的停用词?
发布于 2013-02-08 05:20:06
在写这个问题的过程中,我发现了这个问题的答案,这个问题是通过pylucene dev列表上的这个线程来实现的:
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)https://stackoverflow.com/questions/14761186
复制相似问题