예제 #1
0
 public void Add(SynonymDto item)
 {
     _synonymReopsitory.Insert(new Synonym
     {
         Term        = item.Term,
         SynonymList = string.Join(",", item.Synonyms)
     });
 }
예제 #2
0
        public async Task <IActionResult> Post(SynonymDto synonym)
        {
            var result = await _synonymBusiness.CreateAsync(synonym);

            if ((result?.Id ?? 0) != 0)
            {
                return(Created("", result.Id));
            }
            return(BadRequest());
        }
예제 #3
0
        public void Post([FromBody] SynonymDto value)

        {
            if (value.Synonyms != null && value.Term != null)
            {
                try
                {
                    var synonyms = value.Synonyms.Split(',');
                    if (synonyms.FirstOrDefault(x => x == value.Term) == null)
                    {
                        db.SynonymDtoes.Add(value);
                        db.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Exception caught.", e);
                }
            }
        }
예제 #4
0
 public async Task <IActionResult> Put(int id, SynonymDto synonym)
 {
     return(Ok(await _synonymBusiness.UpdateAsync(id, synonym)));
 }
        public async Task <SynonymDto> UpdateAsync(int id, SynonymDto synonym)
        {
            await DeleteAsync(id);

            return(await CreateAsync(synonym));
        }
 public async Task <SynonymDto> CreateAsync(SynonymDto synonym)
 {
     return(_synonymMapper.ConvertToDto(
                await _synonymRepository.CreateAsync(
                    _synonymMapper.ConvertToEntity(synonym))));
 }
예제 #7
0
        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));
        }