文本合并认知技能

“文本合并”技能会将字符串数组中的文本合并到单个字段中。

注意

此技能未绑定到认知服务。 它不可计费,并且没有认知服务密钥要求。

@odata.type

Microsoft.Skills.Text.MergeSkill

技能参数

参数区分大小写。

参数名称 说明
insertPreTag 每次插入之前要包含的字符串。 默认值为 " "。 要忽略空格,请将值设置为 ""
insertPostTag 每次插入后要包含的字符串。 默认值为 " "。 要忽略空格,请将值设置为 ""

技能输入

输入名称 说明
itemsToInsert 要合并的字符串数组。
text (可选)要插入的主文本正文。 如果未提供 text,则将串联 itemsToInsert 的元素。
offsets (可选)text 中应插入 itemsToInsert 的位置数组。 如果提供,则 text 的元素数目必须等于 textToInsert 的元素数目。 否则,所有项都将追加到 text 的末尾。

技能输出

输出名称 说明
mergedText 生成的合并文本。
mergedOffsets mergedText 中应插入 itemsToInsert 元素的位置数组。

示例输入

为此技能提供可用输入的 JSON 文档有:

{
  "values": [
    {
      "recordId": "1",
      "data":
      {
        "text": "The brown fox jumps over the dog",
        "itemsToInsert": ["quick", "lazy"],
        "offsets": [3, 28]
      }
    }
  ]
}

示例输出

此示例显示之前输入的输出,假设将 insertPreTag 设置为 " "并将 insertPostTag 设置为 ""

{
  "values": [
    {
      "recordId": "1",
      "data":
      {
        "mergedText": "The quick brown fox jumps over the lazy dog"
      }
    }
  ]
}

扩展的示例技能集定义

使用文本合并的一个常见场景是将图像的文本表示形式(OCR 技能中的文本或图像的描述文字)合并到文档的内容字段中。

以下示例技能使用 OCR 技能从文档中嵌入的图像中提取文本。 接下来,它会创建 merged_text 字段以包含每个图像的原始和 OCRed 文本。 可在此处了解有关 OCR 技能的详细信息。

{
  "description": "Extract text from images and merge with content text to produce merged_text",
  "skills":
  [
    {
      "description": "Extract text (plain and structured) from image.",
      "@odata.type": "#Microsoft.Skills.Vision.OcrSkill",
      "context": "/document/normalized_images/*",
      "defaultLanguageCode": "en",
      "detectOrientation": true,
      "inputs": [
        {
          "name": "image",
          "source": "/document/normalized_images/*"
        }
      ],
      "outputs": [
        {
          "name": "text"
        }
      ]
    },
    {
      "@odata.type": "#Microsoft.Skills.Text.MergeSkill",
      "description": "Create merged_text, which includes all the textual representation of each image inserted at the right location in the content field.",
      "context": "/document",
      "insertPreTag": " ",
      "insertPostTag": " ",
      "inputs": [
        {
          "name":"text", 
          "source": "/document/content"
        },
        {
          "name": "itemsToInsert", 
          "source": "/document/normalized_images/*/text"
        },
        {
          "name":"offsets", 
          "source": "/document/normalized_images/*/contentOffset" 
        }
      ],
      "outputs": [
        {
          "name": "mergedText", 
          "targetName" : "merged_text"
        }
      ]
    }
  ]
}

以上示例假设存在规范化的图像字段。 要获取规范化的图像字段,请将索引器定义中的 imageAction 配置设置为 generateNormalizedImages,如下所示:

{
  //...rest of your indexer definition goes here ...
  "parameters":{
    "configuration":{
        "dataToExtract":"contentAndMetadata",
        "imageAction":"generateNormalizedImages"
    }
  }
}

另请参阅