LinderaCompatible with Milvus 2.5.11+
lindera 标记符号生成器执行基于字典的形态分析。对于日语、韩语和汉语等单词不以空格分隔的语言,它是一个不错的选择。
前提条件
要使用lindera 标记符号生成器,需要使用专门编译的 Milvus 版本。所有词典都必须在编译过程中明确启用才能使用。
要启用特定字典,请在编译命令中包含它们:
make milvus TANTIVY_FEATURES=lindera-ipadic,lindera-ko-dic
可用词典的完整列表如下lindera-ipadic,lindera-ipadic-neologd,lindera-unidic,lindera-ko-dic,lindera-cc-cedict 。
例如,启用所有词典:
make milvus TANTIVY_FEATURES=lindera-ipadic,lindera-ipadic-neologd,lindera-unidic,lindera-ko-dic,lindera-cc-cedict
配置
要配置使用lindera 标记符号化器的分析器,请将tokenizer.type 设置为lindera ,并选择dict_kind 的字典。
- Python
- Java
- Go
analyzer_params = {
"tokenizer": {
"type": "lindera",
"dict_kind": "ipadic"
}
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer",
new HashMap<String, Object>() {{
put("type", "lindera");
put("dict_kind", "ipadic");
}});
analyzerParams = map[string]any{"tokenizer": map[string]any{"type": "lindera", "dict_kind": "ipadic"}}
| 参数
|
参数
| | --- | --- | |
type
|
标记符类型。固定为"lindera" 。
| |
dict_kind
|
用于定义词汇的字典。可能的值:
-
ko-dic:韩语 - 韩语形态词典(MeCab Ko-dic) -
ipadic:日语 - 标准形态词典(MeCab IPADIC) -
ipadic-neologd:日语新词词典(扩展)- 包括新词和专有名词(IPADIC NEologd) -
unidic:日语 UniDic(扩展)- 包含详细语言信息的学术标准词典(UniDic) -
cc-cedict:中文普通话(繁体/简体) - 社区维护的汉英词典(CC-CEDICT)**注意:**所有词典必须在 Milvus 编译时启用,才能使用。
|
定义analyzer_params 后,您可以在定义 Collection Schema 时将其应用到VARCHAR 字段。这样,Milvus 就能使用指定的分析器处理该字段中的文本,以实现高效的标记化和过滤。有关详情,请参阅示例使用。
示例
在将分析器配置应用到 Collection 模式之前,请使用run_analyzer 方法验证其行为。
分析器配置
- Python
- Java
- Go
analyzer_params = {
"tokenizer": {
"type": "lindera",
"dict_kind": "ipadic"
}
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer",
new HashMap<String, Object>() {{
put("type", "lindera");
put("dict_kind", "ipadic");
}});
analyzerParams = map[string]any{"tokenizer": map[string]any{"type": "lindera", "dict_kind": "ipadic"}}
使用run_analyzerCompatible with Milvus 2.5.11+
- Python
- Java
- Go
from pymilvus import (
MilvusClient,
)
client = MilvusClient(uri="http://localhost:19530")
# 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)
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.service.vector.request.RunAnalyzerReq;
import io.milvus.v2.service.vector.response.RunAnalyzerResp;
ConnectConfig config = ConnectConfig.builder()
.uri("http://localhost:19530")
.build();
MilvusClientV2 client = new MilvusClientV2(config);
List<String> texts = new ArrayList<>();
texts.add("東京スカイツリーの最寄り駅はとうきょうスカイツリー駅で");
RunAnalyzerResp resp = client.runAnalyzer(RunAnalyzerReq.builder()
.texts(texts)
.analyzerParams(analyzerParams)
.build());
List<RunAnalyzerResp.AnalyzerResult> results = resp.getResults();
import (
"context"
"encoding/json"
"fmt"
"github.com/milvus-io/milvus/client/v2/milvusclient"
)
client, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: "localhost:19530",
APIKey: "root:Milvus",
})
if err != nil {
fmt.Println(err.Error())
// handle error
}
bs, _ := json.Marshal(analyzerParams)
texts := []string{"東京スカイツリーの最寄り駅はとうきょうスカイツリー駅で"}
option := milvusclient.NewRunAnalyzerOption(texts).
WithAnalyzerParams(string(bs))
result, err := client.RunAnalyzer(ctx, option)
if err != nil {
fmt.Println(err.Error())
// handle error
}
预期输出
{tokens: ['東京', 'スカイ', 'ツリー', 'の', '最寄り駅', 'は', 'とう', 'きょう', 'スカイ', 'ツリー', '駅', 'で']}