預測之前或預測期間變更語句資料Alter utterance data before or during prediction

LUIS 提供可在預測之前或預測期間操作語句的方法。LUIS provides ways to manipulate the utterance before or during the prediction. 其中包括修正拼寫,以及修正預先建立之datetimeV2的時區問題。These include fixing spelling, and fixing timezone issues for prebuilt datetimeV2.

校正語句中的拼字錯誤Correct spelling errors in utterance

警告

在預測端點的 V3 API 中不支援這項功能。This feature is not supported in the V3 API for prediction endpoints.

LUIS 使用 Bing 拼字檢查 API V7 來校正語句中的拼字錯誤。LUIS uses Bing Spell Check API V7 to correct spelling errors in the utterance. LUIS 需要與該服務相關的金鑰。LUIS needs the key associated with that service. 請建立金鑰,然後在端點新增該金鑰作為查詢字串參數。Create the key, then add the key as a querystring parameter at the endpoint.

端點必須有兩個參數,才能讓拼字校正運作:The endpoint requires two params for spelling corrections to work:

ParamParam Value
spellCheck booleanboolean
bing-spell-check-subscription-key Bing 拼字檢查 API V7 端點金鑰Bing Spell Check API V7 endpoint key

Bing 拼字檢查 API V7 偵測到錯誤時,系統會將原始語句和校正後語句及預測一起從端點傳回。When Bing Spell Check API V7 detects an error, the original utterance, and the corrected utterance are returned along with predictions from the endpoint.

{
  "query": "Book a flite to London?",
  "alteredQuery": "Book a flight to London?",
  "topScoringIntent": {
    "intent": "BookFlight",
    "score": 0.780123
  },
  "entities": []
}

允許的單字清單List of allowed words

LUIS 中使用的 Bing 拼寫檢查 API 不支援在拼寫檢查改變期間忽略的字詞清單。The Bing spell check API used in LUIS does not support a list of words to ignore during the spell check alterations. 如果您需要允許單字或縮略字清單,請先處理用戶端應用程式中的語句,再將語句傳送至 LUIS 進行意圖預測。If you need to allow a list of words or acronyms, process the utterance in the client application before sending the utterance to LUIS for intent prediction.

變更預先建置 datetimeV2 實體的時區Change time zone of prebuilt datetimeV2 entity

當 LUIS 應用程式使用預先建立的datetimeV2實體時,可以在預測回應中傳回 datetime 值。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. 如果要求來自 Bot 或另一個集中式應用程式,請在其抵達 LUIS 之前,先更正 LUIS 使用的時區。If the request is coming from a bot or another centralized application before getting to LUIS, correct the timezone LUIS uses.

端點查詢字串參數Endpoint querystring parameter

更正時區的方式是使用 timezoneOffset 參數將使用者時區新增至端點The timezone is corrected by adding the user's timezone to the endpoint using the timezoneOffset param. timezoneOffset 的值應該是用以變更時間的正數或負數 (以分鐘為單位)。The value of timezoneOffset should be the positive or negative number, in minutes, to alter the time.

ParamParam Value
timezoneOffset 正數或負數 (以分鐘為單位)positive or negative number, in minutes

日光節約範例Daylight savings example

如果您需要讓傳回的預先建置 datetimeV2 針對日光節約時間進行調整,則應該針對端點查詢,使用 timezoneOffset 查詢字串參數搭配以分鐘為單位的 +/- 值。If you need the returned prebuilt datetimeV2 to adjust for daylight savings time, you should use the timezoneOffset querystring parameter with a +/- value in minutes for the endpoint query.

增加 60 分鐘:Add 60 minutes:

https://{region}.api.cognitive.microsoft.com/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}https://{region}.api.cognitive.microsoft.com/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.microsoft.com/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}https://{region}.api.cognitive.microsoft.com/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}

C# 程式碼可判斷 timezoneOffset 的正確值C# code determines correct value of timezoneOffset

下列 C# 程式碼使用 TimeZoneInfo 類別的 FindSystemTimeZoneById 方法,根據系統時間判斷正確的 timezoneOffsetThe following C# code uses the TimeZoneInfo class's FindSystemTimeZoneById method to determine the correct timezoneOffset 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
int timezoneOffset = (int)((cstDatetime - utcDatetime).TotalMinutes);

後續步驟Next steps