Search code examples
c#botframeworkazure-language-understanding

Get canonical form from list entity


I have a bot using the Microsoft Bot Framework, using the LUIS API, and in it I have an entity that's a closed list. And I wanted to programmatically get its canonical form value when my bot catches an intent with that entity. But all I seem able to do is to get the value that the user typed, the synonym found.

foreach (var entity in result.Entities)
{
   await context.PostAsync($"{entity.Type}: {entity.Entity}");
}

Solution

  • Found a way to do it, using the comments and expanding on the answer from JasonSowers, had to travel on the dictionary and use a couple of casts but got around to it finally:

    foreach (var entity in result.Entities)
    {
       var dict = entity.Resolution.Values.GetEnumerator();
       dict.MoveNext();
       var valuesList = (List<object>)dict.Current;
       var canonicalForm = (string)valuesList[0];
    
       await context.PostAsync($"{canonicalForm}");
    }