Segmenter.Base.Collectors.FrequencyDictionary.Put C# (CSharp) Method

Put() public method

Maps the specified word to the specified cursorPosition in a sequence.
public Put ( string str, int pos ) : void
str string a new word
pos int a cursorPosition of the word in the sequence
return void
        public void Put(string str, int pos)
        {
            try
            {
                if (string.IsNullOrEmpty(str))
                {
                    return;
                }

                if (!words.ContainsKey(str))
                {
                    var wordPositions = new List<int> { pos };
                    words.Add(str, wordPositions);
                }
                else
                {
                    List<int> modified = words[str];
                    if (!modified.Contains(pos))
                    {
                        modified.Add(pos);
                    }
                }
            }
            catch (Exception)
            {
            }
        }

Usage Example

        public void PutTest()
        {
            var alphabet = new FrequencyDictionary(chain);
            string word = "string";
            string unknown = "WOW";
            int pos = 20;
            alphabet.Put(word, pos);

            Assert.True(alphabet.Contains(word));
            Assert.True(!alphabet.Contains(unknown));
        }