0

我要在这个问题上失明了,所以我不得不问:

我有 1 条线索:重新排列代码,使错误消息不同:

我收到错误:min_analyzer = SpaceSeparatedTokenizer() | 小写过滤器() | mitt_filter() TypeError: _ call _ () 正好需要 2 个参数(1 个给定)

从这段代码:

import sqlite3
from whoosh.fields import Schema, TEXT, ID
from whoosh.index import create_in
from whoosh.analysis import SpaceSeparatedTokenizer
from whoosh.analysis import StopFilter
from whoosh.analysis import LowercaseFilter

mitt_filter = StopFilter(stoplist=frozenset(['and', 'is', 'it', 'an', 'as', 'at', 'have',     'in', 'yet', 'if', 'from', 'for', 'when', 'by', 'to', 'you', 'be', 'we', 'that', 'may', 'not', 'with', 'a', 'on', 'your', 'this', 'of', 'us', 'will', 'can', 'the', 'or', 'are', u'og', u'i', u'-', u'\\xa0', u'for', u'av', u'til', u'p\\xe5', u'the', u'and', u'as', u'med', u'er', u'en', u'of', u'to', u'har', u'Vi', u'kontakt', u'som', u'\\xe5', u'v\\xe5re', u'vi', u'in', u'oss', u'a', u'det', u'at', u'is', u'\\u2013', u'/', u'\\xbb', u'kan', u'by', u'skal', 'fra', u'ut', u'with', u'be', u'v\\xe5rt', u'mer', u'du', u'\\xa9', u'us', u'on', u'hopp', u'ogs\\xe5', u'Hopp']), minsize=2, maxsize=None, renumber=False)

min_analyzer = SpaceSeparatedTokenizer() | LowercaseFilter() | mitt_filter()

schema = Schema(Hoveddomene=ID, innhold=TEXT (stored=True,     analyzer=min_analyzer(removestops=False, positions=True)), webadresse=ID)

ix = create_in('/Users/Sverdrup/virtualenv-1.6.1/whoosh/whoosh directory/', schema)

如果我像这样重新排列代码:

import sqlite3

from whoosh.fields import Schema, TEXT, ID
from whoosh.index import create_in
from whoosh.analysis import SpaceSeparatedTokenizer
from whoosh.analysis import StopFilter
from whoosh.analysis import LowercaseFilter

min_analyzer = SpaceSeparatedTokenizer() | LowercaseFilter() | StopFilter(stoplist=frozenset(['and', 'is', 'it', 'an', 'as', 'at', 'have', 'in', 'yet', 'if', 'from', 'for', 'when', 'by', 'to', 'you', 'be', 'we', 'that', 'may', 'not', 'with', 'a', 'on', 'your', 'this', 'of', 'us', 'will', 'can', 'the', 'or', 'are', u'og', u'i', u'-', u'\\xa0', u'for', u'av', u'til', u'p\\xe5', u'the', u'and', u'as', u'med', u'er', u'en', u'of', u'to', u'har', u'Vi', u'kontakt', u'som', u'\\xe5', u'v\\xe5re', u'vi', u'in', u'oss', u'a', u'det', u'at', u'is', u'\\u2013', u'/', u'\\xbb', u'kan', u'by', u'skal', 'fra', u'ut', u'with', u'be', u'v\\xe5rt', u'mer', u'du', u'\\xa9', u'us', u'on', u'hopp', u'ogs\\xe5', u'Hopp']), minsize=2, maxsize=None, renumber=False)

schema = Schema(Hoveddomene=ID, innhold=TEXT (stored=True, analyzer=min_analyzer(removestops=False, positions=True)), webadresse=ID)

ix = create_in('/Users/Sverdrup/virtualenv-1.6.1/whoosh/whoosh directory/', schema)

这条线索让我相信是 stopFilter 函数的声明是错误的,但我看不出是什么?

任何帮助将不胜感激!

我收到以下错误: schema = Schema(Hoveddomene=ID, innhold=TEXT (stored=True, analyzer=min_analyzer(removestops=False, position=True)), webadresse=ID) TypeError: _ call _ () 至少需要2 个参数(1 个给定)

4

2 回答 2

1

您对构造函数的analyzer参数不正确。Schem分析器必须是带有该__call__方法的函数或类,因此您的错误是关于call.

http://packages.python.org/Whoosh/analysis.html

于 2011-12-13T19:53:03.127 回答
1

您可能只是想要mitt_filter,否则您正在__call__实例化的对象上执行,这与您的第二个示例不同。

min_analyzer = SpaceSeparatedTokenizer() | LowercaseFilter() | mitt_filter

min_analyzer由于您的第二个示例更正确,因此该错误表明您在将参数发送到Schema构造函数时可能不应该将参数传递给。我基本上analyzer=min_analyzer是说这可能更正确,并且应该在其他地方提供removestopsand参数。positions

于 2011-12-13T19:54:14.437 回答