Beispiel #1
0
        public void TestDistance()
        {
            var instance = new MetricLCS();

            NullEmptyTests.TestDistance(instance);

            // TODO: regular (non-null/empty) distance tests
        }
Beispiel #2
0
        protected override async Task <ExitCode> Run()
        {
            var downloads = ((AbsolutePath)DownloadsFolder).EnumerateFiles(false)
                            .Where(x => Consts.SupportedArchives.Contains(x.Extension))
                            .Select(x => (string)x.FileNameWithoutExtension)
                            .ToList();

            var similar = downloads
                          .Select(x =>
            {
                var pair = new KeyValuePair <string, CompareStruct>(x, downloads
                                                                    .Where(y => y != x)
                                                                    .Select(y =>
                {
                    var lcs      = new MetricLCS();
                    var distance = lcs.Distance(x, y);
                    return(new CompareStruct(y, distance));
                })
                                                                    .Aggregate((smallest, next) => smallest.Distance < next.Distance ? smallest : next));
                return(pair);
            })
                          .DistinctBy(x => x.Key)
                          .DistinctBy(x => x.Value.Distance)
                          .Where(x => x.Value.Distance <= Threshold)
                          .ToList();

            CLIUtils.Log($"Found {similar.Count} similar files:");

            similar.Do(f =>
            {
                var(key, value) = f;
                CLIUtils.Log($"{key} similar to {value.Name} by {Math.Round(value.Distance, 3)}");
            });

            return(ExitCode.Ok);
        }