メインコンテンツまでスキップ

Stop

stop フィルターは、トークン化されたテキストから指定されたストップワードを除去し、一般的で意味の薄い単語を取り除くのに役立ちます。ストップワードのリストは、stop_words パラメーターで設定できます。

設定

stop フィルターのストップワードリストは、stop_words パラメーターでインラインに指定するか、stop_words_file パラメーターで登録済みのファイルリソースから指定できます。

インラインのストップワードリスト

stop フィルターをインラインリストで使用するには、フィルター設定に "type": "stop" を指定し、ストップワードのリストを含む stop_words パラメーターを併せて指定します。

python
analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "stop", # Specifies the filter type as stop
"stop_words": ["of", "to", "_english_"], # Defines custom stop words and includes the English stop word list
}],
}

stop フィルターでは、以下のパラメーターを設定できます。

パラメーター

説明

stop_words

トークン化の対象から除外する単語のリストです。デフォルトでは、組み込みの english 辞書が使用されます。次の3つの方法で上書きまたは拡張できます。

  • 組み込み辞書 – 事前定義された辞書を使用するには、以下の言語エイリアスのいずれかを指定します。

    "english""danish""dutch""finnish""french""german""hungarian""italian""norwegian""portuguese""russian""spanish""swedish"

  • カスタムリスト – 独自の用語の配列を渡します(例:["foo", "bar", "baz"])。

  • 混合リスト – エイリアスとカスタム用語を組み合わせます(例:["of", "to", "english"])。

各事前定義辞書の具体的な内容については、stop_words を参照してください。

stop フィルターはトークナイザーが生成した語句に対して動作するため、トークナイザーと組み合わせて使用する必要があります。Zilliz Cloud で利用可能なトークナイザーの一覧については、Standard Tokenizer およびその関連ページを参照してください。

analyzer_params を定義したら、コレクションスキーマの定義時に VARCHAR フィールドへ適用できます。これにより、Zilliz Cloud が指定されたアナライザーを使って当該フィールドのテキストを処理し、効率的なトークン化とフィルタリングを行えます。詳細については、使用例 を参照してください。

アナライザー設定をコレクションスキーマに適用する前に、run_analyzer メソッドを使用して動作を確認してください。

アナライザーの設定

python
analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "stop", # Specifies the filter type as stop
"stop_words": ["of", "to", "_english_"], # Defines custom stop words and includes the English stop word list
}],
}

run_analyzer を使った検証

python
from pymilvus import (
MilvusClient,
)

client = MilvusClient(uri="YOUR_CLUSTER_ENDPOINT")

# Sample text to analyze
sample_text = "The stop filter allows control over common stop words for text processing."

# Run the standard analyzer with the defined configuration
result = client.run_analyzer(sample_text, analyzer_params)
print("Standard analyzer output:", result)

期待される出力

python
['The', 'stop', 'filter', 'allows', 'control', 'over', 'common', 'stop', 'words', 'text', 'processing']