示例#1
0
        public static List <WordInformation> Combine <T>(List <T> tokens, Database dictionary) where T : class, IToken
        {
            List <WordInformation> words = new List <WordInformation>();
            WordInformation        word  = null;
            T    nextToken            = null;
            T    previousToken        = null;
            bool isPreviousConjugated = false;

            for (int i = 0; i < tokens.Count; i++)
            {
                if (i < tokens.Count - 1)
                {
                    nextToken = tokens[i + 1];
                }
                else
                {
                    nextToken = null;
                }

                if (isPreviousConjugated)
                {
                    if (word.TryAddConjungationPart(previousToken, tokens[i], nextToken))
                    {
                        word.AddWordPart(tokens[i]);

                        if (nextToken != null &&
                            IsConjugationForm(tokens[i], nextToken))
                        {
                            isPreviousConjugated = true;
                        }
                        else
                        {
                            isPreviousConjugated = false;
                        }

                        previousToken = tokens[i];
                        continue;
                    }
                }

                if (nextToken != null &&
                    IsConjugationForm(tokens[i], nextToken))
                {
                    isPreviousConjugated = true;
                }
                else
                {
                    isPreviousConjugated = false;
                }

                word = new WordInformation(tokens[i], nextToken, dictionary);
                words.Add(word);
                if (word.IsHaveSplitWords)
                {
                    words.AddRange(word.SplitWords);
                    isPreviousConjugated = false;
                }
                previousToken = tokens[i];
            }

            FinalizeWordList(dictionary, words);

            return(words);
        }