Chinês

O analisador chinese foi concebido especificamente para lidar com texto chinês, fornecendo segmentação e tokenização eficazes.

Definição

O analisador chinese é composto por:

  • Tokenizador: Usa o tokenizador jieba para segmentar o texto chinês em tokens com base no vocabulário e no contexto. Para obter mais informações, consulte Jieba.

  • Filtro: Utiliza o filtro cnalphanumonly para remover tokens que contenham caracteres não chineses. Para obter mais informações, consulte Cnalphanumonly.

A funcionalidade do analisador chinese é equivalente à seguinte configuração de analisador personalizado:

analyzer_params = {
    "tokenizer": "jieba",
    "filter": ["cnalphanumonly"]
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "jieba");
analyzerParams.put("filter", Collections.singletonList("cnalphanumonly"));
const analyzer_params = {
    "tokenizer": "jieba",
    "filter": ["cnalphanumonly"]
};
analyzerParams = map[string]any{"tokenizer": "jieba", "filter": []any{"cnalphanumonly"}}
# restful
analyzerParams='{
  "tokenizer": "jieba",
  "filter": [
    "cnalphanumonly"
  ]
}'

Configuração

Para aplicar o analisador chinese a um campo, basta definir type para chinese em analyzer_params.

analyzer_params = {
    "type": "chinese",
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("type", "chinese");
const analyzer_params = {
    "type": "chinese",
}
analyzerParams = map[string]any{"type": "chinese"}
# restful
analyzerParams='{
  "type": "chinese"
}'

O analisador chinese não aceita nenhum parâmetro opcional.

Exemplos

Antes de aplicar a configuração do analisador ao seu esquema de coleção, verifique seu comportamento usando o método run_analyzer.

Configuração do analisador

analyzer_params = {
    "type": "chinese",
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("type", "chinese");
// javascript
analyzerParams = map[string]any{"type": "chinese"}
# restful

Verificação usando run_analyzerCompatible with Milvus 2.5.11+

from pymilvus import (
    MilvusClient,
)

client = MilvusClient(uri="http://localhost:19530")

# Sample text to analyze
sample_text = "Milvus 是一个高性能、可扩展的向量数据库!"

# Run the standard analyzer with the defined configuration
result = client.run_analyzer(sample_text, analyzer_params)
print("English 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("Milvus 是一个高性能、可扩展的向量数据库!");

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{"Milvus 是一个高性能、可扩展的向量数据库!"}
option := milvusclient.NewRunAnalyzerOption(texts).
    WithAnalyzerParams(string(bs))

result, err := client.RunAnalyzer(ctx, option)
if err != nil {
    fmt.Println(err.Error())
    // handle error
}
# restful

Saída esperada

Chinese analyzer output: ['Milvus', '是', '一个', '高性', '性能', '高性能', '可', '扩展', '的', '向量', '数据', '据库', '数据库']
Tabela de conteúdos

Try Managed Milvus for Free

Zilliz Cloud is hassle-free, powered by Milvus and 10x faster.

Get Started
Feedback

Esta página foi útil?