アラビア語の正規化
arabic_normalization フィルターは、アラビア語テキスト用の組み込みトークンフィルターです。アラビア語固有の文字異形を正規化し、テキスト分析時に同等のアラビア語用語が異なるように見える可能性がある省略可能な記号を削除します。
設定
Notes
アラビア語テキストでは、ほとんどの場合、組み込みの アラビア語アナライザー を使用してください。組み込みアナライザーには、このフィルターと、標準トークン化、小文字化、10 進数字の正規化、アラビア語のステミング、アラビア語のストップワード削除が含まれています。カスタムアナライザーパイプラインを構築する必要がある場合にのみ、arabic_normalization を直接使用してください。
カスタムアナライザーで arabic_normalization フィルターを使用するには、analyzer_params の filter セクションに追加します。
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- CSharp
- cURL
python
analyzer_params = {
"tokenizer": "standard",
"filter": ["arabic_normalization"],
}
java
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", Collections.singletonList("arabic_normalization"));
go
analyzerParams := map[string]any{"tokenizer": "standard", "filter": []any{"arabic_normalization"}}
rust
let analyzer_params = serde_json::json!({
"tokenizer": "standard",
"filter": ["arabic_normalization"]
});
c++
nlohmann::json analyzer_params = {
{"tokenizer", "standard"},
{"filter", {"arabic_normalization"}},
};
javascript
const analyzer_params = {
"tokenizer": "standard",
"filter": ["arabic_normalization"],
};
csharp
using Milvus.Client.V2;
using Milvus.Client.V2.Requests.Collection;
using Milvus.Client.V2.Requests.Dml;
using Milvus.Client.V2.Requests.Dql;
using Milvus.Client.V2.Requests.Index;
using Milvus.Client.V2.Types;
var analyzerParams = new Dictionary<string, object>
{
["tokenizer"] = "standard",
["filter"] = new[] { "arabic_normalization" },
};
bash
# restful
analyzerParams='{
"tokenizer": "standard",
"filter": [
"arabic_normalization"
]
}'
arabic_normalization フィルターには設定可能なパラメーターはありません。
このフィルターは次の変換を適用します。
| 変換 | 変換前 | 変換後 |
|---|---|---|
| ハムザ + アリフの異形 | آ, أ, إ | ا |
| ターマルブータ | ة | ه |
| アリフ・マクスーラ | ى | ي |
| ハラカート | U+064B から U+065F まで | 削除 |
| タトウィール / カシーダ | ـ | 削除 |
このフィルターは、トークナイザーによって生成されたトークンに対して動作します。上記の設定は意図的にカスタムアナライザーの例として示したものであり、アラビア語処理パイプライン全体を含むものではありません。
例
アナライザーの設定をコレクションスキーマに適用する前に、run_analyzer メソッドを使用して動作を検証してください。
アナライザーの設定
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- CSharp
- cURL
python
analyzer_params = {
"tokenizer": "standard",
"filter": ["arabic_normalization"],
}
java
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", Collections.singletonList("arabic_normalization"));
go
analyzerParams = map[string]any{"tokenizer": "standard", "filter": []any{"arabic_normalization"}}
rust
let analyzer_params = serde_json::json!({
"tokenizer": "standard",
"filter": ["arabic_normalization"]
});
c++
nlohmann::json analyzer_params = {
{"tokenizer", "standard"},
{"filter", {"arabic_normalization"}},
};
javascript
const analyzer_params = {
"tokenizer": "standard",
"filter": ["arabic_normalization"],
};
csharp
using Milvus.Client.V2;
using Milvus.Client.V2.Requests.Collection;
using Milvus.Client.V2.Requests.Dml;
using Milvus.Client.V2.Requests.Dql;
using Milvus.Client.V2.Requests.Index;
using Milvus.Client.V2.Types;
var analyzerParams = new Dictionary<string, object>
{
["tokenizer"] = "standard",
["filter"] = new[] { "arabic_normalization" },
};
bash
# restful
analyzerParams='{
"tokenizer": "standard",
"filter": [
"arabic_normalization"
]
}'
run_analyzer を使用した検証
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- CSharp
- cURL
python
from pymilvus import MilvusClient
client = MilvusClient(uri="YOUR_CLUSTER_ENDPOINT")
sample_text = "آدم أحمد إسلام مدرسة كبرى كِتَابٌ عـــربي"
result = client.run_analyzer(sample_text, analyzer_params)
print(result)
java
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();
go
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
}
rust
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!({
"tokenizer": "standard",
"filter": ["arabic_normalization"]
});
let result = client.run_analyzer(
RunAnalyzerRequest::builder()
.texts(texts)
.analyzer_params(analyzer_params)
.build()?,
).await?;
println!("{:?}", result.results());
c++
#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;
}
javascript
import { MilvusClient } from "@zilliz/milvus2-sdk-node";
const client = new MilvusClient({
address: "YOUR_CLUSTER_ENDPOINT",
});
const res = await client.runAnalyzer({
text: 'آدم أحمد إسلام مدرسة كبرى كِتَابٌ عـــربي',
analyzer_params: analyzer_params
});
console.log(res);
csharp
using Milvus.Client.V2;
using Milvus.Client.V2.Requests.Collection;
using Milvus.Client.V2.Requests.Dml;
using Milvus.Client.V2.Requests.Dql;
using Milvus.Client.V2.Requests.Index;
using Milvus.Client.V2.Types;
using Milvus.Client.V2.Requests.Utility;
var client = new MilvusClientV2(new ConnectConfig
{
Uri = "YOUR_CLUSTER_ENDPOINT",
Username = "root",
Password = "Milvus"
});
string sampleText = "آدم أحمد إسلام مدرسة كبرى كِتَابٌ عـــربي";
var result = await client.RunAnalyzerAsync(new RunAnalyzerReq
{
AnalyzerParams = analyzerParams,
Texts = new[] { sampleText }
});
Console.WriteLine(result.Results?.SelectMany(r => r.Tokens.Select(t => t.Token)));
bash
# restful
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/common/run_analyzer" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--data '{
"text": ["آدم أحمد إسلام مدرسة كبرى كِتَابٌ عـــربي"],
"analyzerParams": "{\"tokenizer\":\"standard\",\"filter\":[\"arabic_normalization\"]}"
}'
期待される出力
plaintext
['ادم', 'احمد', 'اسلام', 'مدرسه', 'كبري', 'كتاب', 'عربي']