Example #1
0
        public override bool Equals(object o)
        {
            if (o is NgramContainer <T> )
            {
                NgramContainer <T> testObj = (NgramContainer <T>)o;
                return(Ngrams.OrderBy(a => a).ToArray().SequenceEqual(testObj.Ngrams.OrderBy(a => a).ToArray()));
            }

            return(false);
        }
Example #2
0
        internal StateStatistic(NgramContainer <TGram> state, IEnumerable <TGram> valuesAtState)
        {
            State = state.Ngrams;
            var groupedValues = valuesAtState.GroupBy(x => x).ToList();

            Next = groupedValues.Select(a => new NgramStatistic <TGram>
            {
                Value       = a.Key,
                Count       = a.Count(),
                Probability = Math.Round(((double)a.Count() / (double)groupedValues.Sum(x => x.Count())) * 100, 2)
            }).OrderByDescending(x => x.Probability);
        }
Example #3
0
 /// <summary>
 /// Add a TGram to the markov models store with a composite key of the previous [Level] number of TGrams
 /// </summary>
 /// <param name="key">The composite key under which to add the TGram value</param>
 /// <param name="value">The value to add to the store</param>
 internal void AddOrCreate(NgramContainer <T> key, T value)
 {
     lock (_lockObj)
     {
         if (!ChainDictionary.ContainsKey(key))
         {
             ChainDictionary.TryAdd(key, new List <T> {
                 value
             });
         }
         else
         {
             ChainDictionary[key].Add(value);
         }
     }
 }
Example #4
0
 internal List <T> GetValuesForKey(NgramContainer <T> key)
 {
     return(ChainDictionary[key]);
 }
Example #5
0
 internal bool Contains(NgramContainer <T> key)
 {
     return(ChainDictionary.ContainsKey(key));
 }