Example #1
0
        private void AssociateMatchedFilters(string suspect)
        {
            var suspectTokens           = suspect.Split(' ');
            var expandedSuspectTokenSet = ExpandTokenSet(suspectTokens);

            if (usePluralizationService)
            {
                expandedSuspectTokenSet = ExpandTokenSetWithPlurals(expandedSuspectTokenSet);
            }

            var applicableFilters = new List <FilteredKeyword>();

            foreach (var token in expandedSuspectTokenSet)
            {
                List <FilteredKeyword> filterSubset;
                var additionalFilterSubset = new List <FilteredKeyword>();

                filteredKeywordTokenMap.TryGetValue(token, out filterSubset);

                if (filterSubset == null)
                {
                    continue;
                }

                foreach (var keyword in filterSubset)
                {
                    var singularPluralKeyword = SingularPluralKeyword.CreateInstance(keyword.Keyword);

                    if (singularPluralKeyword.HasBothSingularAndPlural)
                    {
                        additionalFilterSubset.Add(singularPluralKeyword.Singular == keyword.Keyword
                            ? new FilteredKeyword {
                            Keyword = singularPluralKeyword.Plural
                        }
                            : new FilteredKeyword {
                            Keyword = singularPluralKeyword.Singular
                        });
                    }
                }

                applicableFilters.AddRange(filterSubset);
                applicableFilters.AddRange(additionalFilterSubset);
            }

            applicableFilters = applicableFilters.Distinct().ToList();

            var filterKeywordPairs = applicableFilters
                                     .Select(x => new { filter = x, keyword = Normalize(x.Keyword) });

            var suspectNorm = Normalize(suspect);

            var matchedFiltered = filterKeywordPairs
                                  .FirstOrDefault(x => suspectNorm.Contains(x.keyword));

            if (!associateMatchedFilteredKeywordsReturnValue.ContainsKey(suspect))
            {
                associateMatchedFilteredKeywordsReturnValue.Add(suspect,
                                                                matchedFiltered == null ? null : matchedFiltered.filter);
            }
        }
Example #2
0
        private IEnumerable <string> ExpandTokenSetWithPlurals(IEnumerable <string> suspectTokens)
        {
            var expandedTokenSet = new List <string>();

            foreach (var suspectToken in suspectTokens)
            {
                var singularPluralKeyword = SingularPluralKeyword.CreateInstance(suspectToken);

                if (singularPluralKeyword.HasBothSingularAndPlural)
                {
                    expandedTokenSet.Add(singularPluralKeyword.Singular);
                    expandedTokenSet.Add(singularPluralKeyword.Plural);
                }

                expandedTokenSet.Add(singularPluralKeyword.OriginalKeyword);
            }

            return(expandedTokenSet);
        }