Exemple #1
0
        public void Verbose_With_Levenstein()
        {
            const double latitude  = 37.786971;
            const double longitude = -122.399677;

            IStringMetric metric    = new Levenstein();
            ITokenizer    tokenizer = new Tokenizer();

            var geopages = WikiApi.Geosearch(latitude, longitude);

            foreach (var geopage in geopages)
            {
                output.WriteLine($"[{geopage.Pageid}] {geopage.Title}");

                var images = WikiApi.Images(geopage.Pageid);

                var imagesWithMetrics = images
                                        .Select(image => new { Image = image, Similarity = image.CalcMetric(geopage.Title, tokenizer, metric) })
                                        .ToList();
                var title = imagesWithMetrics.Aggregate((image, next) => next.Similarity > image.Similarity ? next : image);

                output.WriteLine($"\t*[{title.Image.Ns}] {title.Image.Title} {title.Similarity}");

                foreach (var image in imagesWithMetrics)
                {
                    output.WriteLine($"\t[{image.Image.Ns}] {image.Image.Title} {image.Similarity}");
                }
            }
        }
Exemple #2
0
        public void Should_Work()
        {
            const int pageid = 40413203;
            var       images = WikiApi.Images(pageid);

            Assert.NotNull(images);
            Assert.NotEmpty(images);
        }
Exemple #3
0
        public void Should_Work_Empty_With_Missing_Page()
        {
            const int pageid = 1;
            var       images = WikiApi.Images(pageid);

            Assert.NotNull(images);
            Assert.Empty(images);
        }
Exemple #4
0
        public void Should_Work_Multi_Page()
        {
            const int pageid1 = 40413203;
            const int pageid2 = 40377676;
            var       images  = WikiApi.Images(new [] { pageid1, pageid2 });

            Assert.NotNull(images);
            Assert.NotEmpty(images);

            Assert.NotEmpty(images[pageid1].Images);
            Assert.NotEmpty(images[pageid2].Images);
        }