Decompositore
Il filtro decompounder suddivide le parole composte in singoli componenti sulla base di un dizionario specificato, facilitando la ricerca di parti di termini composti. Questo filtro è particolarmente utile per le lingue che utilizzano frequentemente parole composte, come il tedesco.
Configurazione
Il filtro decompounder è un filtro personalizzato di Milvus. Per usarlo, si deve specificare "type": "decompounder" nella configurazione del filtro, insieme a un parametro word_list che fornisce il dizionario dei componenti delle parole da riconoscere.
analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "decompounder", # Specifies the filter type as decompounder
"word_list": ["dampf", "schiff", "fahrt", "brot", "backen", "automat"],
}],
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter",
Collections.singletonList(
new HashMap<String, Object>() {{
put("type", "decompounder");
put("word_list", Arrays.asList("dampf", "schiff", "fahrt", "brot", "backen", "automat"));
}}
)
);
const analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "decompounder", // Specifies the filter type as decompounder
"word_list": ["dampf", "schiff", "fahrt", "brot", "backen", "automat"],
}],
};
analyzerParams = map[string]any{"tokenizer": "standard",
"filter": []any{map[string]any{
"type": "decompounder",
"word_list": []string{"dampf", "schiff", "fahrt", "brot", "backen", "automat"},
}}}
# restful
analyzerParams='{
"tokenizer": "standard",
"filter": [
{
"type": "decompounder",
"word_list": [
"dampf",
"schiff",
"fahrt",
"brot",
"backen",
"automat"
]
}
]
}'
Il filtro decompounder accetta i seguenti parametri configurabili.
Parametro |
Descrizione |
|---|---|
|
Un elenco di componenti di parole usate per dividere i termini composti. Questo dizionario determina il modo in cui le parole composte vengono scomposte in termini individuali. |
Il filtro decompounder opera sui termini generati dal tokenizer, quindi deve essere usato in combinazione con un tokenizer. Per un elenco dei tokenizer disponibili in Milvus, fare riferimento a Standard Tokenizer e alle sue pagine collaterali.
Dopo aver definito analyzer_params, è possibile applicarlo a un campo VARCHAR quando si definisce uno schema di raccolta. Ciò consente a Milvus di elaborare il testo in quel campo usando l'analizzatore specificato per una tokenizzazione e un filtraggio efficienti. Per i dettagli, si veda l'esempio di utilizzo.
Esempi
Prima di applicare la configurazione dell'analizzatore allo schema di raccolta, verificarne il comportamento con il metodo run_analyzer.
Configurazione dell'analizzatore
analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "decompounder", # Specifies the filter type as decompounder
"word_list": ["dampf", "schiff", "fahrt", "brot", "backen", "automat"],
}],
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter",
Collections.singletonList(
new HashMap<String, Object>() {{
put("type", "decompounder");
put("word_list", Arrays.asList("dampf", "schiff", "fahrt", "brot", "backen", "automat"));
}}
)
);
// javascript
analyzerParams = map[string]any{"tokenizer": "standard",
"filter": []any{map[string]any{
"type": "decompounder",
"word_list": []string{"dampf", "schiff", "fahrt", "brot", "backen", "automat"},
}}}
# restful
analyzerParams='{
"tokenizer": "standard",
"filter": [
{
"type": "decompounder",
"word_list": [
"dampf",
"schiff",
"fahrt",
"brot",
"backen",
"automat"
]
}
]
}'
Verifica con run_analyzerCompatible with Milvus 2.5.11+
from pymilvus import (
MilvusClient,
)
client = MilvusClient(uri="http://localhost:19530")
# Sample text to analyze
sample_text = "dampfschifffahrt brotbackautomat"
# 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("dampfschifffahrt brotbackautomat");
RunAnalyzerResp resp = client.runAnalyzer(RunAnalyzerReq.builder()
.texts(texts)
.analyzerParams(analyzerParams)
.build());
List<RunAnalyzerResp.AnalyzerResult> results = resp.getResults();
// javascript
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{"dampfschifffahrt brotbackautomat"}
option := milvusclient.NewRunAnalyzerOption(texts).
WithAnalyzerParams(string(bs))
result, err := client.RunAnalyzer(ctx, option)
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
Risultato atteso
['dampf', 'schiff', 'fahrt', 'brotbackautomat']