コード例 #1
0
ファイル: Extensions.cs プロジェクト: Ram13234/chatbot
        /// <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);
        }
コード例 #2
0
ファイル: LuisResult.cs プロジェクト: nancysprojects/thirdbot
 /// <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);
 }
コード例 #3
0
ファイル: LUISExt.cs プロジェクト: eas2000/WCBot
 public static string GetChildType(this EntityRecommendation ent)
 {
     return(ent.Type.Substring(ent.Type.IndexOf("::") + 2));
 }
コード例 #4
0
ファイル: LUISExt.cs プロジェクト: eas2000/WCBot
 public static string GetParentType(this EntityRecommendation ent)
 {
     return(ent.Type.Substring(0, ent.Type.IndexOf("::")));
 }
コード例 #5
0
ファイル: LUISExt.cs プロジェクト: eas2000/WCBot
 /// <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);
 }