//Step 2 //Busca todos os lugares no banco de dados //Compara os nomes de todos os lugares entre si para buscar similaridades (distancia de Levenshtein normalizada) //Insere no banco o resultado do calculo se for menor que 0.2 private static void RemoveSimilarVenues(IVenueService venueService, ILocationService locationService) { List <Venue> venuesToRemove = new List <Venue>(); List <Venue> venues = venueService.GetAll().ToList(); for (int i = 0; i < venues.Count - 1; i++) { int nextIndex = i + 1; venues[i].SimilarVenues = venues.GetRange(nextIndex, venues.Count - nextIndex) .Select(x => new VenueSimilarityDTO { Venue = new Venue { Id = x.Id, Name = x.Name } }) .ToList(); venues[i].CalculateNameSimilarity(); foreach (var similar in venues[i].SimilarVenues) { if (similar.Similarity <= (decimal)0.2) { venues[i].Location = locationService.GetByVenueId(venues[i].Id); similar.Venue.Location = locationService.GetByVenueId(similar.Venue.Id); if (venues[i].Location.CalculateDistance(similar.Venue.Location) < 100) { venuesToRemove.Add(similar.Venue); } } } } foreach (var venue in venuesToRemove.Distinct()) { Console.WriteLine(venue.Name); venueService.DeleteById(venue); } }