Exemplo n.º 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
                }
            }
        }
Exemplo n.º 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;
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
 public void SetNGramCache(NGramCache value)
 {
     _segmentTable = value;
 }