您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

整形程序认知技能Shaper cognitive skill

整形程序技能将多个输入合并为一个复杂类型,以后可在扩充管道中进行引用。The Shaper skill consolidates several inputs into a complex type that can be referenced later in the enrichment pipeline. 借助整形程序技能,可实质上创建结构、定义该结构的成员名称,并为每个成员分配值。The Shaper skill allows you to essentially create a structure, define the name of the members of that structure, and assign values to each member. 搜索方案中有用的合并字段的示例包括:将名字和姓氏合并为单个结构,将城市和州合并为单个结构,或将名称和出生日期合并为单个结构以建立唯一标识。Examples of consolidated fields useful in search scenarios include combining a first and last name into a single structure, city and state into a single structure, or name and birthdate into a single structure to establish unique identity.

此外,方案 3中所示的整形程序技能向输入添加了一个可选的sourceContext属性。Additionally, the Shaper skill illustrated in scenario 3 adds an optional sourceContext property to the input. SourcesourceContext属性互相排斥。The source and sourceContext properties are mutually exclusive. 如果输入位于技能的上下文中,只需使用sourceIf the input is at the context of the skill, simply use source. 如果输入的上下文与技能上下文不同,请使用sourceContextIf the input is at a different context than the skill context, use the sourceContext. SourceContext要求您定义一个嵌套输入,并将特定元素作为源进行寻址。The sourceContext requires you to define a nested input with the specific element being addressed as the source.

输出名称始终为 "output"。The output name is always "output". 在内部,管道可以映射不同的名称,如以下示例中所示的 "analyzedText",但整形技能本身会在响应中返回 "output"。Internally, the pipeline can map a different name, such as "analyzedText" as shown in the examples below, but the Shaper skill itself returns "output" in the response. 如果正在调试大量文档并发现存在命名差异,或者要生成自定义技能并自行构建响应,这一点非常重要。This might be important if you are debugging enriched documents and notice the naming discrepancy, or if you build a custom skill and are structuring the response yourself.

备注

整形程序技能未绑定到认知服务 API,你不用付费。The Shaper skill is not bound to a Cognitive Services API and you are not charged for using it. 但是,你仍然应该附加认知服务资源,以覆盖免费资源选项,该选项限制你每天进行少量的每日扩充。You should still attach a Cognitive Services resource, however, to override the Free resource option that limits you to a small number of daily enrichments per day.

@odata.type

Microsoft.Skills.Util.ShaperSkillMicrosoft.Skills.Util.ShaperSkill

方案1:复杂类型Scenario 1: complex types

请思考这样一种情况:想要创建名为 analyzedText 的结构,该结构具有两个成员:分别为 text 和 sentiment。Consider a scenario where you want to create a structure called analyzedText that has two members: text and sentiment, respectively. 在索引中,多部分可搜索字段称为复杂类型,并且通常在源数据具有映射到它的相应复杂结构时创建。In an index, a multi-part searchable field is called a complex type and it's often created when source data has a corresponding complex structure that maps to it.

但是,创建复杂类型的另一种方法是使用整形程序技能。However, another approach for creating complex types is through the Shaper skill. 通过在技能组合中包括这一技能,在技能组合处理过程中,内存中操作可以使用嵌套结构输出数据形状,然后可以将这些形状映射到索引中的复杂类型。By including this skill in a skillset, the in-memory operations during skillset processing can output data shapes with nested structures, which can then be mapped to a complex type in your index.

下面的示例技术定义提供了成员名称作为输入。The following example skill definition provides the member names as the input.

{
  "@odata.type": "#Microsoft.Skills.Util.ShaperSkill",
  "context": "/document/content/phrases/*",
  "inputs": [
    {
      "name": "text",
      "source": "/document/content/phrases/*"
    },
    {
      "name": "sentiment",
      "source": "/document/content/phrases/*/sentiment"
    }
  ],
  "outputs": [
    {
      "name": "output",
      "targetName": "analyzedText"
    }
  ]
}

示例索引Sample index

技能组合由索引器调用,并且索引器需要索引。A skillset is invoked by an indexer, and an indexer requires an index. 索引中的复杂字段表示形式可能类似于下面的示例。A complex field representation in your index might look like the following example.


    "name": "my-index",
    "fields": [
        {   "name": "myId", "type": "Edm.String", "key": true, "filterable": true   },
        {   "name": "analyzedText", "type": "Edm.ComplexType",
            "fields": [{
                    "name": "text",
                    "type": "Edm.String",
                    "filterable": false,
                    "sortable": false,
                    "facetable": false,
                    "searchable": true  },
          {
                    "name": "sentiment",
                    "type": "Edm.Double",
                    "searchable": true,
                    "filterable": true,
                    "sortable": true,
                    "facetable": true
                },

技能输入Skill input

为此整形程序技能提供可用输入的传入 JSON 文档可能是:An incoming JSON document providing usable input for this Shaper skill could be:

{
    "values": [
        {
            "recordId": "1",
            "data": {
                "text": "this movie is awesome",
                "sentiment": 0.9
            }
        }
    ]
}

技能输出Skill output

整形程序技能使用 textsentiment 组合元素生成一个名为 analyzedText 的新元素。The Shaper skill generates a new element called analyzedText with the combined elements of text and sentiment. 此输出符合索引架构。This output conforms to the index schema. 它将在 Azure 认知搜索索引中导入并编制索引。It will be imported and indexed in an Azure Cognitive Search index.

{
    "values": [
      {
        "recordId": "1",
        "data":
           {
            "analyzedText": 
              {
                "text": "this movie is awesome" ,
                "sentiment": 0.9
              }
           }
      }
    ]
}

方案2:输入合并Scenario 2: input consolidation

在另一个示例中,假设处于管道处理的不同阶段,已提取书名以及该书不同页面上的章节标题。In another example, imagine that at different stages of pipeline processing, you have extracted the title of a book, and chapter titles on different pages of the book. 现在可创建由这些不同输入组成的单个结构。You could now create a single structure composed of these various inputs.

此方案的整形程序技能定义可能类似于以下示例:The Shaper skill definition for this scenario might look like the following example:

{
    "@odata.type": "#Microsoft.Skills.Util.ShaperSkill",
    "context": "/document",
    "inputs": [
        {
            "name": "title",
            "source": "/document/content/title"
        },
        {
            "name": "chapterTitles",
            "source": "/document/content/pages/*/chapterTitles/*/title"
        }
    ],
    "outputs": [
        {
            "name": "output",
            "targetName": "titlesAndChapters"
        }
    ]
}

技能输出Skill output

在这种情况下,整形会平展所有章节标题,以创建单个阵列。In this case, the Shaper flattens all chapter titles to create a single array.

{
    "values": [
        {
            "recordId": "1",
            "data": {
                "titlesAndChapters": {
                    "title": "How to be happy",
                    "chapterTitles": [
                        "Start young",
                        "Laugh often",
                        "Eat, sleep and exercise"
                    ]
                }
            }
        }
    ]
}

方案3:从嵌套上下文输入合并Scenario 3: input consolidation from nested contexts

假设您拥有书籍的标题、章节和内容,并对内容运行实体识别和关键短语,现在需要将不同技能的结果聚合为一个具有章节名称、实体和关键短语的形状。Imagine you have the title, chapters, and contents of a book and have run entity recognition and key phrases on the contents and now need to aggregate results from the different skills into a single shape with the chapter name, entities, and key phrases.

此方案的整形程序技能定义可能类似于以下示例:The Shaper skill definition for this scenario might look like the following example:

{
    "@odata.type": "#Microsoft.Skills.Util.ShaperSkill",
    "context": "/document",
    "inputs": [
        {
            "name": "title",
            "source": "/document/content/title"
        },
        {
            "name": "chapterTitles",
            "sourceContext": "/document/content/pages/*/chapterTitles/*",
            "inputs": [
              {
                  "name": "title",
                  "source": "/document/content/pages/*/chapterTitles/*/title"
              },
              {
                  "name": "number",
                  "source": "/document/content/pages/*/chapterTitles/*/number"
              }
            ]
        }

    ],
    "outputs": [
        {
            "name": "output",
            "targetName": "titlesAndChapters"
        }
    ]
}

技能输出Skill output

在这种情况下,整形会创建复杂类型。In this case, the Shaper creates a complex type. 此结构存在于内存中。This structure exists in-memory. 如果要将其保存到知识库,应在技能组合中创建一个定义存储特征的投影。If you want to save it to a knowledge store, you should create a projection in your skillset that defines storage characteristics.

{
    "values": [
        {
            "recordId": "1",
            "data": {
                "titlesAndChapters": {
                    "title": "How to be happy",
                    "chapterTitles": [
                      { "title": "Start young", "number": 1},
                      { "title": "Laugh often", "number": 2},
                      { "title": "Eat, sleep and exercise", "number: 3}
                    ]
                }
            }
        }
    ]
}

另请参阅See also