public void YandexDictionary_Create(IYandexSpeller yandexSpeller, MockExternalDictionary mockExternalDictionary)
		{
			IYandexDictionary yandex = new YandexDictionary(yandexSpeller, mockExternalDictionary);
			var word = _fixture.Create<string>();
			Error error;
			Assert.False(yandex.ContainsWord(word, Lang.En, out error));
			yandex.AddWord(word, Lang.En);
			Assert.True(yandex.ContainsWord(word, Lang.En, out error));
		}
		public void YandexDictionary_YandexAPIRequest(IYandexSpeller yandexSpeller,
			MockExternalDictionary mockExternalDictionary)
		{
			IYandexDictionary yandex = new YandexDictionary(yandexSpeller, mockExternalDictionary);
			var word = _fixture.Create<string>();
			Error error;
			Mock.Get(yandexSpeller)
				.Setup(x => x.CheckText(word, Lang.En, It.IsAny<Options>(), It.IsAny<TextFormat>()))
				.Returns(new SpellResult {Errors = new List<Error>()});
			Assert.True(yandex.ContainsWord(word, Lang.En, out error));
		}
Esempio n. 3
0
 private bool YandexSpellCheckPass(IYandexSpeller speller, string word)
 {
     return(!speller.CheckText(word, Lang.Ru | Lang.En, Options.IgnoreCapitalization, TextFormat.Plain).Errors.Any());
 }
Esempio n. 4
0
        private void SpellPhrase(Pack pack, string phrase, Hunspell hunSpell, Hunspell hunSpellEng, IYandexSpeller speller)
        {
            var words = GetWords(phrase);

            foreach (var word in Enumerable.Select(words, w => w.ToLowerInvariant().Replace('ё', 'е')))
            {
                if (hunSpell.Spell(word) || hunSpellEng.Spell(word) || ExistsInSkipped(word, phrase, pack.Id))
                {
                    continue;
                }
                if (!YandexSpellCheckPass(speller, word))
                {
                    ShowSpellErrorMessages(pack, phrase, word);
                    var key = Console.ReadKey();
                    switch (key.KeyChar)
                    {
                    case 'y':
                    case 'Y':
                    case 'd':
                    case 'D':
                        SaveNewCustomWord(hunSpell, word);
                        break;

                    case 's':
                    case 'S':
                        SaveNewSkipWord(word, phrase, pack.Id);
                        break;
                    }
                    Console.WriteLine("Работаем Дальше!");
                }
                else
                {
                    SaveNewCustomWord(hunSpell, word);
                }
            }
        }
Esempio n. 5
0
        private void SpellPhrase(Pack pack, string phrase, Hunspell hunSpell, Hunspell hunSpellEng, IYandexSpeller speller)
        {
            var words = StringUtilities.GetWordsFromString(phrase);

            foreach (var word in words.Select(w => w.ToLowerInvariant().Replace('ё', 'е')).Where(word =>
                                                                                                 !hunSpell.Spell(word) && !hunSpellEng.Spell(word) && !ExistsInSkipped(word, phrase, pack.Id)))
            {
                if (SeveralLanguages(word))
                {
                    ShowSpellErrorMessages(pack, phrase, word, "Несколько языков в слове");
                    HandleErrorWord(pack, word, phrase, hunSpell);
                }
                else if (YandexSpellCheckPass(speller, word) || OxfordSpellCheck(pack, word))
                {
                    SaveNewCustomWord(hunSpell, word);
                }
                else
                {
                    ShowSpellErrorMessages(pack, phrase, word);
                    HandleErrorWord(pack, word, phrase, hunSpell);
                }
            }
        }
Esempio n. 6
0
 private static bool YandexSpellCheckPass([NotNull] IYandexSpeller speller, string word) =>
 !speller.CheckText(word, Lang.Ru | Lang.En, Options.IgnoreCapitalization, TextFormat.Plain).Errors.Any();
		public YandexDictionary(IYandexSpeller yandexSpeller, IExternalDictionary externalDictionary)
		{
			_yandexSpeller = yandexSpeller;
			_externalDictionary = externalDictionary;
			_externalDictionary.DictionaryUpdated += _externalDictionary_DictionaryUpdated;
		}