模式语法Pattern syntax

模式语法是一个话语模板。Pattern syntax is a template for an utterance. 该模板应包含要匹配的字词和实体,还要包含希望忽略的字词和标点。The template should contain words and entities you want to match as well as words and punctuation you want to ignore. 它不是一个正则表达式 。It is not a regular expression.

注意

模式仅包括机器学习实体父项,而不包括子组件。Patterns only include machine-learned entity parents, not subcomponents.

模式中的实体用花括号 {} 括起。Entities in patterns are surrounded by curly brackets, {}. 模式可包含实体和带角色的实体。Patterns can include entities, and entities with roles. Pattern.any 是仅在模式中使用的实体。Pattern.any is an entity only used in patterns.

模式语法支持以下语法:Pattern syntax supports the following syntax:

函数Function 语法Syntax 嵌套级别Nesting level 示例Example
实体entity {} - 大括号{} - curly brackets 22 窗体 {entity-name} 在哪里?Where is form {entity-name}?
可选optional [] - 方括号[] - square brackets

可选和分组的任何组合的嵌套级别都限制为 3There is a limit of 3 on nesting levels of any combination of optional and grouping
22 问号是可选的 [?]The question mark is optional [?]
分组grouping () - 括号() - parentheses 22 是 (a | b)is (a | b)
or | - 竖线(管道)| - vertical bar (pipe)

一个组中的竖线限制为 2There is a limit of 2 on the vertical bars (Or) in one group
- 窗体 ({form-name-short} | {form-name-long} | {form-number}) 在哪里Where is form ({form-name-short} | {form-name-long} | {form-number})
话语的开头和/或结尾beginning and/or end of utterance ^ - 脱字号^ - caret - ^开始话语^begin the utterance
话语完成^the utterance is done^
^将整句话语与 {number} 实体进行严格的文本匹配^^strict literal match of entire utterance with {number} entity^

模式中的嵌套语法Nesting syntax in patterns

带有方括号的可选语法可以嵌套两个级别。The optional syntax, with square brackets, can be nested two levels. 例如:[[this]is] a new formFor example: [[this]is] a new form. 此示例允许以下话语:This example allows for the following utterances:

嵌套的可选话语示例Nested optional utterance example 说明Explanation
这是一个新窗体this is a new form 匹配模式中的所有字词matches all words in pattern
是一个新窗体is a new form 匹配模式中的外层可选字词和非可选字词matches outer optional word and non-optional words in pattern
一个新窗体a new form 仅匹配必需的字词matches required words only

带括号的分组语法可以嵌套两层。The grouping syntax, with parentheses, can be nested two levels. 例如:(({Entity1.RoleName1} | {Entity1.RoleName2} ) | {Entity2} )For example: (({Entity1.RoleName1} | {Entity1.RoleName2} ) | {Entity2} ). 此功能允许匹配任意三个实体。This feature allows any of the three entities to be matched.

如果 Entity1 是具有起点(西雅图)和终点(开罗)等角色的位置,并且 Entity 2 是列表实体中的一座已知大楼名称 (RedWest-C),则以下话语将映射到此模式:If Entity1 is a Location with roles such as origin (Seattle) and destination (Cairo) and Entity 2 is a known building name from a list entity (RedWest-C), the following utterances would map to this pattern:

嵌套的分组话语示例Nested grouping utterance example 说明Explanation
RedWest-CRedWest-C 匹配外层分组实体matches outer grouping entity
西雅图Seattle 匹配内层分组实体之一matches one of the inner grouping entities
开罗Cairo 匹配内层分组实体之一matches one of the inner grouping entities

带有可选语法的组的嵌套限制Nesting limits for groups with optional syntax

分组可选语法组合的嵌套级别限制为 3。A combination of grouping with optional syntax has a limit of 3 nesting levels.

允许Allowed 示例Example
Yes ( [ ( test1 | test2 ) ] | test3 )( [ ( test1 | test2 ) ] | test3 )
No ( [ ( [ test1 ] | test2 ) ] | test3 )( [ ( [ test1 ] | test2 ) ] | test3 )

带有 or-ing 语法的组的嵌套限制Nesting limits for groups with or-ing syntax

分组or-ing 语法组合的竖线限制为 2。A combination of grouping with or-ing syntax has a limit of 2 vertical bars.

允许Allowed 示例Example
Yes ( test1 | test2 | ( test3 | test4 ) )( test1 | test2 | ( test3 | test4 ) )
No ( test1 | test2 | test3 | ( test4 | test5 ) )( test1 | test2 | test3 | ( test4 | test5 ) )

用于向模式模板添加实体的语法Syntax to add an entity to a pattern template

要向模式模板添加实体,需用花括号将实体名称括起,比如 Who does {Employee} manage?To add an entity into the pattern template, surround the entity name with curly braces, such as Who does {Employee} manage?.

