إيقاف

يقوم مرشح " stop " بإزالة الكلمات الممنوعة المحددة من النص الذي تم تقسيمه إلى رموز، مما يساعد على التخلص من الكلمات الشائعة والأقل دلالة. يمكنك تكوين قائمة الكلمات الممنوعة باستخدام المعلمة stop_words.

التكوين

يقبل مرشح " stop " قائمة كلمات التوقف الخاصة به إما مضمنة عبر المعلمة stop_words أو من مورد ملف مسجل عبر المعلمة stop_words_file.

قائمة الكلمات الممنوعة المضمنة

لاستخدام مرشح stop مع قائمة مضمنة، حدد "type": "stop" في تكوين المرشح، إلى جانب المعلمة stop_words التي توفر قائمة الكلمات الممنوعة.

analyzer_params = {
    "tokenizer": "standard",
    "filter":[{
        "type": "stop", # Specifies the filter type as stop
        "stop_words": ["of", "to", "_english_"], # Defines custom stop words and includes the English stop word list
    }],
}
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",
        Collections.singletonList(
                new HashMap<String, Object>() {{
                    put("type", "stop");
                    put("stop_words", Arrays.asList("of", "to", "_english_"));
                }}
        )
);
analyzerParams := map[string]any{"tokenizer": "standard",
    "filter": []any{map[string]any{
        "type":       "stop",
        "stop_words": []string{"of", "to", "_english_"},
    }}}
use milvus::v2::prelude::*;
use serde_json::json;

let analyzer_params = json!({
    "tokenizer": "standard",
    "filter": [{
        "type": "stop",
        "stop_words": ["of", "to", "_english_"]
    }]
});
nlohmann::json analyzer_params = {
    {"tokenizer", "standard"},
    {"filter", {
        {{"type", "stop"}, {"stop_words", {"of", "to", "_english_"}}}
    }}
};
const analyzer_params = {
    tokenizer: "standard",
    filter: [{
        type: "stop",  // Specifies the filter type as stop
        stop_words: ["of", "to", "_english_"],  // Custom stop words + built-in English list
    }],
};
using System.Collections.Generic;

Dictionary<string, object> analyzerParams = new()
{
    ["tokenizer"] = "standard",
    ["filter"] = new List<object>
    {
        new Dictionary<string, object>
        {
            ["type"] = "stop", // Specifies the filter type as stop
            ["stop_words"] = new List<object> { "of", "to", "_english_" } // Defines custom stop words and includes the English stop word list
        }
    }
};
# restful
analyzerParams='{
  "tokenizer": "standard",
  "filter": [
    {
      "type": "stop",
      "stop_words": [
        "of",
        "to",
        "_english_"
      ]
    }
  ]
}'

يقبل مرشح stop المعلمات القابلة للتكوين التالية.

المعلمة

الوصف

stop_words

قائمة بالكلمات المراد إزالتها من عملية التقطيع إلى رموز. بشكل افتراضي، يستخدم المرشح قاموس " _english_ " المدمج. يمكنك تجاوزه أو توسيعه بثلاث طرق:

  • القواميس المدمجة – أدخل أحد أسماء اللغات المستعارة التالية لاستخدام قاموس محدد مسبقًا:

    "_arabic_"، "_english_" ، "_danish_" ، "_dutch_" ، "_finnish_" ، "_french_" ، "_german_" ، "_hungarian_" ، "_italian_" ، "_norwegian_" ، "_portuguese_" ، "_russian_" ، "_spanish_" ، "_swedish_" ، "_thai_"

  • قائمة مخصصة – قم بتمرير مصفوفة من المصطلحات الخاصة بك، على سبيل المثال ["foo", "bar", "baz"].

  • قائمة مختلطة – اجمع بين الأسماء المستعارة والمصطلحات المخصصة، على سبيل المثال: ["of", "to", "_english_"].

    للحصول على تفاصيل حول المحتوى الدقيق لكل قاموس محدد مسبقًا، راجع stop_words. لفحص القاموس العربي أو التايلاندي، راجع قائمة الكلمات الممنوعة العربية أو قائمة الكلمات الممنوعة التايلاندية.

يعمل مرشح stop على المصطلحات التي تم إنشاؤها بواسطة أداة التقطيع، لذا يجب استخدامه بالاقتران مع أداة التقطيع. للحصول على قائمة بأدوات التقطيع المتاحة في Milvus، راجع أداة التقطيع القياسية والصفحات المرتبطة بها.

