private static IEnumerable<KeyValuePair<string, double>> CalculateDistances(FansubFile file, IEnumerable<string> folders, Strategy.ComparisonStrategy strategy) { var bagOfResults = new ConcurrentDictionary<string, double>(); var justFolders = folders.ToDictionary(key => key, value => StringUtilities.GetJustFolderName(value)); Parallel.ForEach(justFolders, folder => { var projectedStrategy = strategy.Invoke(file.SeriesName, folder.Value); var seriesName = projectedStrategy.Item1; var projectedFolderName = projectedStrategy.Item2; bagOfResults.TryAdd(folder.Key, StringMetricsCalculator.Instance.MeasureSimilarity(seriesName, projectedFolderName)); }); var listResult = bagOfResults.ToList(); listResult.Sort(KeyValuePairComparison); return listResult; }
public string Compare(FansubFile file, IEnumerable<string> folders, Strategy.ComparisonStrategy strategy) { var justFolderNamesMap = folders.ToDictionary(key => key, value => StringUtilities.GetJustFolderName(value)); var seriesName = file.SeriesName; foreach (var folder in justFolderNamesMap) { var stringsToCompare = strategy.Invoke(seriesName, folder.Value); var transformedSeriesName = stringsToCompare.Item1; var transformedFolderName = stringsToCompare.Item2; if(transformedSeriesName.Equals(transformedFolderName, StringComparison.Ordinal)) { return folder.Key; } } return null; }
public string Compare(FansubFile file, IEnumerable<string> folders, Strategy.ComparisonStrategy strategy) { var distances = CalculateDistances(file, folders, strategy); if (!distances.Any()) { return null; } var headItem = distances.First(); var comparison = headItem.Value - _smudgeFactor; var comparisonMagnitude = Math.Abs(comparison); if (comparison >= 0.0 && comparisonMagnitude >= _epsilon) { return headItem.Key; } return null; }