public AskMeChannel(string message, int node, int sessionId) { this.Message = message.ToLower(); this.Node = node; this.SessionId = sessionId; db = new ChatDatabaseModel(); hiBye = new AskMeHiBye(Message, Node); suggestionMatch = new AskMeSuggestionMatch(Message, Node); common = new AskMeCommon(Message, Node); zPossibleMatch = new AskMezPossibleMatch(Message, Node); synonymMatch = new AskMeSynonymMatch(Message, Node); }
public KeyValuePair <string, bool> SynonymMatch(List <string> vocabList, List <ChatIntent> intentList) { bool hasMatch = false; string responseMessage = contentManager.IntentPossibleMatchedResponse; int counter = 0; AskMezPossibleMatch possibleMatch = new AskMezPossibleMatch(Message, Node); LevenshteinDistance dist = new LevenshteinDistance(); TFIDF getVocab = new TFIDF(); List <string> responseList = new List <string>(); foreach (string vocab in vocabList) { string json; url = url + vocab; List <string> synonymList = new List <string>(); using (WebClient client = new WebClient()) { try { json = client.DownloadString(url); SynonymDto synonym = Newtonsoft.Json.JsonConvert.DeserializeObject <SynonymDto>(json); foreach (var def in synonym.def) { foreach (var tr in def.tr) { foreach (var mean in tr.mean) { synonymList.Add(mean.text); } } } } catch (Exception) { } } foreach (ChatIntent intent in intentList) { if (possibleMatch.CheckIfRedirect(intent, intentList)) { continue; } string intentDesc = intent.IntentDescription; List <string> intentvocabList = getVocab.GetVocabulary(intentDesc); bool hasSynonm = synonymList.Intersect(intentvocabList).Any(); if (hasSynonm && counter <= 3) { counter = counter + 1; responseList.Add(intentDesc); } } } responseList = (responseList.Count > 1) ? responseList.Distinct().Take(3).ToList() : responseList; foreach (string response in responseList) { responseMessage = responseMessage + "<br>"; responseMessage = responseMessage + response; } responseMessage = responseMessage + "<br>" + contentManager.IntentSuggestionResponse; if (counter > 0) { return(new KeyValuePair <string, bool>(responseMessage, true)); } return(new KeyValuePair <string, bool>(responseMessage, hasMatch)); }