peng04.processing.TextSource.FindOccurrences C# (CSharp) Method

FindOccurrences() public method

public FindOccurrences ( IEnumerable ngram ) : int
ngram IEnumerable
return int
        public int FindOccurrences(IEnumerable<string> ngram)
        {
            if (ngram.Count() == 0)
            {
                // considering unigrams, we need to fit prob 1 total
                // this means we have to divide by number of segments total

                return Documents.Aggregate(0, (count, doc) => count + doc.LanguageSegments.Count);
            }

            if (_segmentTable != null)
            {
                double data;
                if (_segmentTable.TryFindValue(ngram, out data))
                {
                    return Convert.ToInt32(data);
                }
                else
                {
                    return 0;
                }
            }

            int result = 0;

            foreach (var item in Documents)
            {
                result += item.FindOccurrences(ngram);
            }

            return result;
        }