합성어 분해기

decompounder 필터는 지정된 사전을 기반으로 복합어를 개별 구성 요소로 분할하여 복합어의 일부를 더 쉽게 검색할 수 있도록 해줍니다. 이 필터는 독일어와 같이 복합어를 자주 사용하는 언어에 특히 유용합니다. 구성 요소 사전은 word_list 파라미터를 통해 인라인으로 제공하거나 word_list_file 파라미터를 통해 등록된 파일 리소스에서 로드할 수 있습니다.

구성

decompounder 필터는 word_list 매개변수를 통해 인라인으로 구성 요소 사전을 받거나 word_list_file 매개변수를 통해 등록된 파일 리소스에서 구성 요소 사전을 받습니다.

인라인 단어 목록

decompounder 필터는 Milvus의 사용자 정의 필터입니다. 이 필터를 사용하려면 필터 구성에 "type": "decompounder" 을 지정하고 인식할 단어 구성 요소의 사전을 제공하는 word_list 파라미터를 함께 지정하세요.

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"
      ]
    }
  ]
}'

decompounder 필터는 다음과 같은 구성 가능한 매개변수를 허용합니다.

파라미터

설명

word_list

복합 용어를 분할하는 데 사용되는 단어 구성 요소 목록입니다. 이 사전은 복합어가 개별 용어로 분해되는 방식을 결정합니다.

decompounder 필터는 토큰화기에 의해 생성된 용어에 대해 작동하므로 토큰화기와 함께 사용해야 합니다. Milvus에서 사용할 수 있는 토큰화기 목록은 표준 토큰화기와 그 형제 페이지를 참조하세요.

analyzer_params 을 정의한 후 컬렉션 스키마를 정의할 때 VARCHAR 필드에 적용할 수 있습니다. 이렇게 하면 Milvus가 지정된 분석기를 사용하여 해당 필드의 텍스트를 처리하여 효율적인 토큰화 및 필터링을 수행할 수 있습니다. 자세한 내용은 사용 예시를 참조하세요.

파일 리소스에서 단어 컴포넌트 로드Compatible with Milvus 3.0.x

대용량 구성 요소 사전, 특히 전체 언어 단어 목록의 경우 구성 요소를 파일에 저장하고 파일을 원격 파일 리소스로 등록한 다음 word_list_file 매개 변수를 통해 필터에서 참조하세요. word_list_file 단독으로 사용하거나 word_list 인라인과 함께 사용할 수 있으며, 둘 다 설정하면 필터가 두 소스를 단일 컴포넌트 목록으로 병합합니다.

파일은 한 줄에 하나의 컴포넌트 단어가 포함된 일반 UTF-8 텍스트입니다. 예를 들어

dampf
schiff
fahrt
brot
backen
automat

Milvus 클러스터가 사용하도록 구성된 개체 저장소에 파일을 업로드한 다음 등록합니다:

from pymilvus import MilvusClient

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

# Register the uploaded file under a name you'll reference from analyzer configs.
client.add_file_resource(
    name="de_components",
    path="file/decompounder.txt",    # full S3 object key, including the rootPath prefix
)

word_list_file 을 통해 필터에서 등록된 리소스를 참조합니다:

analyzer_params = {
    "tokenizer": "standard",
    "filter": [{
        "type": "decompounder",
        "word_list_file": {
            "type": "remote",
            "resource_name": "de_components",
            "file_name": "decompounder.txt",
        },
    }],
}

word_list_file 매개변수는 다음 필드를 가진 개체를 허용합니다:

필드

설명

type

리소스 유형. add_file_resource 을 통해 등록된 파일의 경우 "remote" 을 사용합니다. 자체 호스팅 배포에 사용되는 "local" 변형에 대해서는 파일 리소스 관리를 참조하세요.

resource_name

파일이 add_file_resource 에 등록될 때 사용된 이름입니다.

file_name

등록된 리소스의 객체 저장소 경로 중 파일 이름 부분(예: 리소스가 path="file/decompounder.txt" 에 등록된 경우 "decompounder.txt" )입니다.

예제

분석기 구성을 컬렉션 스키마에 적용하기 전에 run_analyzer 메서드를 사용하여 그 동작을 확인합니다.

분석기 구성

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"
      ]
    }
  ]
}'

다음을 사용하여 확인 run_analyzer

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

예상 출력

['dampf', 'schiff', 'fahrt', 'brotbackautomat']

번역DeepL

관리형 Milvus를 무료로 사용해 보세요

Zilliz Cloud는 번거로움이 없으며, Milvus 기반으로 10배 더 빠릅니다.

시작하기
피드백

이 페이지가 도움이 되었나요?