在预测之前或预测期间更改话语数据Alter utterance data before or during prediction

LUIS 提供在预测之前或预测期间操作陈述的方法。LUIS provides ways to manipulate the utterance before or during the prediction. 这些方法包括修复预生成 datetimeV2 的时区问题。These include fixing timezone issues for prebuilt datetimeV2.

更改预生成 datetimeV2 实体的时区Change time zone of prebuilt datetimeV2 entity

LUIS 应用使用预生成的 datetimeV2 实体时,可以在预测响应中返回日期/时间值。When a LUIS app uses the prebuilt datetimeV2 entity, a datetime value can be returned in the prediction response. 请求的时区用于确定要返回的正确日期/时间。The timezone of the request is used to determine the correct datetime to return. 如果请求在到达 LUIS 之前来自机器人或另一个集中式应用程序,则更正 LUIS 使用的时区。If the request is coming from a bot or another centralized application before getting to LUIS, correct the timezone LUIS uses.

用于更改时区的 V3 预测 APIV3 prediction API to alter timezone

在 V3 中,datetimeReference 确定时区偏移量。In V3, the datetimeReference determines the timezone offset. 请详细了解 V3 预测Learn more about V3 predictions.

用于更改时区的 V2 预测 APIV2 prediction API to alter timezone

可以通过以下方式更正时区:根据 API 版本,使用 timezoneOffset 参数将用户的时区添加到终结点。The timezone is corrected by adding the user's timezone to the endpoint using the timezoneOffset parameter based on the API version. 要更改时间,此参数值应为正数或负数(以分钟为单位)。The value of the parameter should be the positive or negative number, in minutes, to alter the time.

V2 预测夏令时示例V2 prediction daylight savings example

如果需要返回的预生成 datetimeV2 来调整夏令时,则应对该终结点查询使用值为正数/负数(以分钟为单位)的 querystring 参数。If you need the returned prebuilt datetimeV2 to adjust for daylight savings time, you should use the querystring parameter with a +/- value in minutes for the endpoint query.

增加 60 分钟:Add 60 minutes:

https://{region}.api.cognitive.azure.cn/luis/v2.0/apps/{appId}?q=Turn the lights on?timezoneOffset=60&verbose={boolean}&spellCheck={boolean}&staging={boolean}&bing-spell-check-subscription-key={string}&log={boolean}

减去 60 分钟:Remove 60 minutes:

https://{region}.api.cognitive.azure.cn/luis/v2.0/apps/{appId}?q=Turn the lights on?timezoneOffset=-60&verbose={boolean}&spellCheck={boolean}&staging={boolean}&bing-spell-check-subscription-key={string}&log={boolean}

V2 预测 C# 代码确定正确的参数值V2 prediction C# code determines correct value of parameter

下面的 C# 代码使用 TimeZoneInfo 类的 FindSystemTimeZoneById 方法基于系统时间来确定正确的偏移值:The following C# code uses the TimeZoneInfo class's FindSystemTimeZoneById method to determine the correct offset value based on system time:

// Get CST zone id
TimeZoneInfo targetZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");

// Get local machine's value of Now
DateTime utcDatetime = DateTime.UtcNow;

// Get Central Standard Time value of Now
DateTime cstDatetime = TimeZoneInfo.ConvertTimeFromUtc(utcDatetime, targetZone);

// Find timezoneOffset/datetimeReference
int offset = (int)((cstDatetime - utcDatetime).TotalMinutes);