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

interpret 方法interpret Method

interpret 方法采用自然语言查询字符串,并根据语法和索引数据返回对用户意向的格式化解释。The interpret method takes a natural language query string and returns formatted interpretations of user intent based on the grammar and index data. 为了提供交互式搜索体验,可以调用此方法,因为每个字符都由用户输入,其中 complete 参数设置为 1 以启用自动完成建议。To provide an interactive search experience, this method may be called as each character is entered by the user with the complete parameter set to 1 to enable auto-complete suggestions.

请求Request

http://<host>/interpret?query=<query>[&<options>]

NameName Value 描述Description
queryquery 文本字符串Text string 用户输入的查询。Query entered by user. 如果 complete 设置为 1,查询将被解释为生成查询自动完成建议的前缀。If complete is set to 1, query will be interpreted as a prefix for generating query auto-completion suggestions.
completecomplete 0(默认值)或 10 (default) or 1 1 意味着自动完成建议是基于语法和索引数据生成的。1 means that auto-completion suggestions are generated based on the grammar and index data.
计数count 数字(默认值为 10)Number (default=10) 返回的最大解释数。Maximum number of interpretations to return.
offsetoffset 数字(默认值为 0)Number (default=0) 返回的第一个解释的索引。Index of the first interpretation to return. 例如,count=2&offset=0 返回解释 0 和 1。For example, count=2&offset=0 returns interpretations 0 and 1. count=2&offset=2 返回解释 2 和 3。count=2&offset=2 returns interpretations 2 and 3.
timeouttimeout 数字(默认值为 1000)Number (default=1000) 超时(以毫秒为单位)。Timeout in milliseconds. 仅返回在超时之前找到的解释。Only interpretations found before the timeout has elapsed are returned.

使用 count 和 offset 参数,可以在多个请求中以增量方式获取大量结果。Using the count and offset parameters, a large number of results may be obtained incrementally over multiple requests.

响应 (JSON)Response (JSON)

JSONPathJSONPath 描述Description
$.query$.query query 参数来自请求。query parameter from the request.
$.interpretations$.interpretations 将输入查询与语法相匹配的 0 种或多种方法数组。Array of 0 or more ways to match the input query against the grammar.
$.interpretations[*].logprob$.interpretations[*].logprob 解释的相对对数概率 (<=0)。Relative log probability of the interpretation (<= 0). 较高值更有可能。Higher values are more likely.
$.interpretations[*].parse$.interpretations[*].parse XML 字符串,显示如何解释查询的各个部分。XML string that shows how each part of the query was interpreted.
$.interpretations[*].rules$.interpretations[*].rules 在解释期间调用的语法中定义的 1 个或多个规则数组。Array of 1 or more rules defined in the grammar invoked during interpretation.
$.interpretations[*].rules[*].name$.interpretations[*].rules[*].name 规则名称。Name of the rule.
$.interpretations[*].rules[*].output$.interpretations[*].rules[*].output 规则的语义输出。Semantic output of the rule.
$.interpretations[*].rules[*].output.type$.interpretations[*].rules[*].output.type 语义输出的数据类型。Data type of the semantic output.
$.interpretations[*].rules[*].output.value$.interpretations[*].rules[*].output.value 语义输出的值。Value of the semantic output.
$.aborted$.aborted 如果请求超时,则为 True。True if the request timed out.

分析 XMLParse XML

分析 XML 注释(已完成)查询,提供关于如何与索引中的语法和属性中的规则相匹配的信息。The parse XML annotates the (completed) query with information about how it matches against the rules in the grammar and attributes in the index. 下面是学术出版物领域的一个示例:Below is an example from the academic publications domain:

<rule name="#GetPapers">
  papers by 
  <attr name="academic#Author.Name" canonical="heungyeung shum">harry shum</attr>
  <rule name="#GetPaperYear">
    written in
    <attr name="academic#Year">2000</attr>
  </rule>
</rule>

<rule> 元素划定与其 name 属性指定的规则相匹配的查询范围。The <rule> element delimits the range in the query matching the rule specified by its name attribute. 当解析涉及到语法中的规则引用时,可能会嵌套。It may be nested when the parse involves rule references in the grammar.

<attr> 元素划定与其 name 属性指定的索引属性相匹配的查询范围。The <attr> element delimits the range in the query matching the index attribute specified by its name attribute. 当匹配在输入查询中包含同义词时,canonical 属性将包含与索引中的同义词匹配的规范值。When the match involves a synonym in the input query, the canonical attribute will contain the canonical value matching the synonym from the index.

示例Example

在学术出版物示例中,下面的请求针对前缀查询“papers by jaime”返回最多 2 个自动完成建议:In the academic publications example, the following request returns up to 2 auto-completion suggestions for the prefix query "papers by jaime":

http://<host>/interpret?query=papers by jaime&complete=1&count=2

响应包含前两个(“count=2”)最有可能的解释,这两个解释完成了部分“papers by jaime”查询:“papers by jaime teevan”和“papers by jaime green”。The response contains the top two ("count=2") most likely interpretations that complete the partial query "papers by jaime": "papers by jaime teevan" and "papers by jaime green". 该服务生成查询完成,而不是只考虑作者“jaime”的精确匹配,因为请求指定“complete=1”。The service generated query completions instead of considering only exact matches for the author "jaime" because the request specified "complete=1". 请注意,规范值“j l green”通过同义词“jamie green”匹配,如解析中所示。Note that the canonical value "j l green" matched via the synonym "jamie green", as indicated in the parse.

{
  "query": "papers by jaime",
  "interpretations": [
    {
      "logprob": -5.615,
      "parse": "<rule name=\"#GetPapers\">papers by <attr name=\"academic#Author.Name\">jaime teevan</attr></rule>",
      "rules": [
        {
          "name": "#GetPapers",
          "output": {
            "type": "query",
            "value": "Composite(Author.Name=='jaime teevan')"
          }
        }
      ]
    },
    {
      "logprob": -5.849,
      "parse": "<rule name=\"#GetPapers\">papers by <attr name=\"academic#Author.Name\" canonical=\"j l green\">jaime green</attr></rule>",
      "rules": [
        {
          "name": "#GetPapers",
          "output": {
            "type": "query",
            "value": "Composite(Author.Name=='j l green')"
          }
        }
      ]
    }
  ]
}

当语义输出类型为“query”,就像本例所示,可以通过 expr 参数将 output.value 传递到 evaluate API 来检索匹配对象。When the type of semantic output is "query", as in this example, the matching objects can be retrieved by passing output.value to the evaluate API via the expr parameter.

http://<host>/evaluate?expr=Composite(AA.AuN=='jaime teevan')