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

语义解释Semantic Interpretation

语义解释通过语法将语义输出与每个解释路径相关联。Semantic interpretation associates semantic output with each interpreted path through the grammar. 具体而言,服务计算解释遍历的 tag 元素中的语句序列,以计算最终输出。In particular, the service evaluates the sequence of statements in the tag elements traversed by the interpretation to compute the final output.

语句可能是文本分配或另一变量的变量。A statement may be an assignment of a literal or a variable to another variable. 此外,它还可向变量分配不带参数或带参数的函数的输出。It may also assign the output of a function with 0 or more parameters to a variable. 每个函数参数都可使用文本或变量指定。Each function parameter may be specified using a literal or a variable. 如果函数不返回任何输出,则省略分配。If the function does not return any output, the assignment is omitted.

<tag>x = 1; y = x;</tag>
<tag>q = All(); q = And(q, q2);</tag>
<tag>AssertEquals(x, 1);</tag>

使用以字母开头,仅包含字母 (A-Z)、数字 (0-9) 和下划线 (_) 的名称标识符指定变量。A variable is specified using a name identifier that starts with a letter and consists only of letters (A-Z), numbers (0-9), and the underscore (_). 从分配给它的文本或函数输出隐式推断出它的类型。Its type is implicitly inferred from the literal or function output value assigned to it.

以下是当前受支持的数据类型列表:Below is a list of currently supported data types:

