2017-07-18 38 views
-1

我試圖從一個timex鍵來的LUIS響應中獲取日期,但我只能設法進入列表並無法將其轉換回字典。 有沒有辦法達到鍵值對。LUIS Timex日期

private const string EntityCustomerID = "CustomerID"; 
private const string EntityDateOfBirth = "builtin.datetimeV2.date"; 
private const string EntityNumber = "builtin.number"; 
private const string DateKeyName = "timex"; 
private const string ResolutionKeyName = "values"; 




public async Task Verification(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result) 
     { 
      var message = ""; 
      EntityRecommendation customerIdEntityRecommendation; 
      EntityRecommendation customerDobEntityRecommendation; 

      if(result.TryFindEntity(EntityCustomerID, out customerIdEntityRecommendation)) 
      { 
       message = $"Your customer ID is '{customerIdEntityRecommendation.Entity}'"; 
      } 

      if (result.TryFindEntity(EntityDateOfBirth, out customerDobEntityRecommendation)) 
      { 
       object dateObject; 

       if (customerDobEntityRecommendation.Resolution.TryGetValue(ResolutionKeyName, out dateObject)) 
       { 

        IEnumerable enumerable = dateObject as IEnumerable; 
        if(enumerable != null) 
        { 

         foreach (object element in enumerable) 
         { 

         } 
        } 
        //string dateString = (string)dateObject; 
        //string dateTransformed = DateTime.ParseExact(dateString, "yyyy-MM-dd", null).ToString("MM/dd/yyyy"); 
        //message = dateTransformed; 

       } 
      } 
      await context.PostAsync(message); 
      context.Wait(MessageReceived); 
     } 

編輯1:我找到了一種通過使用下面的代碼

foreach (object element in enumerable) 
{ 
var jObject = (JObject)element; 
var dict = jObject.ToObject<Dictionary<string, object>>(); 
var timexValue = dict[DateKeyName]; 
} 
+0

標記時,請小心,這顯然是C#語法(改變了它你) –

+0

@FelixPalmen我幾乎可以發誓,我已經選擇了C#,它可能是一個誠實的人的錯誤。感謝您糾正。 – user6083088

+0

這是你在找什麼=> https://github.com/Microsoft/BotBuilder/pull/2964? –

回答

2

對此問題進行修復正在討論here得到的日期。與此同時,您可以嘗試重新使用fix的代碼。喜歡的東西:

var children = myArray.Children(); 

if (children.Count() == 1) 
{ 
     return children.First().ToObject<IDictionary<string, object>>(); 
} 
else if (children.Count() > 0) 
{ 
     return children.Select(c => c.ToObject<IDictionary<string, object>>()).ToList(); 
} 
+0

我會盡我所能。我不確定重新調整目的是什麼意思。我對C#非常陌生# – user6083088

+1

以修復程序的代碼並使其適用於您的方案。 –

+0

如何更新代碼,是不是鎖定在DLL中 - 我在這裏錯過了什麼? – user6083088