模式与实体Pattern with entity
Who does {Employee} manage?

用于向模式模板添加实体和角色的语法Syntax to add an entity and role to a pattern template

实体角色表示为 {entity:role}其中实体名称后接一个冒号,再接角色名称。An entity role is denoted as {entity:role} with the entity name followed by a colon, then the role name. 要向模式模板添加带角色的实体,需用花括号将实体名称和角色名称括起,比如 Book a ticket from {Location:Origin} to {Location:Destination}To add an entity with a role into the pattern template, surround the entity name and role name with curly braces, such as Book a ticket from {Location:Origin} to {Location:Destination}.

模式与实体角色Pattern with entity roles
Book a ticket from {Location:Origin} to {Location:Destination}

用于向模式模板添加 pattern.any 的语法Syntax to add a pattern.any to pattern template

Pattern.any 实体可用于向模式添加不同长度的实体。The Pattern.any entity allows you to add an entity of varying length to the pattern. 只要按照模式模板操作,pattern.any 即可为任意长度。As long as the pattern template is followed, the pattern.any can be any length.

要向模式模板添加 Pattern.any 实体,需用花括号将 Pattern.any 实体括起,比如 How much does {Booktitle} cost and what format is it available in?To add a Pattern.any entity into the pattern template, surround the Pattern.any entity with the curly braces, such as How much does {Booktitle} cost and what format is it available in?.

模式与 Pattern.any 实体Pattern with Pattern.any entity
How much does {Booktitle} cost and what format is it available in?
模式中的书名Book titles in the pattern
《偷书》的价格是多少?它适合哪种格式 ?How much does steal this book cost and what format is it available in?
《询问》的价格是多少?它适合哪种格式 ?How much does ask cost and what format is it available in?
《深夜小狗神秘事件》的价格是多少?它适合哪种格式 ?How much does The Curious Incident of the Dog in the Night-Time cost and what format is it available in?

对于 LUIS 而言,书名的字词不容易混淆,因为 LUIS 可以根据 Pattern.any 实体知道书名在哪里结尾。The words of the book title are not confusing to LUIS because LUIS knows where the book title ends, based on the Pattern.any entity.

显式列表Explicit lists

在以下情况下请通过创作 API 创建一个显式列表来允许例外:create an Explicit List through the authoring API to allow the exception when:

  • 你的模式包含 Pattern.anyYour pattern contains a Pattern.any
  • 并且该模式语法可能会基于话语提取不正确的实体。And that pattern syntax allows for the possibility of an incorrect entity extraction based on the utterance.

例如,假设你的模式中包含可选语法 [] 和实体语法 {},两个语法的组合方式导致数据提取错误。For example, suppose you have a pattern containing both optional syntax, [], and entity syntax, {}, combined in a way to extract data incorrectly.

请考虑使用模式“[find] email about {subject} [from {person}]”。Consider the pattern `[find] email about {subject} [from {person}]'.

在下面的话语中,主题和人员实体一个提取正确,一个提取错误 :In the following utterances, the subject and person entity are extracted correctly and incorrectly:

话语Utterance 实体Entity 提取是否正确Correct extraction
email about dogs from Chrisemail about dogs from Chris subject=dogssubject=dogs
person=Chrisperson=Chris
email about the man from La Manchaemail about the man from La Mancha subject=the mansubject=the man
person=La Manchaperson=La Mancha
XX

在上表中,主题应当是 the man from La Mancha(书名),但因为主题包含可选字词 from,因此书名没有正确预测。In the preceding table, the subject should be the man from La Mancha (a book title) but because the subject includes the optional word from, the title is incorrectly predicted.

要避免模式出现此异常,需使用显式列表的创作 API 添加 the man from la mancha 作为 {subject} 实体的显式列表匹配。To fix this exception to the pattern, add the man from la mancha as an explicit list match for the {subject} entity using the authoring API for explicit list.

用于在模板话语中标记可选文本的语法Syntax to mark optional text in a template utterance

使用正则表达式方括号语法 [] 标出话语中的可选文本。Mark optional text in the utterance using the regular expression square bracket syntax, []. 最多能对两个括号使用方括号嵌套可选文本。The optional text can nest square brackets up to two brackets only.

模式与可选的文本Pattern with optional text 含义Meaning
[find] email about {subject} [from {person}] findfrom {person} 是可选的find and from {person} are optional
`你可以帮我吗[?]`Can you help me[?] 问号是可选的The punctuation mark is optional

标点符号(?!.)应当忽略,并且你需要在模式中使用方括号语法来忽略它们。Punctuation marks (?, !, .) should be ignored and you need to ignore them using the square bracket syntax in patterns.

后续步骤Next steps

详细了解模式:Learn more about patterns: