アラビア語
arabic アナライザーは、アラビア語テキスト用の組み込みアナライザーです。Zilliz Cloud でアラビア文字の異形を正規化し、分音記号とタトウィールを削除し、アラビア・インド数字を変換し、アラビア語のステミングを適用し、アラビア語のストップワードを削除する必要がある場合に、このアナライザーを使用します。
構成
組み込みアナライザーは、Milvus が提供するアナライザーテンプレートです。組み込みアナライザーを使用するには、analyzer_params の type に定義済みのアナライザー名を設定します。
組み込みのアラビア語アナライザーを使用するには、type に arabic を設定します。
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- CSharp
- cURL
analyzer_params = {
"type": "arabic",
}
import java.util.HashMap;
import java.util.Map;
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("type", "arabic");
analyzerParams := map[string]any{"type": "arabic"}
let analyzer_params = serde_json::json!({
"type": "arabic"
});
nlohmann::json analyzer_params = {
{"type", "arabic"},
};
const analyzer_params = {
"type": "arabic",
};
using System.Collections.Generic;
var analyzerParams = new Dictionary<string, object>
{
["type"] = "arabic"
};
# restful
analyzerParams='{
"type": "arabic"
}'
arabic アナライザーは、次のオプションパラメーターを受け入れます。
| パラメーター | 型 | デフォルト | 説明 |
|---|---|---|---|
stop_words | list[str] | _arabic_ | トークン化から削除する追加のストップワードのリストです。デフォルトでは、arabic アナライザーは組み込みの _arabic_ 辞書を使用します。デフォルトの辞書を確認するには、アラビア語のストップワードリスト を参照してください。このリストは、Apache Lucene のアラビア語ストップワードファイル を基にしています。 |
カスタムストップワードを追加するには、stop_words を含めます。
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- CSharp
- cURL
analyzer_params = {
"type": "arabic",
"stop_words": ["ميلفوس"],
}
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("type", "arabic");
analyzerParams.put("stop_words", Collections.singletonList("ميلفوس"));
analyzerParams = map[string]any{"type": "arabic", "stop_words": []string{"ميلفوس"}}
let analyzer_params = serde_json::json!({
"type": "arabic",
"stop_words": ["ميلفوس"]
});
nlohmann::json analyzer_params = {
{"type", "arabic"},
{"stop_words", {"ميلفوس"}},
};
const analyzer_params = {
"type": "arabic",
"stop_words": ["ميلفوس"],
};
using System.Collections.Generic;
var analyzerParams = new Dictionary<string, object>
{
["type"] = "arabic",
["stop_words"] = new[] { "ميلفوس" }
};
# restful
analyzerParams='{
"type": "arabic",
"stop_words": [
"ميلفوس"
]
}'
Zilliz Cloud は、組み込みの _arabic_ 辞書に加えてカスタムストップワードを適用します。
組み込みの arabic アナライザーは、次のカスタムアナライザー構成と同等です。
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- CSharp
- cURL
analyzer_params = {
"tokenizer": "standard",
"filter": [
"lowercase",
"decimaldigit",
"arabic_normalization",
{
"type": "stemmer",
"language": "arabic",
},
{
"type": "stop",
"stop_words": ["_arabic_"],
},
],
}
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter", Arrays.asList(
"lowercase",
"decimaldigit",
"arabic_normalization",
new HashMap<String, Object>() {{
put("type", "stemmer");
put("language", "arabic");
}},
new HashMap<String, Object>() {{
put("type", "stop");
put("stop_words", Collections.singletonList("_arabic_"));
}}
));
analyzerParams = map[string]any{"tokenizer": "standard",
"filter": []any{"lowercase", "decimaldigit", "arabic_normalization", map[string]any{
"type": "stemmer",
"language": "arabic",
}, map[string]any{
"type": "stop",
"stop_words": []string{"_arabic_"},
}}}
let analyzer_params = serde_json::json!({
"tokenizer": "standard",
"filter": [
"lowercase",
"decimaldigit",
"arabic_normalization",
{"type": "stemmer", "language": "arabic"},
{"type": "stop", "stop_words": ["_arabic_"]}
]
});
nlohmann::json analyzer_params = {
{"tokenizer", "standard"},
{"filter", {"lowercase", "decimaldigit", "arabic_normalization",
{{"type", "stemmer"}, {"language", "arabic"}},
{{"type", "stop"}, {"stop_words", "_arabic_"}}}},
};
const analyzer_params = {
"tokenizer": "standard",
"filter": [
"lowercase",
"decimaldigit",
"arabic_normalization",
{"type": "stemmer", "language": "arabic"},
{"type": "stop", "stop_words": ["_arabic_"]}
],
};
using System.Collections.Generic;
var analyzerParams = new Dictionary<string, object>
{
["tokenizer"] = "standard",
["filter"] = new object[]
{
"lowercase",
"decimaldigit",
"arabic_normalization",
new Dictionary<string, object> { ["type"] = "stemmer", ["language"] = "arabic" },
new Dictionary<string, object> { ["type"] = "stop", ["stop_words"] = new[] { "_arabic_" } }
}
};
# restful
analyzerParams='{
"tokenizer": "standard",
"filter": [
"lowercase",
"decimaldigit",
"arabic_normalization",
{
"type": "stemmer",
"language": "arabic"
},
{
"type": "stop",
"stop_words": "_arabic_"
}
]
}'
このアナライザーは、次の処理手順を適用します。
-
トークン化:
standardトークナイザーを使用して、テキストをトークンに分割します。 -
数字の正規化:
decimaldigitフィルターを使用して、アラビア・インド数字やその他の Unicode 10 進数字を ASCII 数字に変換します。 -
アラビア語の正規化:
arabic_normalizationフィルターを使用して、アレフの異形、ターマルブータ、アレフ・マクスーラを正規化し、ハラカートとタトウィールを削除します。 -
ステミング:
languageをarabicに設定してstemmerフィルターを使用します。 -
ストップワードの削除: 組み込みの
_arabic_辞書でstopフィルターを使用します。
analyzer_params を定義した後、コレクションスキーマを定義する際に、アナライザーを VARCHAR フィールドに適用できます。詳細は、使用例 を参照してください。
例
アナライザー構成をコレクションスキーマに適用する前に、run_analyzer メソッドを使用してその動作を確認してください。
アナライザーの構成
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- CSharp
- cURL
analyzer_params = {
"type": "arabic",
}
import java.util.HashMap;
import java.util.Map;
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("type", "arabic");
analyzerParams = map[string]any{"type": "arabic"}
let analyzer_params = serde_json::json!({
"type": "arabic"
});
nlohmann::json analyzer_params = {
{"type", "arabic"},
};
const analyzer_params = {
"type": "arabic",
};
using System.Collections.Generic;
var analyzerParams = new Dictionary<string, object>
{
["type"] = "arabic"
};
# restful
analyzerParams='{
"type": "arabic"
}'
run_analyzer を使用した検証
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- CSharp
- cURL
from pymilvus import MilvusClient
client = MilvusClient(uri="YOUR_CLUSTER_ENDPOINT")
sample_text = "كِتَابٌ عـــربي ١٢٣"
result = client.run_analyzer(sample_text, analyzer_params)
print(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;
import java.util.ArrayList;
import java.util.List;
ConnectConfig config = ConnectConfig.builder()
.uri("YOUR_CLUSTER_ENDPOINT")
.token("YOUR_CLUSTER_TOKEN")
.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/v3/milvusclient"
)
ctx := context.Background()
client, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: "YOUR_CLUSTER_ENDPOINT",
APIKey: "YOUR_CLUSTER_TOKEN",
})
if err != nil {
fmt.Println(err.Error())
// handle error
}
bs, _ := json.Marshal(analyzerParams)
texts := []string{"كِتَابٌ عـــربي ١٢٣"}
option := milvusclient.NewRunAnalyzerOption(texts...).
WithAnalyzerParamsStr(string(bs))
result, err := client.RunAnalyzer(ctx, option)
if err != nil {
fmt.Println(err.Error())
// handle error
}
use milvus::v2::error::Result;
use milvus::v2::prelude::*;
let config = ConnectConfig::new().uri("YOUR_CLUSTER_ENDPOINT").token("YOUR_CLUSTER_TOKEN");
let client = ClientV2::new(&config).await?;
let texts = ["كِتَابٌ عـــربي ١٢٣".to_string()];
let analyzer_params = serde_json::json!({
"type": "arabic"
});
let result = client.run_analyzer(
RunAnalyzerRequest::builder()
.texts(texts)
.analyzer_params(analyzer_params)
.build()?,
).await?;
println!("{:?}", result.results());
#include "milvus/MilvusClientV2.h"
#include <iostream>
#include <string>
auto client = milvus::MilvusClientV2::Create();
milvus::ConnectParam connect_param{"YOUR_CLUSTER_ENDPOINT", "YOUR_CLUSTER_TOKEN"};
auto status = client->Connect(connect_param);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
std::string text = "كِتَابٌ عـــربي ١٢٣";
auto request = milvus::RunAnalyzerRequest()
.AddText(text)
.WithAnalyzerParams(analyzer_params);
milvus::RunAnalyzerResponse response;
status = client->RunAnalyzer(request, response);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
const res = await client.runAnalyzer({
text: 'كِتَابٌ عـــربي ١٢٣',
analyzer_params: analyzer_params
});
console.log(res);
using Milvus.Client.V2;
using Milvus.Client.V2.Requests.Utility;
using var client = new MilvusClientV2(new ConnectConfig
{
Uri = "YOUR_CLUSTER_ENDPOINT",
ApiKey = "YOUR_CLUSTER_TOKEN"
});
await client.ConnectAsync();
var sampleText = "كِتَابٌ عـــربي ١٢٣";
var result = await client.RunAnalyzerAsync(new RunAnalyzerReq
{
AnalyzerParams = analyzerParams,
Texts = new[] { sampleText }
});
foreach (var r in result.Results)
{
Console.WriteLine(string.Join(", ", r.Tokens.Select(t => t.Token)));
}
# restful
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/common/run_analyzer" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--data '{
"analyzerParams": "{\"type\":\"arabic\"}",
"text": ["كِتَابٌ عـــربي ١٢٣"]
}'
期待される出力
['كتاب', 'عرب', '123']