بعد تعريف «الكلمات الممنوعة» ( analyzer_params)، يمكنك تطبيقها على حقل «المصطلح» ( VARCHAR ) عند تعريف مخطط المجموعة. وهذا يسمح لـ Milvus بمعالجة النص الموجود في هذا الحقل باستخدام أداة التحليل المحددة من أجل التقطيع والتصفية بكفاءة. لمزيد من التفاصيل، راجع «مثال على الاستخدام».

تحميل الكلمات الممنوعة من مورد ملفCompatible with Milvus 3.0.x

بالنسبة لقوائم كلمات الإيقاف المخصصة الكبيرة — مثل القوائم الخاصة بلغة معينة، أو مفردات المجال، أو القوائم التي ترغب في مشاركتها عبر العديد من المجموعات — قم بتخزين الكلمات في ملف وتسجيل الملف كمورد ملف بعيد، ثم قم بالإشارة إليه من المرشح عبر المعلمة stop_words_file. يمكنك استخدام المعلمة « stop_words_file » بمفردها أو جنبًا إلى جنب مع المعلمة المضمنة « stop_words »؛ وعند تعيينهما معًا، يقوم المرشح بدمج المصدرين في قائمة كلمات توقف واحدة.

الملف عبارة عن نص عادي بتنسيق UTF‑8 يحتوي على كلمة محظورة واحدة في كل سطر. على سبيل المثال:

the
of
for

قم بتحميل الملف إلى مخزن الكائنات الذي تم تكوين مجموعة 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="en_stop_words",
    path="file/stop_words.txt",    # full S3 object key, including the rootPath prefix
)

أشر إلى المورد المسجل في المرشح عبر stop_words_file:

analyzer_params = {
    "tokenizer": "standard",
    "filter": [{
        "type": "stop",
        "stop_words_file": {
            "type": "remote",
            "resource_name": "en_stop_words",
            "file_name": "stop_words.txt",
        },
    }],
}

يقبل المعلمة stop_words_file كائنًا يحتوي على الحقول التالية:

الحقل

الوصف

type

نوع المورد. استخدم "remote" لملف مسجل عبر add_file_resource. بالنسبة لمتغير "local" المستخدم في عمليات النشر ذاتية الاستضافة، راجع إدارة موارد الملفات.

resource_name

الاسم المستخدم عند تسجيل الملف باستخدام add_file_resource.

file_name

جزء اسم الملف من مسار مخزن الكائنات للمورد المسجل (على سبيل المثال، "stop_words.txt" إذا تم تسجيل المورد عبر path="file/stop_words.txt").

أمثلة

قبل تطبيق تكوين المحلل على مخطط المجموعة الخاص بك، تحقق من سلوكه باستخدام طريقة run_analyzer.

تكوين المحلل

analyzer_params = {
    "tokenizer": "standard",
    "filter":[{
        "type": "stop", # Specifies the filter type as stop
        "stop_words": ["of", "to", "_english_"], # Defines custom stop words and includes the English stop word list
    }],
}
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",
        Collections.singletonList(
                new HashMap<String, Object>() {{
                    put("type", "stop");
                    put("stop_words", Arrays.asList("of", "to", "_english_"));
                }}
        )
);
analyzerParams := map[string]any{"tokenizer": "standard",
    "filter": []any{map[string]any{
        "type":       "stop",
        "stop_words": []string{"of", "to", "_english_"},
    }}}
use milvus::v2::prelude::*;
use serde_json::json;

let analyzer_params = json!({
    "tokenizer": "standard",
    "filter": [{
        "type": "stop",
        "stop_words": ["of", "to", "_english_"]
    }]
});
nlohmann::json analyzer_params = {
    {"tokenizer", "standard"},
    {"filter", {
        {{"type", "stop"}, {"stop_words", {"of", "to", "_english_"}}}
    }}
};
const analyzer_params = {
    tokenizer: "standard",
    filter: [{
        type: "stop",  // Specifies the filter type as stop
        stop_words: ["of", "to", "_english_"],  // Custom stop words + built-in English list
    }],
};
using System.Collections.Generic;

Dictionary<string, object> analyzerParams = new()
{
    ["tokenizer"] = "standard",
    ["filter"] = new List<object>
    {
        new Dictionary<string, object>
        {
            ["type"] = "stop", // Specifies the filter type as stop
            ["stop_words"] = new List<object> { "of", "to", "_english_" } // Defines custom stop words and includes the English stop word list
        }
    }
};
# restful
analyzerParams='{
  "tokenizer": "standard",
  "filter": [
    {
      "type": "stop",
      "stop_words": [
        "of",
        "to",
        "_english_"
      ]
    }
  ]
}'

التحقق باستخدام run_analyzer

from pymilvus import (
    MilvusClient,
)

