Пример #1
0
        private static Dictionary <string, int> GetCharSuggs(MappingSequence mappingSequences, string pinglishWord, int index, Dictionary <string, int> charSuggs, int prefixGram, int postfixGram)
        {
            var tmpSuggs = GetSuggsForKey(mappingSequences, pinglishWord, index, prefixGram, postfixGram);

            charSuggs = Union(charSuggs, tmpSuggs);
            return(charSuggs);
        }
Пример #2
0
        private static Dictionary <string, int> GetSuggsForKey(MappingSequence mappingSequences, string pinglishWord, int index, int prefixGram, int postfixGram)
        {
            var prefix = MappingSequence.GetPrefixForIndex(pinglishWord, index, prefixGram);

            if (prefix.Length != prefixGram)
            {
                return(new Dictionary <string, int>());
            }

            var postfix = MappingSequence.GetPostfixForIndex(pinglishWord, index, postfixGram);

            if (postfix.Length != postfixGram)
            {
                return(new Dictionary <string, int>());
            }

            var ch = pinglishWord[index];

            Dictionary <string, int> charSuggs = null;

            try
            {
                // TODO: If Key does not exist ?!
                var listOfAllSuggs = mappingSequences[ch, prefix, postfix];

                if (listOfAllSuggs != null)
                {
                    charSuggs = listOfAllSuggs.ToDictionary(sug => sug.Key, sug => sug.Value);
                }
                else
                {
                    charSuggs = new Dictionary <string, int>();
                }
            }
            catch (KeyNotFoundException ex)
            {
                throw ex;
            }

            return(charSuggs);
        }