LUIS 应用的 DatetimeV2 预生成实体DatetimeV2 prebuilt entity for a LUIS app

datetimeV2 预生成实体提取日期和时间值。The datetimeV2 prebuilt entity extracts date and time values. 将以标准化格式解析这些值,使客户端程序能够使用它们。These values resolve in a standardized format for client programs to consume. 当某条陈述包含不完整的日期或时间时,LUIS 会在终结点响应中包含过去的值和未来的值。When an utterance has a date or time that isn't complete, LUIS includes both past and future values in the endpoint response. 由于此实体已经过训练,因此不需要将包含 datetimeV2 的陈述示例添加到应用程序意向中。Because this entity is already trained, you do not need to add example utterances containing datetimeV2 to the application intents.

datetimeV2 的类型Types of datetimeV2

通过 Recognizers-text GitHub 存储库管理 DatetimeV2。DatetimeV2 is managed from the Recognizers-text GitHub repository.

示例 JSONExample JSON

下面显示了以下话语及其部分 JSON 响应。The following utterance and its partial JSON response is shown below.

8am on may 2nd 2019

"entities": {
    "datetimeV2": [
        {
            "type": "datetime",
            "values": [
                {
                    "timex": "2019-05-02T08",
                    "resolution": [
                        {
                            "value": "2019-05-02 08:00:00"
                        }
                    ]
                }
            ]
        }
    ]
}

datetimeV2 的子类型Subtypes of datetimeV2

datetimeV2 预生成实体具有以下子类型,后面的表中提供了每个子类型的示例:The datetimeV2 prebuilt entity has the following subtypes, and examples of each are provided in the table that follows:

  • date
  • time
  • daterange
  • timerange
  • datetimerange

解析值Values of resolution

  • 如果陈述中的日期或时间已完全指定且没有歧义,则数组包含一个元素。The array has one element if the date or time in the utterance is fully specified and unambiguous.
  • 如果 datetimeV2 值歧义,则数组包含两个元素。The array has two elements if the datetimeV2 value is ambiguous. 歧义性包括缺少特定的年份、时间或时间范围。Ambiguity includes lack of specific year, time, or time range. 有关示例,请参阅歧义日期See Ambiguous dates for examples. 当时间在 A.M. 或 P.M. 方面存在歧义时,When the time is ambiguous for A.M. 会包含这两个值。or P.M., both values are included.
  • 如果陈述包含两个有歧义的元素,则数组包含四个元素。The array has four elements if the utterance has two elements with ambiguity. 这种歧义性包括具有以下特征的元素:This ambiguity includes elements that have:
    • 日期或日期范围在年份方面存在歧义A date or date range that is ambiguous as to year
    • 日期或日期范围在 A.M. 或A time or time range that is ambiguous as to A.M. P.M. 方面存在歧义or P.M. 例如,4 月 3 日 3:00。For example, 3:00 April 3rd.

values 数组的每个元素可以包含以下字段:Each element of the values array may have the following fields:

属性名称Property name 属性说明Property description
timextimex 遵循 ISO 8601 标准的、以 TIMEX 格式表示的时间、日期或日期范围,以及使用 TimeML 语言的注释的 TIMEX3 属性。time, date, or date range expressed in TIMEX format that follows the ISO 8601 standard and the TIMEX3 attributes for annotation using the TimeML language.
modmod 术语,用于说明如何使用 beforeafter 等值。term used to describe how to use the value such as before, after.
typetype 子类型,可以是下述项目之一:datetimedatetimedaterangetimerangedatetimerangedurationsetThe subtype, which can be one of the following items: datetime, date, time, daterange, timerange, datetimerange, duration, set.
valuevalue 可选。Optional. 采用 yyyy-MM-dd(日期)、HH:mm:ss(时间)、yyyy-MM-dd HH:mm:ss(日期/时间)格式的日期/时间对象。A datetime object in the Format yyyy-MM-dd (date), HH:mm:ss (time) yyyy-MM-dd HH:mm:ss (datetime). 如果 typeduration,则值是秒数(持续时间)If type is duration, the value is the number of seconds (duration)
仅当 typedatetimedatetime 或 `duration 时才使用。Only used if type is datetime or date, time, or `duration.

有效日期值Valid date values

datetimeV2 支持以下范围内的日期:The datetimeV2 supports dates between the following ranges:

MinMin MaxMax
1900 年 1 月 1 日1st January 1900 2099 年 12 月 31 日31st December 2099

歧义日期Ambiguous dates

如果日期可以是过去或未来的日期,则 LUIS 会提供这两个值。If the date can be in the past or future, LUIS provides both values. 包括年份中的月份和日期的陈述就是一个例子。An example is an utterance that includes the month and date without the year.

例如,给定以下话语:For example, given the following utterance:

May 2nd

  • 如果今天的日期是 2017 年 5 月 3 日,则 LUIS 会提供“2017-05-02”和“2018-05-02”作为值。If today's date is May 3rd 2017, LUIS provides both "2017-05-02" and "2018-05-02" as values.
  • 如果今天的日期是 2017 年 5 月 1 日,则 LUIS 会提供“2016-05-02”和“2017-05-02”作为值。When today's date is May 1st 2017, LUIS provides both "2016-05-02" and "2017-05-02" as values.

以下示例显示了实体“5 月 2 日”的解析。The following example shows the resolution of the entity "may 2nd". 此解析假设今天的日期是 2017 年 5 月 2 日和 2018 年 5 月 1 日之间的某个日期。This resolution assumes that today's date is a date between May 2nd 2017 and May 1st 2018. timex 字段中包含 X 的字段是未在陈述中显式指定的日期的一部分。Fields with X in the timex field are parts of the date that aren't explicitly specified in the utterance.

