跳到主要内容
版本:Cloud 开发指南

Lindera
公测版

lindera 分词器用于根据指定的字典对文本进行词形学分析。该分词器对于诸如中文、日语和韩语等语言来说是个不错的选择。这些语言的共同点是不使用空格定义单词的边界。

📘说明

lindera 分词器在输出的分词结果中会将标点符号作为独立的词元予以保留。例如:"こんにちは!" 的分词结果为 ["こんにちは", "!"]。如果需要在分词结果中去除标点符号词元,需要使用 removepunct 过滤器。

配置

在配置 Analyzer 使用 Lindera 分词器时,需要将 tokenizer.type 设置为 lindera,并将 dict_kind 设置为需要使用的字典。

analyzer_params = {
"tokenizer": {
"type": "lindera",
"dict_kind": "ipadic"
}
}

参数名称

参数描述

type

分词器类型,在使用 Lindera 分词器时,该值为 lindera

dict_kind

作为参考词表的字典。取值范围如下:

在定义了 analyzer_params 后,您可以在定义 Collection Schema 时将其应用到 VARCHAR 类型的字段上。Zilliz Cloud 将会根据 Analyzer 的设置对该字段的内容进行分词和过滤。更多详情,可参考使用示例

使用示例

在完成 Analyzer 配置后,您可以使用 run_analyzer 方法来验证分词效果是否符合预期。

Analyzer 配置

analyzer_params = {
"tokenizer": {
"type": "lindera",
"dict_kind": "ipadic"
}
}

使用 run_analyzer 验证效果

from pymilvus import (
MilvusClient,
)

client = MilvusClient(
uri="YOUR_CLUSTER_ENDPOINT",
token="YOUR_CLUSTER_TOKEN"
)

# Sample text to analyze
sample_text = "東京スカイツリーの最寄り駅はとうきょうスカイツリー駅で"

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

预期结果

{tokens: ['東京', 'スカイ', 'ツリー', 'の', '最寄り駅', 'は', 'とう', 'きょう', 'スカイ', 'ツリー', '駅', 'で']}