コード例 #1
0
        private void AnalyzeProduct(Dictionary <string, int> map, string product)
        {
            var words = productNameProcessor.Process(product);

            foreach (var word in words)
            {
                if (map.TryGetValue(word, out var cnt))
                {
                    map[word] = cnt + 1;
                    continue;
                }

                var foundSimilar = false;
                foreach (var key in map.Keys.ToArray())
                {
                    if (!WordUtils.IsWordsSimilar(key, word, wordSimilarityRatio))
                    {
                        continue;
                    }
                    map[key]     = map[key] + 1;
                    foundSimilar = true;
                    break;
                }
                if (foundSimilar)
                {
                    continue;
                }

                map[word] = 1;
            }
        }
コード例 #2
0
        private int CalcProductWeight(Group group, IList <string> productWords)
        {
            var result = 0;
            var map    = group.KeyWords.ToDictionary(x => x.Token, x => x.Weight);

            foreach (var word in productWords)
            {
                if (map.TryGetValue(word, out var weight))
                {
                    result += weight;
                    continue;
                }

                foreach (var key in map.Keys.ToArray())
                {
                    if (!WordUtils.IsWordsSimilar(key, word, wordSimilarityRatio))
                    {
                        continue;
                    }
                    result += map[key];
                    break;
                }
            }

            return(result);
        }