类型Type 说明Description 示例Examples
StringString 0 或更多字符的序列Sequence of 0 or more characters "Hello World!""Hello World!"
""""
BoolBool 布尔值Boolean value truetrue
falsefalse
Int32Int32 32 位带符号整数。32-bit signed integer. -2.1e9 到 2.1e9-2.1e9 to 2.1e9 123123
-321-321
Int64Int64 64 位带符号整数。64-bit signed integer. -9.2e18 和 9.2e18-9.2e18 and 9.2e18 98765432109876543210
DoubleDouble 双精度浮点。Double precision floating-point. 1.7e+/-308(15 位)1.7e+/-308 (15 digits) 123.456789123.456789
1.23456789e21.23456789e2
GuidGuid 全局唯一标识符Globally unique identifier "602DD052-CC47-4B23-A16A-26B52D30C05B""602DD052-CC47-4B23-A16A-26B52D30C05B"
QueryQuery 查询表达式,指示索引中的数据对象子集Query expression that specifies a subset of data objects in the index All()All()
And(q1, q2) And(q1, q2)

语义函数Semantic Functions

没有内置的语义函数集。There is a built-in set of semantic functions. 它们允许构造复杂查询,并提供对语法解释的上下文敏感控件。They allow the construction of sophisticated queries, and provide context sensitive control over grammar interpretations.

And 函数And Function

query = And(query1, query2);

返回由两个输入查询的交集组成的查询。Returns a query composed from the intersection of two input queries.

Or 函数Or Function

query = Or(query1, query2);

返回由两个输入查询的并集组成的查询。Returns a query composed from the union of two input queries.

All 函数All Function

query = All();

返回包含所有数据对象的查询。Returns a query that includes all data objects.

在以下示例中,我们以迭代方式使用 All() 函数根据 1 个或多个关键字的交集生成查询。In the following example, we use the All() function to iteratively build up a query based on the intersection of 1 or more keywords.

<tag>query = All();</tag>
<item repeat="1-">
  <attrref uri="academic#Keyword" name="keyword">
  <tag>query = And(query, keyword);</tag>
</item>

None 函数None Function

query = None();

返回不包含任何数据对象的查询。Returns a query that includes no data objects.

在以下示例中,我们以迭代方式使用 None() 函数根据 1 个或多个关键字的并集生成查询。In the following example, we use the None() function to iteratively build up a query based on the union of 1 or more keywords.

<tag>query = None();</tag>
<item repeat="1-">
  <attrref uri="academic#Keyword" name="keyword">
  <tag>query = Or(query, keyword);</tag>
</item>

Query 函数Query Function

query = Query(attrName, value)
query = Query(attrName, value, op)

根据指定运算 op(默认值为“eq”),返回仅包含其属性 attrName 匹配值 value 的数据对象的查询 。Returns a query that includes only data objects whose attribute attrName matches value value according to the specified operation op, which defaults to "eq". 通常情况下,使用 attrref 元素基于匹配的输入查询字符串创建查询。Typically, use an attrref element to create a query based on the matched input query string. 如果给定值或通过其他方式获得值,可使用 Query() 函数创建匹配该值的查询。If a value is given or obtained through other means, the Query() function can be used to create a query matching this value.

在下面的示例中,使用 Query() 函数来实现对指定特定十年中的学术出版物的支持。In the following example, we use the Query() function to implement support for specifying academic publications from a particular decade.

written in the 90s
<tag>
  beginYear = Query("academic#Year", 1990, "ge");
  endYear = Query("academic#Year", 2000, "lt");
  year = And(beginYear, endYear);
</tag>

Composite 函数Composite Function

query = Composite(innerQuery);

返回一个查询,它封装一个由匹配组成的 innerQuery,该 innerQuery 针对常见复合属性 attr 的子属性 。Returns a query that encapsulates an innerQuery composed of matches against sub-attributes of a common composite attribute attr. 封装要求任何匹配的数据对象的复合属性 attr 至少有一个单独满足 innerQuery 的值 。The encapsulation requires the composite attribute attr of any matching data object to have at least one value that individually satisfies the innerQuery. 请注意,复合属性的子属性上的查询必须使用 Composite() 函数封装,然后才能与其他查询结合使用。Note that a query on sub-attributes of a composite attribute has to be encapsulated using the Composite() function before it can be combined with other queries.

例如,以下查询将返回“harry shum”的学术出版物,同时他在“microsoft”:For example, the following query returns academic publications by "harry shum" while he was at "microsoft":

Composite(And(Query("academic#Author.Name", "harry shum"), 
              Query("academic#Author.Affiliation", "microsoft")));

另一方面,下面的查询返回学术出版物,其中一位作者是“harry shum”,且其中一个隶属关系是“microsoft”:On the other hand, the following query returns academic publications where one of the authors is "harry shum" and one of the affiliations is "microsoft":

And(Composite(Query("academic#Author.Name", "harry shum"), 
    Composite(Query("academic#Author.Affiliation", "microsoft")));

GetVariable 函数GetVariable Function

value = GetVariable(name, scope);

返回变量 name 的值,该值根据指定的 scope 定义 。Returns the value of variable name defined under the specified scope. name 是以字母开头,仅包含字母 (A-Z)、数字 (0-9) 和下划线 () 的标识符 。name is an identifier that starts with a letter and consists only of letters (A-Z), numbers (0-9), and the underscore (). scope 可设置为“请求”或“系统” 。scope can be set to "request" or "system". 请注意,根据不同作用域定义的变量有别于彼此,包括通过语义函数的输出定义的变量。Note that variables defined under different scopes are distinct from each other, including ones defined via the output of semantic functions.

请求作用域变量在当前解释请求的所有解释之间共用。Request scope variables are shared across all interpretations within the current interpret request. 可使用它们来控制通过语法搜索解释。They can be used to control the search for interpretations over the grammar.

服务预定义系统变量并可用来检索有关系统当前状态的各种统计信息。System variables are predefined by the service and can be used to retrieve various statistics about the current state of the system. 下面是当前支持的系统变量集:Below is the set of currently supported system variables:

名称Name 类型Type 说明Description
IsAtEndOfQueryIsAtEndOfQuery BoolBool 如果当前解释匹配所有输入查询文本,则为 truetrue if the current interpretation has matched all input query text
IsBeyondEndOfQueryIsBeyondEndOfQuery BoolBool 如果当前解释建议了输入查询文本之外的完成,则为 truetrue if the current interpretation has suggested completions beyond the input query text

SetVariable 函数SetVariable Function

SetVariable(name, value, scope);

根据指定的 scope,向变量 name 分配 value 。Assigns value to variable name under the specified scope. name 是以字母开头,仅包含字母 (A-Z)、数字 (0-9) 和下划线 () 的标识符 。name is an identifier that starts with a letter and consists only of letters (A-Z), numbers (0-9), and the underscore (). 目前 scope 唯一有效的值是“请求” 。Currently, the only valid value for scope is "request". 没有任何可设置的系统变量。There are no settable system variables.

请求作用域变量在当前解释请求的所有解释之间共用。Request scope variables are shared across all interpretations within the current interpret request. 可使用它们来控制通过语法搜索解释。They can be used to control the search for interpretations over the grammar.

AssertEquals 函数AssertEquals Function

AssertEquals(value1, value2);

如果 value1 和 value2 等效,则函数成功,并且没有任何副作用 。If value1 and value2 are equivalent, the function succeeds and has no side effects. 否则,函数失败并拒绝解释。Otherwise, the function fails and rejects the interpretation.

AssertNotEquals 函数AssertNotEquals Function

AssertNotEquals(value1, value2);

如果 value1 和 value2 不等效,则函数成功,并且没有任何副作用 。If value1 and value2 are not equivalent, the function succeeds and has no side effects. 否则,函数失败并拒绝解释。Otherwise, the function fails and rejects the interpretation.