Example #1
0
        public void BuildSegmentTable(int n)
        {
            if(_segmentTable == null) _segmentTable = new NGramCache();

            foreach (var item in Documents)
            {
                var array = item.LanguageSegments.ToArray();
                for (int i = 0; i <= array.Length - n; i++)
                {
                    _segmentTable.Increment(array.GetNGram(i, n), 1); // inc count
                }
            }
        }
Example #2
0
        public static NGramCache Aggregate(IEnumerable<NGramCache> nGramCaches)
        {
            var result = new NGramCache();

            foreach (var item in nGramCaches)
            {
                IEnumerable<NGramCache> nGrams = item.NextSegment.Values;

                while(nGrams.Count() > 0)
                {
                    foreach (var xGram in nGrams)
                    {
                        result.Increment(xGram.NGram, xGram.Value);
                    }

                    // next n
                    nGrams = nGrams.SelectMany(el => el.NextSegment.Values);
                }
            }

            return result;
        }
Example #3
0
        public static NGramCache Aggregate(IEnumerable <NGramCache> nGramCaches)
        {
            var result = new NGramCache();

            foreach (var item in nGramCaches)
            {
                IEnumerable <NGramCache> nGrams = item.NextSegment.Values;

                while (nGrams.Count() > 0)
                {
                    foreach (var xGram in nGrams)
                    {
                        result.Increment(xGram.NGram, xGram.Value);
                    }

                    // next n
                    nGrams = nGrams.SelectMany(el => el.NextSegment.Values);
                }
            }

            return(result);
        }
Example #4
0
 public void SetNGramCache(NGramCache value)
 {
     _segmentTable = value;
 }