client = MilvusClient(uri="http://localhost:19530", token="root:Milvus")

# Sample text to analyze
sample_text = "The stop filter allows control over common stop words for text processing."

# Run the analyzer with the defined configuration
result = client.run_analyzer(sample_text, analyzer_params)
print("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;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

ConnectConfig config = ConnectConfig.builder()
        .uri("http://localhost:19530")
        .token("root:Milvus")
        .build();
MilvusClientV2 client = new MilvusClientV2(config);

List<String> texts = new ArrayList<>();
texts.add("The stop filter allows control over common stop words for text processing.");

RunAnalyzerResp resp = client.runAnalyzer(RunAnalyzerReq.builder()
        .texts(texts)
        .analyzerParams(analyzerParams)
        .build());
List<RunAnalyzerResp.AnalyzerResult> results = resp.getResults();
import (
    "context"
    "fmt"

    "github.com/milvus-io/milvus/client/v3/milvusclient"
)

ctx := context.Background()

client, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
    Address: "http://localhost:19530",
    APIKey:  "root:Milvus",
})
if err != nil {
    fmt.Println(err.Error())
    // handle error
}

texts := []string{"The stop filter allows control over common stop words for text processing."}
option := milvusclient.NewRunAnalyzerOption(texts...).
    WithAnalyzerParams(analyzerParams)

result, err := client.RunAnalyzer(ctx, option)
if err != nil {
    fmt.Println(err.Error())
    // handle error
}
fmt.Println(result)
use milvus::v2::prelude::*;
use serde_json::json;

let config = ConnectConfig::new().uri("http://localhost:19530").token("root:Milvus");
let client = ClientV2::new(&config).await?;

let analyzer_params = json!({
    "tokenizer": "standard",
    "filter": [{
        "type": "stop",
        "stop_words": ["of", "to", "_english_"]
    }]
});
let result = client
    .run_analyzer(
        RunAnalyzerRequest::builder()
            .texts(vec!["The stop filter allows control over common stop words for text processing."])
            .analyzer_params(analyzer_params)
            .build()?,
    )
    .await?;
#include "milvus/MilvusClientV2.h"
#include <iostream>
#include <string>

auto client = milvus::MilvusClientV2::Create();

milvus::ConnectParam connect_param{"http://localhost:19530", "root:Milvus"};
auto status = client->Connect(connect_param);
if (!status.IsOk()) {
    std::cout << status.Message() << std::endl;
}

std::string text = "The stop filter allows control over common stop words for text processing.";
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;
}
import { MilvusClient } from "@zilliz/milvus2-sdk-node";

const client = new MilvusClient({
    address: "http://localhost:19530",
    token: "root:Milvus",
});

const sample_text = "The stop filter allows control over common stop words for text processing.";

// Run the analyzer with the defined configuration
const result = await client.runAnalyzer({
    text: sample_text,
    analyzer_params,
});
console.log("Analyzer output:", result);
using Milvus.Client.V2;
using Milvus.Client.V2.Requests.Utility;
using Milvus.Client.V2.Responses.Utility;
using Milvus.Client.V2.Types;

MilvusClientV2 client = new(new ConnectConfig
{
    Uri = "http://localhost:19530",
    ApiKey = "root:Milvus"
});

// Sample text to analyze
string sampleText = "The stop filter allows control over common stop words for text processing.";

// Run the analyzer with the defined configuration
RunAnalyzerResp result = await client.RunAnalyzerAsync(new RunAnalyzerReq
{
    AnalyzerParams = analyzerParams,
    Texts = [sampleText]
});

foreach (AnalyzerToken t in result.Results.SelectMany(r => r.Tokens))
{
    Console.WriteLine(t.Token);
}
# restful
curl --request POST \
     --url "http://localhost:19530/v2/vectordb/common/run_analyzer" \
     --header "Authorization: Bearer root:Milvus" \
     --header "Content-Type: application/json" \
     -d '{
        "text": ["The stop filter allows control over common stop words for text processing."],
        "analyzerParams": "{\"tokenizer\": \"standard\", \"filter\": [{\"type\": \"stop\", \"stop_words\": [\"of\", \"to\", \"_english_\"]}]}"
     }'

الناتج المتوقع

['The', 'stop', 'filter', 'allows', 'control', 'over', 'common', 'stop', 'words', 'text', 'processing']

ترجمة بواسطةDeepL

جرب Managed Milvus مجاناً

Zilliz Cloud خالي من المتاعب، ويعمل بواسطة Milvus ويعمل بسرعة 10 أضعاف.

ابدأ
التعليقات

هل كانت هذه الصفحة مفيدة؟