日期解析示例Date resolution example

下面显示了以下话语及其部分 JSON 响应。The following utterance and its partial JSON response is shown below.

May 2nd

"entities": {
    "datetimeV2": [
        {
            "type": "date",
            "values": [
                {
                    "timex": "XXXX-05-02",
                    "resolution": [
                        {
                            "value": "2019-05-02"
                        },
                        {
                            "value": "2020-05-02"
                        }
                    ]
                }
            ]
        }
    ]
}

数字日期的日期范围解析示例Date range resolution examples for numeric date

datetimeV2 实体提取日期和时间范围。The datetimeV2 entity extracts date and time ranges. startend 字段指定范围的开始和结束。The start and end fields specify the beginning and end of the range. 对于话语 May 2nd to May 5th,LUIS 会提供当年和下一年的 daterange 值。For the utterance May 2nd to May 5th, LUIS provides daterange values for both the current year and the next year. timex 字段中,XXXX 值指示年份的歧义性。In the timex field, the XXXX values indicate the ambiguity of the year. P3D 指示时间段为三天。P3D indicates the time period is three days long.

下面显示了以下话语及其部分 JSON 响应。The following utterance and its partial JSON response is shown below.

May 2nd to May 5th


"entities": {
    "datetimeV2": [
        {
            "type": "daterange",
            "values": [
                {
                    "timex": "(XXXX-05-02,XXXX-05-05,P3D)",
                    "resolution": [
                        {
                            "start": "2019-05-02",
                            "end": "2019-05-05"
                        },
                        {
                            "start": "2020-05-02",
                            "end": "2020-05-05"
                        }
                    ]
                }
            ]
        }
    ]
}

星期日期的日期范围解析示例Date range resolution examples for day of week

以下示例演示 LUIS 如何使用 datetimeV2 来解析话语 Tuesday to ThursdayThe following example shows how LUIS uses datetimeV2 to resolve the utterance Tuesday to Thursday. 在此示例中,当前日期为 6 月 19 日。In this example, the current date is June 19th. LUIS 为当前日期前面和后面的日期范围包含 daterange 值。LUIS includes daterange values for both of the date ranges that precede and follow the current date.

下面显示了以下话语及其部分 JSON 响应。The following utterance and its partial JSON response is shown below.

Tuesday to Thursday

"entities": {
    "datetimeV2": [
        {
            "type": "daterange",
            "values": [
                {
                    "timex": "(XXXX-WXX-2,XXXX-WXX-4,P2D)",
                    "resolution": [
                        {
                            "start": "2019-10-08",
                            "end": "2019-10-10"
                        },
                        {
                            "start": "2019-10-15",
                            "end": "2019-10-17"
                        }
                    ]
                }
            ]
        }
    ]
}

歧义时间Ambiguous time

如果时间或时间范围歧义,values 数组将包含两个 time 元素。The values array has two time elements if the time, or time range is ambiguous. 如果存在歧义的时间,则 values 包含 A.M.When there's an ambiguous time, values have both the A.M. 和 P.M.and P.M. 时间。times.

时间范围解析示例Time range resolution example

DatetimeV2 JSON 响应在 API V3 中已更改。DatetimeV2 JSON response has changed in the API V3. 以下示例演示 LUIS 如何使用 datetimeV2 来解析包含时间范围的陈述。The following example shows how LUIS uses datetimeV2 to resolve the utterance that has a time range.

自 API V2 以来的更改:Changes from API V2:

  • datetimeV2.timex.type 属性不再返回,因为它在父级别 datetimev2.type 返回。datetimeV2.timex.type property is no longer returned because it is returned at the parent level, datetimev2.type.
  • datetimeV2.value 属性已重名为 datetimeV2.timexThe datetimeV2.value property has been renamed to datetimeV2.timex.

下面显示了以下话语及其部分 JSON 响应。The following utterance and its partial JSON response is shown below.

from 6pm to 7pm

以下 JSON 的 verbose 参数设置为 falseThe following JSON is with the verbose parameter set to false:


"entities": {
    "datetimeV2": [
        {
            "type": "timerange",
            "values": [
                {
                    "timex": "(T18,T19,PT1H)",
                    "resolution": [
                        {
                            "start": "18:00:00",
                            "end": "19:00:00"
                        }
                    ]
                }
            ]
        }
    ]
}

时间解析示例Time resolution example

下面显示了以下话语及其部分 JSON 响应。The following utterance and its partial JSON response is shown below.

8am

"entities": {
    "datetimeV2": [
        {
            "type": "time",
            "values": [
                {
                    "timex": "T08",
                    "resolution": [
                        {
                            "value": "08:00:00"
                        }
                    ]
                }
            ]
        }
    ]
}

已弃用的预生成日期时间Deprecated prebuilt datetime

datetime 预生成实体已弃用,已由 datetimeV2 取代。The datetime prebuilt entity is deprecated and replaced by datetimeV2 .

若要在 LUIS 应用中将 datetime 替换为 datetimeV2,请完成以下步骤:To replace datetime with datetimeV2 in your LUIS app, complete the following steps:

  1. 打开 LUIS Web 界面的“实体”窗格。Open the Entities pane of the LUIS web interface.
  2. 删除 datetime 预生成实体。Delete the datetime prebuilt entity.
  3. 单击“添加预生成实体”Click Add prebuilt entity
  4. 选择“datetimeV2”并单击“保存”。 Select datetimeV2 and click Save .

后续步骤Next steps

详细了解 V3 预测终结点Learn more about the V3 prediction endpoint.

了解维度电子邮件实体和数字Learn about the dimension, email entities, and number.