예제 #1
0
        private async Task <NoteTemplateModel> FindBestNoteTemplate(string eventId, string message)
        {
            IEnumerable <NoteTemplateModel> noteTemplates = await _noteRestService.GetNoteTemplates(eventId);

            if (noteTemplates == null)
            {
                return(null);
            }

            NoteTemplateModel foundNote = noteTemplates.ToList().Find(p => p.Note.ToLower() == message.ToLower());

            if (foundNote != null)
            {
                return(foundNote);
            }

            Levenshtein       distanceTest                = new Levenshtein();
            double            minimumDistanceValue        = -1;
            NoteTemplateModel templateWithMinimumDistance = null;

            foreach (var noteTemplate in noteTemplates)
            {
                double currentDistance = distanceTest.Distance(message, noteTemplate.Note);
                if (minimumDistanceValue == -1 || minimumDistanceValue > currentDistance)
                {
                    minimumDistanceValue        = currentDistance;
                    templateWithMinimumDistance = noteTemplate;
                }
            }

            return(templateWithMinimumDistance);
        }
예제 #2
0
 public async Task <IEnumerable <NoteTemplateModel> > GetNoteTemplates(string eventId)
 {
     return(await _noteRestService.GetNoteTemplates(eventId));
 }