Ejemplo n.º 1
0
        public void Collect_keywords_not_from_journey_steps_Test()
        {
            var keywordBag = new KeywordBag()
            {
                Keywords = new List <Keyword>()
                {
                    new Keyword()
                    {
                        Value = "keyword from answer", IsFromAnswer = true
                    },
                    new Keyword()
                    {
                        Value = "keyword not from answer", IsFromAnswer = false
                    },
                },
                ExcludeKeywords = new List <Keyword>()
                {
                    new Keyword()
                    {
                        Value = "exclude keyword from answer", IsFromAnswer = true
                    },
                    new Keyword()
                    {
                        Value = "exclude keyword not from answer", IsFromAnswer = false
                    },
                }
            };

            var result = _testKeywordCollector.CollectKeywordsFromPreviousQuestion(keywordBag, null);

            Assert.IsNotNull(result);
            Assert.True(result.Keywords.Count() == 1);
            Assert.True(result.ExcludeKeywords.Count() == 1);
        }
Ejemplo n.º 2
0
        private KeywordBag CollectKeywordsFromNonJourneySteps(KeywordBag keywordBag)
        {
            if (keywordBag == null)
            {
                return(new KeywordBag());
            }

            return(new KeywordBag()
            {
                Keywords = keywordBag.Keywords.Where(k => !k.IsFromAnswer).ToList(),
                ExcludeKeywords = keywordBag.ExcludeKeywords.Where(k => !k.IsFromAnswer).ToList()
            });
        }
Ejemplo n.º 3
0
        public KeywordBag CollectKeywords(IEnumerable <string> keywords, IEnumerable <string> excludeKeywords)
        {
            var bag = new KeywordBag();

            var kw = keywords
                     .SelectMany(a => ParseKeywords(a, false)).Distinct(new KeywordComparer()).ToList();

            var exKw = excludeKeywords
                       .SelectMany(a => ParseKeywords(a, false)).Distinct(new KeywordComparer()).ToList();

            bag.Keywords        = bag.Keywords.Union(kw, new KeywordComparer()).ToList();
            bag.ExcludeKeywords = bag.ExcludeKeywords.Union(exKw, new KeywordComparer()).ToList();

            return(bag);
        }
Ejemplo n.º 4
0
        public KeywordBag CollectKeywordsFromPreviousQuestion(KeywordBag keywordBag, List <JourneyStep> journeySteps)
        {
            var bag = CollectKeywordsFromNonJourneySteps(keywordBag);

            if (journeySteps == null)
            {
                return(bag);
            }

            var keywords = journeySteps
                           .Select(s => s.Answer)
                           .SelectMany(a => ParseKeywords(a.Keywords)).Distinct(new KeywordComparer()).ToList();

            var excludeKeywords = journeySteps
                                  .Select(s => s.Answer)
                                  .SelectMany(a => ParseKeywords(a.ExcludeKeywords)).Distinct(new KeywordComparer()).ToList();

            bag.Keywords        = bag.Keywords.Union(keywords, new KeywordComparer()).ToList();
            bag.ExcludeKeywords = bag.ExcludeKeywords.Union(excludeKeywords, new KeywordComparer()).ToList();

            return(bag);
        }
Ejemplo n.º 5
0
 public IEnumerable <string> ConsolidateKeywords(KeywordBag keywordBag)
 {
     return(keywordBag.Keywords.Except(keywordBag.ExcludeKeywords, new KeywordComparer()).Select(k => k.Value));
 }