Exemplo n.º 1
0
        private static int CalculateInterestFactor(SimpleSlide slide1, SimpleSlide slide2)
        {
            var inA      = new List <string>();
            var inB      = new List <string>();
            var inCommon = new List <string>();
            var factors  = new List <int>();

            // Interesection
            inCommon = slide1.Tags.Intersect(slide2.Tags).ToList();

            // In slide1, not in 2
            foreach (var tag in slide1.Tags)
            {
                if (!inCommon.Contains(tag))
                {
                    inA.Add(tag);
                }
            }

            // In slide2, not in 1
            foreach (var tag in slide2.Tags)
            {
                if (!inCommon.Contains(tag))
                {
                    inB.Add(tag);
                }
            }

            factors.Add(inA.Count);
            factors.Add(inB.Count);
            factors.Add(inCommon.Count);

            return(factors.Min(f => f));
        }
Exemplo n.º 2
0
        private static List <SimpleSlide> CreateEnhancedSlideList(List <SimpleSlide> slidesBefore)
        {
            List <SimpleSlide> slidesAfter = new List <SimpleSlide>();
            int  slideCount   = slidesBefore.Count;
            int  bestInterest = 0;
            int  bestId       = 0;
            bool matchFound   = false;

            for (int i = 0; i < slideCount; i++)
            {
                SimpleSlide masterSlide = slidesBefore.ElementAt(i);

                if (!masterSlide.Processed)
                {
                    slidesBefore.ElementAt(i).Processed = true;

                    for (int j = 0; j < slideCount; j++)
                    {
                        SimpleSlide currentSlide = slidesBefore.ElementAt(j);
                        matchFound = false;

                        if (!currentSlide.Processed && i != j)
                        {
                            var interest = CalculateInterestFactor(masterSlide, currentSlide);
                            if (interest > bestInterest)
                            {
                                bestInterest = interest;
                                bestId       = j;
                            }
                            matchFound = true;
                        }
                        else
                        {
                            matchFound = false;
                        }
                    }

                    if (matchFound)
                    {
                        slidesAfter.Add(masterSlide);
                        var bestSlide = slidesBefore.ElementAt(bestId);
                        slidesAfter.Add(bestSlide);
                        slidesBefore.ElementAt(bestId).Processed = true;
                        //Console.WriteLine($"Best match for Ids {masterSlide.Id} and {bestSlide.Id} is {bestInterest}");

                        bestInterest = 0;
                    }
                    else
                    {
                        // No match found.... this one, was the last slide to match
                        //Console.WriteLine($"Adding single slide {masterSlide.Id}");

                        slidesAfter.Add(masterSlide);
                    }
                }
            }
            slidesAfter.ForEach(s => s.Processed = false);
            return(slidesAfter);
        }