7.9.3. TokenFilterStem¶
7.9.3.1. 概要¶
TokenFilterStem は、トークナイズされたトークンをステミングします。
TokenFilterStem を使うには、追加のパッケージをインストールする必要があります。追加のパッケージをインストールする方法の詳細については、各OSのインストール方法 を参照して下さい。
7.9.3.2. 構文¶
TokenFilterStem は、省略可能な引数があります。
TokenFilterStem
TokenFilterStem("algorithm", "steming_algorithm")
7.9.3.3. 使い方¶
以下は TokenFilterStem トークンフィルターを使う例です。
実行例:
plugin_register token_filters/stem
# [[0, 1337566253.89858, 0.000355720520019531], true]
table_create Memos TABLE_NO_KEY
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create Memos content COLUMN_SCALAR ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
table_create Terms TABLE_PAT_KEY ShortText \
  --default_tokenizer TokenBigram \
  --normalizer NormalizerAuto \
  --token_filters TokenFilterStem
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create Terms memos_content COLUMN_INDEX|WITH_POSITION Memos content
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table Memos
[
{"content": "I develop Groonga"},
{"content": "I'm developing Groonga"},
{"content": "I developed Groonga"}
]
# [[0, 1337566253.89858, 0.000355720520019531], 3]
select Memos --match_columns content --query "develops"
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         3
#       ],
#       [
#         [
#           "_id",
#           "UInt32"
#         ],
#         [
#           "content",
#           "ShortText"
#         ]
#       ],
#       [
#         1,
#         "I develop Groonga"
#       ],
#       [
#         2,
#         "I'm developing Groonga"
#       ],
#       [
#         3,
#         "I developed Groonga"
#       ]
#     ]
#   ]
# ]
develop も developing も developed も develops も、すべてステミングすると develop になります。そのため、 develops というクエリーで develop も developing も developed も検索できます。
以下のように algorithm オプションを使って、英語以外のステミングアルゴリズムを指定できます。
実行例:
plugin_register token_filters/stem
table_create Memos TABLE_NO_KEY
column_create Memos content COLUMN_SCALAR ShortText
table_create Terms TABLE_PAT_KEY ShortText \
  --default_tokenizer TokenBigram \
  --normalizer NormalizerAuto \
  --token_filters 'TokenFilterStem("algorithm", "french")'
column_create Terms memos_content COLUMN_INDEX|WITH_POSITION Memos content
load --table Memos
[
{"content": "maintenait"},
{"content": "maintenant"}
]
select Memos --match_columns content --query "maintenir"
# [
#   [
#     0,
#     0.0,
#     0.0
#   ],
#   [
#     [
#       [
#         2
#       ],
#       [
#         [
#           "_id",
#           "UInt32"
#         ],
#         [
#           "content",
#           "ShortText"
#         ]
#       ],
#       [
#         1,
#         "maintenait"
#       ],
#       [
#         2,
#         "maintenant"
#       ]
#     ]
#   ]
# ]
7.9.3.4. 引数¶
7.9.3.4.1. 省略可能引数¶
省略可能な引数として algorithm があります。
7.9.3.4.1.1. algorithm¶
ステミングアルゴリズムを指定します。
ステミングアルゴリズムとは、語幹を抽出するもので、各言語用に用意されています。
ステミングアルゴリズムを切り替えることに寄って、各言語の語幹を抽出できます。例えば、フランス語の語幹を抽出したい場合は、 algorithm オプションに French を指定します。
サポートしているステミングアルゴリズムは以下の通りです:
French
Spanish
Portuguese
Italian
Romanian
German
Dutch
Swedish
Norwegian
Danish
Russian
Finnish