文字分割認知技能

文字分割技能會將文字分割成文字區塊。 您可以指定您要將文字分成句子或特定長度的頁面。 如果其他技能下游有最大文字長度需求,此技能特別有用。

注意

此技能未系結至 Azure AI 服務。 這是不可計費的,而且沒有 Azure AI 服務的主要需求。

@odata.type

Microsoft.Skills.Text.SplitSkill

技能參數

參數會區分大小寫。

參數名稱 描述
textSplitMode pagessentences。 頁面具有可設定的最大長度,但技能會嘗試避免截斷句子,因此實際長度可能較小。 句子是一個字串,其結尾為句尾標點符號,例如句號、問號或驚嘆號,假設語言具有句子結尾標點符號。
maximumPageLength 只有在 設定為 pages時才textSplitMode適用。 此參數會參考 以字元為單位的最大頁面長度,如 所 String.Length測量。 最小值為 300,最大值為 50000,預設值為 5000。 演算法會盡最大努力打破句子界限上的文字,因此每個區塊的大小可能略低於 maximumPageLength
pageOverlapLength 只有在 設定為 pages時才textSplitMode適用。 每個頁面的開頭都是上一頁結尾的這個字元數。 如果此參數設定為 0,則後續頁面上沒有重疊的文字。 此參數支援在 2023-10-01-Preview REST API 和已更新為支援整合向量化的 Azure SDK Beta 套件中。 此 範例 包含 參數。
maximumPagesToTake 只有在 設定為 pages時才textSplitMode適用。 要傳回的頁數。 默認值為 0,表示傳回所有頁面。 如果只需要分頁子集,您應該設定此值。 此參數支援在 2023-10-01-Preview REST API 和已更新為支援整合向量化的 Azure SDK Beta 套件中。 此 範例 包含 參數。
defaultLanguageCode (選擇性)下列其中一個語言代碼: am, bs, cs, da, de, en, es, et, fr, he, hi, hr, hu, fi, id, is, it, ja, ko, lv, no, nl, pl, pt-PT, pt-BR, ru, sk, sl, sr, sv, tr, ur, zh-Hans。 預設值為英文(en)。 需要考慮一些事項:
  • 提供語言代碼有助於避免將非白空間語言的字切成一半,例如中文、日文和韓文。
  • 如果您事先不知道語言(例如,如果您使用 LanguageDetectionSkill 來偵測語言),建議您 en 使用預設值。

技能輸入

參數名稱 描述
text 要分割成子字串的文字。
languageCode (選擇性)檔的語言代碼。 如果您不知道文字輸入的語言(例如,如果您使用 LanguageDetectionSkill 來偵測語言),則可以省略此參數。 如果您設定 languageCode 為語言不在 的支持清單中 defaultLanguageCode,則會發出警告,而且不會分割文字。

技能輸出

參數名稱 描述
textItems 輸出是擷取的子字串數位。 textItems 是輸出的預設名稱。 targetName 是選擇性的,但如果您有多個文字分割技能,請務必設定 targetName ,以免以第二個技能覆寫第一個技能的數據。 如果 targetName 已設定,請在輸出字段對應或使用技能輸出的下游技能中使用。

範例定義

{
    "@odata.type": "#Microsoft.Skills.Text.SplitSkill",
    "textSplitMode" : "pages", 
    "maximumPageLength": 1000,
    "defaultLanguageCode": "en",
    "inputs": [
        {
            "name": "text",
            "source": "/document/content"
        },
        {
            "name": "languageCode",
            "source": "/document/language"
        }
    ],
    "outputs": [
        {
            "name": "textItems",
            "targetName": "mypages"
        }
    ]
}

範例輸入

{
    "values": [
        {
            "recordId": "1",
            "data": {
                "text": "This is the loan application for Joe Romero, a Microsoft employee who was born in Chile and who then moved to Australia...",
                "languageCode": "en"
            }
        },
        {
            "recordId": "2",
            "data": {
                "text": "This is the second document, which will be broken into several pages...",
                "languageCode": "en"
            }
        }
    ]
}

範例輸出

{
    "values": [
        {
            "recordId": "1",
            "data": {
                "textItems": [
                    "This is the loan...",
                    "In the next section, we continue..."
                ]
            }
        },
        {
            "recordId": "2",
            "data": {
                "textItems": [
                    "This is the second document...",
                    "In the next section of the second doc..."
                ]
            }
        }
    ]
}

區塊化和向量化的範例

此範例適用於目前處於預覽狀態的整合向量化。 它會將僅限預覽的參數新增至範例定義,並顯示產生的輸出。

範例定義

此定義會新增 pageOverlapLength 100 個字元和 maximumPagesToTake 1 個字元。

假設 maximumPageLength 是 5,000 個字元(預設值),然後 "maximumPagesToTake": 1 處理每個源文檔的前 5,000 個字元。

本範例會將 設定 textItems 為 到 myPagestargetName。 因為 targetName 已設定, myPages 是您應該用來從文字分割技能中選取輸出的值。 在 /document/mypages/* 下游技能、索引器 輸出字段對應知識存放區投影索引投影中使用

{
    "@odata.type": "#Microsoft.Skills.Text.SplitSkill",
    "textSplitMode" : "pages", 
    "maximumPageLength": 1000,
    "pageOverlapLength": 100,
    "maximumPagesToTake": 1,
    "defaultLanguageCode": "en",
    "inputs": [
        {
            "name": "text",
            "source": "/document/content"
        },
        {
            "name": "languageCode",
            "source": "/document/language"
        }
    ],
    "outputs": [
        {
            "name": "textItems",
            "targetName": "mypages"
        }
    ]
}

範例輸入(與先前的範例相同)

{
    "values": [
        {
            "recordId": "1",
            "data": {
                "text": "This is the loan application for Joe Romero, a Microsoft employee who was born in Chile and who then moved to Australia...",
                "languageCode": "en"
            }
        },
        {
            "recordId": "2",
            "data": {
                "text": "This is the second document, which will be broken into several sections...",
                "languageCode": "en"
            }
        }
    ]
}

範例輸出(請注意重疊)

在每個 「textItems」 陣列中,第一個專案的尾端文字會複製到第二個專案的開頭。

{
    "values": [
        {
            "recordId": "1",
            "data": {
                "textItems": [
                    "This is the loan...Here is the overlap part",
                    "Here is the overlap part...In the next section, we continue..."
                ]
            }
        },
        {
            "recordId": "2",
            "data": {
                "textItems": [
                    "This is the second document...Here is the overlap part...",
                    "Here is the overlap part...In the next section of the second doc..."
                ]
            }
        }
    ]
}

錯誤案例

如果不支持語言,就會產生警告。

另請參閱