public static int?FirstOrDefaultAgeResolution(this LuisV2Entity luisV2) { //extract the integer from the entity text if (luisV2.Resolution.ContainsKey("unit") && luisV2.Resolution.ContainsKey("value")) { var oUnit = luisV2.Resolution["unit"]; var oValu = luisV2.Resolution["value"]; if (oUnit != null && oValu != null && oUnit.ToString() == "Year" && int.TryParse(oValu.ToString(), out var i)) { return(i); } } return(null); }
public static LuisV2Entity SelectTopScore(this IEnumerable <LuisV2Entity> entities, string type) { LuisV2Entity result = null; double? topScore = null; foreach (var entity in entities.Where(item => item.Type == type)) { if (entity.Score > topScore || topScore == null) { topScore = entity.Score; result = entity; } } return(result); }
public static int?EntityAsInt(this LuisV2Entity luisV2) { //extract the integer from the entity text var match = System.Text.RegularExpressions.Regex.Match(luisV2.Entity, @"\d{1,2}"); if (match.Success) { var resultString = match.Value; if (!string.IsNullOrEmpty(resultString) && int.TryParse(resultString, out var i)) { return(i); } } return(null); }