类型
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
通过类型,您可以配置 Google 助理 NLU(自然语言理解)
引擎从用户输入中提取结构化数据。您
可以在以下情况下使用类型:
在意图中,您可以使用类型为训练短语添加注解,
创建槽。当用户说出与广告位匹配的内容时,NLU 引擎
会将其作为类型化参数提取,以便您在场景中对其进行处理。
在场景的“槽位填充”阶段中,您可以指定
您希望用户先提供多个广告位
过渡或退出场景
在场景的 conditions 阶段中,您可以
判断参数是否具有某个类型中定义的特定值的逻辑。
自定义类型
借助自定义类型,您可以创建自己的类型规范,以通知 NLU
为单个键分配一组值。您可以指定各种类型
方式:
- 字词和同义词允许您将多个值映射到单个键,
称为条目您的类型可以包含一个或多个条目。如果您
选择此选项,还可以启用以下 NLU 设置:
<ph type="x-smartling-placeholder">
</ph>
- 启用模糊匹配 - 此功能允许具有多个
即使这些字词的发音顺序不同也是如此。
- 接受未知值 - 当您不能指定所有可能的值时,
语言处理器可以根据上下文接受未知的字词或短语
输入和意图训练数据,例如可能添加到杂货店的物品
列表。
- 正则表达式允许类型使用正则表达式来匹配值
表达式模式,
Google 的 RE2 标准。
- 自由格式文本允许类型匹配
用户所说的内容正在添加注释
一个具有此类型的 intent 可以将所有输入用作参数,
可以通过管道传送到您自己的 NLU。
系统类型
通过系统类型,您可以为已知数据添加注释并从用户输入中提取已知数据
使用系统提供的训练数据和值进行训练。以下系统类型
支持:
类型 |
说明 |
actions.type.DateTime |
包含基于用户设备设置的日期、时间和时区。
可用于槽位填充和训练短语注释。
|
actions.type.Date |
仅包含日期。仅适用于槽位填充。 |
actions.type.Time |
仅包含时间。仅适用于槽位填充。 |
actions.type.Number |
Number 类型与序数和基数匹配
数字。 |
DateTime
、Date
和 Time
用量
这些类型的行为因您使用类型的位置和
与类型匹配的用户输入。
与 intent 配合使用
在 intent 中为训练短语添加注释仅支持 DateTime
类型。用户
输入无需与整个 DateTime
值匹配。例如,如果用户
只提供年份,则 session 参数可能如下所示:
"date_time": {
"year": 2019
}
与槽填充搭配使用
槽填充支持 DateTime
、Date
和 Time
。
- 如果槽类型为
DateTime
,Google 助理会提示用户,直到满了
值。
- 如果槽类型为
Date
,Google 助理会在指定日期之前提示用户
值。收集参数后,您收到的参数是完整的
DateTime
(时间设置为 00:00)。
- 如果槽类型为
Time
,Google 助理会持续提示用户
值。收集后,您收到的参数是完整的
DateTime
对象,其日期设置为当前日期。
例如,假设位于洛杉矶的用户说:“Hey Google,创建一条提醒
“2024 年 1 月 15 日晚上 8 点”将 DateTime
作为槽的一部分提取时
填充过程,则完整参数可能如下所示:
"date_time": {
"day": 15,
"hours": 20,
"minutes": 0,
"month": 1,
"nanos": 0,
"seconds": 0,
"time_zone": {
"id": "America/Los_Angeles"
},
"year": 2024
}
使用 with 条件
条件只允许使用数字和字符串,因此使用顶级
使用 DateTime
参数为该条件返回 False 结果。例如:
$session.params.my_dateTime.day > 5
是有效条件,因为
“day
”的值是一个数字且受支持。
$session.params.my_dateTime > "01-01-2010"
是无效条件,因为
顶级“日期时间”列对象不是数字或字符串。
运行时类型替换项
通过运行时类型替换,您可以在
fulfillment。借助此功能,您可以在
运行时。例如,您可以查看后端数据源以加载每日菜单
转换为履单中的一个类型。
有关详情,请参阅网络钩子指南
了解如何构建类型替换项。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003eTypes are used to extract structured data from user input, allowing you to create slots in intents, manage slot filling within scenes, and define conditions based on parameter values.\u003c/p\u003e\n"],["\u003cp\u003eYou can create custom types using words and synonyms, regular expressions, or free-form text to define how the NLU interprets user input.\u003c/p\u003e\n"],["\u003cp\u003eSystem types such as \u003ccode\u003eDateTime\u003c/code\u003e, \u003ccode\u003eDate\u003c/code\u003e, \u003ccode\u003eTime\u003c/code\u003e, and \u003ccode\u003eNumber\u003c/code\u003e provide built-in data extraction for common data formats.\u003c/p\u003e\n"],["\u003cp\u003eRuntime type overrides enable dynamic modification of types during fulfillment, allowing you to adjust types based on real-time data.\u003c/p\u003e\n"]]],[],null,["# Types let you configure the Assistant NLU (natural language understanding)\nengine to extract structured data from user input. You\ncan use types in the following situations:\n\n- In [intents](/assistant/conversational/intents), you can annotate training phrases with types to\n create slots. When users say something that matches a slot, the NLU engine\n extracts it as a typed parameter, so you can process it in a [scene](/assistant/conversational/scenes).\n\n- Within a scene's [slot filling](/assistant/conversational/scenes#slot_filling) stage, you can specify\n multiple slots that you want the user to provide before they can\n transition or exit out of the scene.\n\n- Within a scene's [conditions](/assistant/conversational/scenes#conditions) stage, you can base\n logic on whether a parameter has a specific value that's defined in a type.\n\nCustom types\n------------\n\nCustom types let you create your own type specification to notify the NLU to\nassign a set of values to a single key. You can specify types in a variety of\nways:\n\n- **Words and synonyms** allow you to map multiple values to a single key, which are called an entry. Your type can contain one or many entries. If you choose this option, you can also enable the following NLU settings:\n - **Enable fuzzy matching** - This feature allows entries with more than one word to be matched, even when the words are spoken in a different order.\n - **Accept unknown values** - When you can't specify all possible values, the language processor can accept unknown words or phrases based on surrounding input and intent training data, such as items that might be added to a grocery list.\n- **Regular expressions** allows the type to match values using regular expression patterns based on [Google's RE2 standard](https://github.com/google/re2/wiki/Syntax).\n- **Free form text** allows the type to match anything a user says. Annotating an intent with this type lets you consume all input as a parameter that you can pipe to your own NLU.\n\nSystem types\n------------\n\nSystem types let you annotate and extract well-known data from user input\nusing system-provided training data and values. The following system types are\nsupported:\n\n| Type | Description |\n|-----------------------------|-----------------------------------------------------------------------------------------------------------------------------------|\n| **`actions.type.DateTime`** | Contains date, time, and timezone based on the user's device settings. Available for slot filling and training phrase annotation. |\n| **`actions.type.Date`** | Contains date only. Available for slot filling only. |\n| **`actions.type.Time`** | Contains time only. Available for slot filling only. |\n| **`actions.type.Number`** | The `Number` type matches ordinal and cardinal numbers. |\n\n### `DateTime`, `Date`, and `Time` usage\n\nThese types behave differently depending on where you use the type and the\nuser input that matches the type.\n\n#### Using with intents\n\nAnnotating training phrases in intents supports only the `DateTime` type. User\ninput doesn't need to match an entire `DateTime` value. For example, if a user\nprovides only the year, the session parameter might look like this: \n\n \"date_time\": {\n \"year\": 2019\n }\n\n#### Using with slot filling\n\nSlot filling supports `DateTime`, `Date`, and `Time`.\n\n- If the slot type is `DateTime`, the Assistant prompts the user until a full value is provided.\n- If the slot type is `Date`, the Assistant prompts the user until a date value is provided. When collected, the parameter you receive is a full `DateTime` with the time set to 00:00.\n- If the slot type is `Time`, the Assistant prompts the user until a time value is provided. When collected, the parameter your receive is a full `DateTime` object with the date set to the current date.\n\nFor example, suppose a user in Los Angeles said, \"Hey Google, create a reminder\nfor January 15, 2024 at 8 pm.\" When `DateTime` is extracted as part of a slot\nfilling process, the full parameter might look like this: \n\n \"date_time\": {\n \"day\": 15,\n \"hours\": 20,\n \"minutes\": 0,\n \"month\": 1,\n \"nanos\": 0,\n \"seconds\": 0,\n \"time_zone\": {\n \"id\": \"America/Los_Angeles\"\n },\n \"year\": 2024\n }\n\n#### Using with conditions\n\nConditions only allow the use of numbers and strings, so using the top level\n`DateTime` parameter results in a **False** result for the condition. For\nexample:\n\n- `$session.params.my_dateTime.day \u003e 5` is a valid condition, because the `day` value is a number and is supported.\n- `$session.params.my_dateTime \u003e \"01-01-2010\"` is an invalid condition, because the top level 'DateTime' object is not a number or string.\n\nRuntime type overrides\n----------------------\n\nRuntime type overrides let you dynamically create or modify types in\nfulfillment. This feature lets you add to or replace a type's specification at\nruntime. For example, you can check a backend data source to load daily menu\nitems into a type in your fulfillment.\n\nSee the [webhooks](/assistant/conversational/webhooks#runtime_type_overrides) guide for more information\non how to build type overrides."]]