/// <summary> /// Try to find an entity within the result. /// </summary> /// <param name="result">The LUIS result.</param> /// <param name="type">The entity type.</param> /// <param name="entity">The found entity.</param> /// <returns>True if the entity was found, false otherwise.</returns> public static bool TryFindEntity(this LuisResult result, string type, out EntityRecommendation entity) { Func <EntityRecommendation, IList <EntityRecommendation>, bool> doesNotOverlapRange = (current, recommendations) => { return(!recommendations.Where(r => current != r) .Any(r => r.StartIndex.HasValue && r.EndIndex.HasValue && current.StartIndex.HasValue && r.StartIndex.Value <= current.StartIndex.Value && r.EndIndex.Value >= current.EndIndex.Value)); }; // find the recommended entity that does not overlap start and end ranges with other result entities entity = result.Entities?.Where(e => e.Type == type && doesNotOverlapRange(e, result.Entities)).FirstOrDefault(); return(entity != null); }
/// <summary> /// Try to find an entity within the result. /// </summary> /// <param name="result">The LUIS result.</param> /// <param name="type">The entity type.</param> /// <param name="entity">The found entity.</param> /// <returns>True if the entity was found, false otherwise.</returns> public static bool TryFindEntity(this LuisResult result, string type, out EntityRecommendation entity) { entity = result.Entities?.FirstOrDefault(e => e.Type == type); return(entity != null); }
public static string GetChildType(this EntityRecommendation ent) { return(ent.Type.Substring(ent.Type.IndexOf("::") + 2)); }
public static string GetParentType(this EntityRecommendation ent) { return(ent.Type.Substring(0, ent.Type.IndexOf("::"))); }
/// <summary> /// Finds by the parent type of the child entity /// </summary> /// <param name="result"></param> /// <param name="type"></param> /// <param name="entity"></param> /// <returns></returns> public static bool TryFindEntityEx(this LuisResult result, string type, out EntityRecommendation entity) { entity = result.Entities?.FirstOrDefault(e => e.Type.StartsWith(type + "::")); return(entity != null); }