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); }
private bool IsMessageDuplicated(NoteTemplateModel message) { string testMessage = $"{message.EventId}_{message.Note}".ToLower(); if (_previousMessageReceived == testMessage) { return(true); } _previousMessageReceived = testMessage; return(false); }
public async Task <string> CreateNoteTemplate(NoteTemplateModel noteTemplate) { RestRequest request = await PrepareQuery("Notes/Templates", Method.POST); request.AddParameter("application/json", JsonConvert.SerializeObject(noteTemplate), ParameterType.RequestBody); var result = await _client.ExecuteTaskAsync <string>(request); if (!result.IsSuccessful) { _logger.LogError($"CreateNoteTemplate: Error while creating a note template: {result.StatusCode}"); } return(result.Data); }