Beispiel #1
0
        public string Analyse(Phrase phrase, long chatId)
        {
            if (phrase.HasAllWords("скажи", "контекст"))
            {
                string contextName = _perChatCache.Get <string>(CurrentContextCacheKey, chatId);
                return(contextName ?? "Нет контекста");
            }

            foreach (var contextAnalyzer in _contextAnalyzers)
            {
                if (phrase.HasAllWords(contextAnalyzer.ContextSwitchWords))
                {
                    _perChatCache.Set(CurrentContextCacheKey, chatId, contextAnalyzer.ContextName);
                    var response = contextAnalyzer.Analyse(phrase, chatId);

                    if (response.ClenUpCurrentContext)
                    {
                        _perChatCache.Set <string>(CurrentContextCacheKey, chatId, null);
                    }

                    return(response.Text);
                }
            }

            return(null);
        }
Beispiel #2
0
        public void HasAllWordTest()
        {
            _phrase.HasAllWords("первое", "второе").Should().BeTrue();
            _phrase.HasAllWords("седьмое").Should().BeFalse();
            _phrase.HasAllWords("седьмое", "четвертое").Should().BeFalse();

            new Phrase("скажи контекст").HasAllWords("скажи", "контекст").Should().BeTrue();
        }