Important
语言理解智能服务(LUIS)将于 2026 年 3 月 31 日完全停用。 LUIS 资源创建不可用。 从 2025 年 10 月 31 日开始,LUIS 门户将不再可用。 我们建议迁移 LUIS 应用程序到对话语言理解,以便获得持续的产品支持和多语言功能并从中受益。
模式语法是一个话语模板。 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.
Caution
模式仅包括机器学习实体父项,而不包括子实体。
模式中的实体用花括号 {} 括起。 模式可包含实体和带角色的实体。 
              Pattern.any is an entity only used in patterns.
模式语法支持以下语法:
| Function | Syntax | Nesting level | Example | 
|---|---|---|---|
| 实体 | {} - 大括号 | 2 | 窗体 {entity-name} 在哪里? | 
| optional | [] - 方括号 可选和分组的任何组合的嵌套级别都限制为 3  | 
2 | 问号是可选的 [?] | 
| 分组 | () - 括号 | 2 | 是 (a | b) | 
| or | | - 竖线(管道) 一个组中的竖线限制为 2  | 
- | 表单的位置 ({form-name-short} |{form-name-long} |{form-number}) | 
| 话语的开头和/或结尾 | ^ - 脱字号 | - | ^开始话语 话语完成^ ^将整句话语与 {number} 实体进行严格的文本匹配^  | 
模式中的嵌套语法
The optional syntax, with square brackets, can be nested two levels. 例如:[[this]is] a new form。 此示例允许以下话语:
| 嵌套的可选话语示例 | Explanation | 
|---|---|
| 这是一个新窗体 | 匹配模式中的所有字词 | 
| 是一个新窗体 | 匹配模式中的外层可选字词和非可选字词 | 
| 一个新窗体 | 仅匹配必需的字词 | 
The grouping syntax, with parentheses, can be nested two levels. 例如:(({Entity1:RoleName1} | {Entity1:RoleName2} ) | {Entity2} )。 此功能允许匹配任意三个实体。
如果 Entity1 是具有起点(西雅图)和终点(开罗)等角色的位置,并且 Entity 2 是列表实体中的一座已知大楼名称 (RedWest-C),则以下话语将映射到此模式:
| 嵌套的分组话语示例 | Explanation | 
|---|---|
| RedWest-C | 匹配外层分组实体 | 
| Seattle | 匹配内层分组实体之一 | 
| Cairo | 匹配内层分组实体之一 | 
带有可选语法的组的嵌套限制
A combination of grouping with optional syntax has a limit of 3 nesting levels.
| Allowed | Example | 
|---|---|
| Yes | ( [ ( test1 | test2 ) ] | test3 ) | 
| No | ( [ ( [ [ test1 ] | test2 ) ] | test3 ) | 
带有 or-ing 语法的组的嵌套限制
A combination of grouping with or-ing syntax has a limit of 2 vertical bars.
| Allowed | Example | 
|---|---|
| Yes | ( test1 | test2 |(test3 | test4) | 
| No | ( test1 | test2 | test3 |(test4 | test5) | 
用于向模式模板添加实体的语法
要向模式模板添加实体,需用花括号将实体名称括起,比如 Who does {Employee} manage?。
| 模式与实体 | 
|---|
Who does {Employee} manage? | 
用于向模式模板添加实体和角色的语法
实体角色表示为 {entity:role}其中实体名称后接一个冒号,再接角色名称。 要向模式模板添加带角色的实体,需用花括号将实体名称和角色名称括起,比如 Book a ticket from {Location:Origin} to {Location:Destination}。
| 模式与实体角色 | 
|---|
Book a ticket from {Location:Origin} to {Location:Destination} | 
用于向模式模板添加 pattern.any 的语法
Pattern.any 实体可用于向模式添加不同长度的实体。 只要按照模式模板操作,pattern.any 即可为任意长度。
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 实体 | 
|---|
How much does {Booktitle} cost and what format is it available in? | 
| 模式中的书名 | 
|---|
| 《偷书》的价格是多少?它适合哪种格式 ? | 
| How much does ask cost and what format is it available in? | 
| 《深夜小狗神秘事件》的价格是多少?它适合哪种格式 ? | 
对于 LUIS 而言,书名的字词不容易混淆,因为 LUIS 可以根据 Pattern.any 实体知道书名在哪里结尾。
Explicit lists
create an Explicit List through the authoring API to allow the exception when:
- Your pattern contains a Pattern.any
 - 并且该模式语法可能会基于话语提取不正确的实体。
 
例如,假设你的模式中包含可选语法 [] 和实体语法 {},两个语法的组合方式导致数据提取错误。
请考虑使用模式“[find] email about {subject} [from {person}]”。
In the following utterances, the subject and person entity are extracted correctly and incorrectly:
| Utterance | Entity | Correct extraction | 
|---|---|---|
| 有关来自 Chris 的狗的电子邮件 | subject=dogs person=Chris  | 
✔ | 
| 有关拉曼查男子的电子邮件 | subject=the man person=La Mancha  | 
X | 
在上表中,主题应当是 the man from La Mancha(书名),但因为主题包含可选字词 from,因此书名没有正确预测。
要避免模式出现此异常,需使用the man from la mancha 添加  作为 {subject} 实体的显式列表匹配。
用于在模板话语中标记可选文本的语法
使用正则表达式方括号语法 [] 标出话语中的可选文本。 最多能对两个括号使用方括号嵌套可选文本。
| 模式与可选的文本 | Meaning | 
|---|---|
[find] email about {subject} [from {person}] | 
              find 和 from {person} 是可选的 | 
| `你可以帮我吗[?] | 问号是可选的 | 
标点符号(?、!、.)应当忽略,并且你需要在模式中使用方括号语法来忽略它们。
Next steps
详细了解模式:
Understand how sentiment is returned in the .json response.