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

快速入门:查询实体Quickstart: Query for Entities

如果查询请求有关人员、地点或事件的信息,则响应可以包含 entities 答案。If the query requests information about a person, place or thing, the response can contain an entities answer. 查询始终返回网页,且事实和/或实体依赖于查询。Queries always return webpages, facts and/or entities are query dependent.

实体支持三种查询方案:Entities support three query scenarios:

  • DominantEntity - 只有一个实体匹配用户的查询和意向。DominantEntity—There is only one entity that matches the user's query and intent. 例如,查询“太空针塔”是 DominantEntity 方案。For example, the query, Space Needle, is a DominantEntity scenario.
  • Disambiguation - 存在多个与用户的查询和意向匹配的实体,由用户选择正确的实体。Disambiguation—There is more than one entity that matches the user's query and intent and it is up to the user to select the correct entity. 例如,查询“权力的游戏”是一个 Disambiguation 方案,它返回电视节目和书籍系列。For example, the query Game of Thrones is a Disambiguation scenario that returns the television show and the book series.
  • List - 存在多个与用户的查询和意向匹配的实体。List—There are multiple entities that match the user's query and intent. 例如,查询“濒危物种列表”是 List 方案,它返回格式设置为以行和单元格显示的表格值。For example, the query "List of endangered species" is a list scenario that returns tabular values formatted for display in rows and cells.

要确定查询方案,请使用 entities 对象的 queryScenario 字段。To determine the query scenario, use the queryScenario field of the entities object. 实体包含的数据取决于实体的类型。The data that the entity includes depends on the entity's type. 虽然实体包含相同的基本信息,但某些实体(如旅游景点或书籍)包含其他属性。Although entities include the same basic information, some entities such as tourist attractions or books include additional properties. 包含其他属性的实体包括 _type 字段,其中包含由序列化程序使用的提示。Entities that include additional properties include the _type field that contains a hint used by the serializer. 以下实体包含其他属性:The following entities include additional properties:

  • 书籍Book
  • 音乐录制MusicRecording
  • 人员Person
  • 景点Attraction

要确定响应所包含的实体的类型,请使用 entityTypeHints 字段,如“比尔·盖茨”的查询所示。To determine the type of entity that the response contains, use the entityTypeHints field as shown in the query for Bill Gates.

        },
        "description": "Bill Gates is an American business man and philanthropist, co-founder of Microsoft",
        "entityPresentationInfo": {
          "entityScenario": "DominantEntity",
          "entityTypeHints": [
            "Person"
          ]
        },
        "bingId": "6d7d66a7-2cb8-0ae9-637c-f81fd749dc9a"
      }

下面是“太空针塔”的查询:The following is a query for Space Needle:

https://api.labs.cognitive.microsoft.com/answerSearch/v7.0/search?q=space+needle&mkt=en-us

该响应包括 entities 答案。The response includes the entities answer. 请注意 entityScenarioentityTypeHints 字段。Note the entityScenario and entityTypeHints fields.

  "entities": {
    "value": [
      {
        "id": "https://www.bingapis.com/api/v7/#Entities.0",
        "contractualRules": [
          {
            "_type": "ContractualRules/LicenseAttribution",
            "targetPropertyName": "description",
            "mustBeCloseToContent": true,
            "license": {
              "name": "CC-BY-SA",
              "url": "https://creativecommons.org/licenses/by-sa/3.0/"
            },
            "licenseNotice": "Text under CC-BY-SA license"
          },
          {
            "_type": "ContractualRules/LinkAttribution",
            "targetPropertyName": "description",
            "mustBeCloseToContent": true,
            "text": "Wikipedia",
            "url": "https://en.wikipedia.org/wiki/Space_Needle"
          },
          {
            "_type": "ContractualRules/MediaAttribution",
            "targetPropertyName": "image",
            "mustBeCloseToContent": true,
            "url": "https://en.wikipedia.org/wiki/Space_Needle"
          }
        ],
        "webSearchUrl": "https://www.bing.com/entityexplore?q\u003dSpace+Needle\u0026filters\u003dsid:%22f8dd5b08-206d-2554-6e4a-893f51f4de7e%22\u0026elv\u003dAXXfrEiqqD9r3GuelwApulpmymQx!ODfuQu*veOQHkvP0!Zbvi5F5tVcMSDJvDEWiQWwrdueYTtIszgj03oFQHykYYLYgq3q5!Sf00QxXGIS",
        "name": "Space Needle",
        "image": {
          "name": "Space Needle",
          "thumbnailUrl": "https://www.bing.com/th?id\u003dA15d336cf119b9b5c7e0ab37e271421d3\u0026w\u003d110\u0026h\u003d110\u0026c\u003d7\u0026rs\u003d1\u0026qlt\u003d80\u0026cdv\u003d1\u0026pid\u003d16.1",
          "provider": [
            {
              "_type": "Organization",
              "url": "https://en.wikipedia.org/wiki/Space_Needle"
            }
          ],
          "hostPageUrl": "https://upload.wikimedia.org/wikipedia/commons/2/23/Space_Needle_2011-07-04.jpg",
          "width": 110,
          "height": 110,
          "sourceWidth": 152,
          "sourceHeight": 300
        },
        "description": "The Space Needle is an observation tower in Seattle, Washington, a landmark of the Pacific Northwest, and an icon of Seattle. It was built in the Seattle Center for the 1962 World\u0027s Fair, which drew over 2.3 million visitors, when nearly 20,000 people a day used its elevators.",
        "entityPresentationInfo": {
          "entityScenario": "DominantEntity",
          "entityTypeHints": [
            "Attraction"
          ]
        },
        "bingId": "f8dd5b08-206d-2554-6e4a-893f51f4de7e"
      }
    ]
  },

如果相关,查询可返回一个列表。A query can return a list if it is relevant.

查询: 以下查询查找濒危物种列表:Query: The following query finds a list of endangered species:

https://api.labs.cognitive.microsoft.com/answerSearch/v7.0/search?q=list+of+endangered+species

响应: 响应包括格式设置为作为表格值显示的列表:Response: The response includes a list formatted for display as tabular values:

  "facts": {
    "id": "https://www.bingapis.com/api/v7/#Facts",
    "contractualRules": [
      {
        "_type": "ContractualRules/LinkAttribution",
        "text": "www.worldwildlife.org/species/directory?direction=desc&sort=e…",
        "url": "https://www.worldwildlife.org/species/directory?direction=desc&sort=extinction_status"
      }
    ],
    "attributions": [
      {
        "providerDisplayName": "www.worldwildlife.org/species/directory?direction=desc&sort=e…",
        "seeMoreUrl": "https://www.worldwildlife.org/species/directory?direction=desc&sort=extinction_status"
      }
    ],
    "value": [
      {
        "subjectName": "Species Directory",
        "richCaption": {
          "_type": "StructuredValue/TabularData",
          "header": [
            "Common name",
            "Scientific name",
            "Conservation status ↓"
          ],
          "rows": [
            {
              "cells": [
                {
                  "_type": "Properties/Link",
                  "text": "Amur Leopard",
                  "url": "https://www.bing.com/https//www.worldwildlife.org/species/amur-leopard"
                },
                {
                  "text": "Panthera pardus orientalis"
                },
                {
                  "text": "Critically Endangered"
                }
              ]
            },
            {
              "cells": [
                {
                  "_type": "Properties/Link",
                  "text": "Black Rhino",
                  "url": "https://www.bing.com/https//www.worldwildlife.org/species/black-rhino"
                },
                {
                  "text": "Diceros bicornis"
                },
                {
                  "text": "Critically Endangered"
                }
              ]
            },
            {
              "cells": [
                {
                  "_type": "Properties/Link",
                  "text": "Bornean Orangutan",
                  "url": "https://www.bing.com/https//www.worldwildlife.org/species/bornean-orangutan"
                },
                {
                  "text": "Pongo pygmaeus"
                },
                {
                  "text": "Critically Endangered"
                }
              ]
            },
            {
              "cells": [
                {
                  "_type": "Properties/Link",
                  "text": "Cross River Gorilla",
                  "url": "https://www.bing.com/https//www.worldwildlife.org/species/cross-river-gorilla"
                },
                {
                  "text": "Gorilla gorilla diehli"
                },
                {
                  "text": "Critically Endangered"
                }
              ]
            }
          ],
          "seeMoreUrl": {
            "text": "46 more rows",
            "url": "https://www.worldwildlife.org/species/directory?direction=desc&sort=extinction_status"
          }
        }
      }
    ]
  },

后续步骤Next steps