Ejemplo n.º 1
0
		public SpellResult CheckText(string text, Lang[] lang = null, SpellerOptions? options = null, OutputFormat? format = null)
		{
			RestRequest request = new RestRequest("checkText");
			request.AddParameter("text", text);
			if (lang != null && lang.Length != 0)
				request.AddParameter("lang", string.Join(",", lang.Select(l => l.ToString().ToLowerInvariant())));
			if (options.HasValue)
				request.AddParameter("options", (int)options.Value);
			if (format.HasValue)
				request.AddParameter("format", format.Value.ToString().ToLowerInvariant());

			return SendRequest<SpellResult>(request);
		}
Ejemplo n.º 2
0
        public frmMain()
        {
            Predictor  = new Predictor(Settings.Default.PredictorKey);
            Dictionary = new Dictionary(Settings.Default.DictionaryKey);
            Translator = new Translator(Settings.Default.TranslatorKey);
            Speller    = new Speller();

            PredictorTimer  = new System.Threading.Timer(_ => UpdatePredictorResult(), null, Timeout.Infinite, Timeout.Infinite);
            DictionaryTimer = new System.Threading.Timer(_ => UpdateDictionaryResult(), null, Timeout.Infinite, Timeout.Infinite);
            TranslatorTimer = new System.Threading.Timer(_ => UpdateTranslatorResult(), null, Timeout.Infinite, Timeout.Infinite);
            SpellerTimer    = new System.Threading.Timer(_ => UpdateSpellerResult(), null, Timeout.Infinite, Timeout.Infinite);

            InitializeComponent();

            tcServices.SelectedIndex = Settings.Default.SelectedTabIndex;

            cmbPredictorLangs.Items.AddRange(Predictor.GetLangs().Select(lang => (object)lang).ToArray());
            cmbDictionaryLangPairs.Items.AddRange(Dictionary.GetLangs().Select(lang => (object)lang).ToArray());
            cmbDictionaryLangUi.Items.Add("");
            cmbDictionaryLangUi.Items.AddRange(Predictor.GetLangs().Select(lang => (object)lang).ToArray());

            cmbPredictorLangs.SelectedItem = Enum.Parse(typeof(Lang), Settings.Default.PredictorLanguage);
            nudMaxHintCount.Value          = Settings.Default.PredictorMaxHintCount;
            nudPredictorDelay.Value        = Settings.Default.PredictorHintDelay;
            tbPredictorInput.Text          = Settings.Default.PredictorInput;

            cmbDictionaryLangPairs.SelectedItem = LangPair.Parse(Settings.Default.DictionaryLangPair);
            cmbDictionaryLangUi.SelectedIndex   = 0;

            cbFamily.Checked               = Settings.Default.DictionaryFamily;
            cbMorpho.Checked               = Settings.Default.DictionaryMorpho;
            cbPartOfSpeech.Checked         = Settings.Default.DictionaryPartOfSpeech;
            nudPredictorDelay.Value        = Settings.Default.DictionaryHintDelay;
            tbDictionaryInput.Text         = Settings.Default.DictionaryInput;
            cbDictionaryFormatting.Checked = Settings.Default.DictionaryFormatting;
            rbDictionaryOutput.Text        = Settings.Default.DictionaryOutputIndent;

            var langArray = ((Lang[])Enum.GetValues(typeof(Lang))).Select(lang => (object)lang).ToArray();

            cmbTranslatorInputLang.Items.AddRange(langArray);
            cmbTranslatorOutputLang.Items.AddRange(langArray);
            cmbTranslatorInputLang.SelectedItem  = (Lang)Enum.Parse(typeof(Lang), Settings.Default.TranslatorInputLang);
            cmbTranslatorOutputLang.SelectedItem = (Lang)Enum.Parse(typeof(Lang), Settings.Default.TranslatorOutputLang);
            nudTranslatorDelay.Value             = Settings.Default.TranslatorHintDelay;
            cbTranslatorDetectInputLang.Checked  = Settings.Default.TranslatorDetectInputLang;
            tbTranslatorInput.Text = Settings.Default.TranslatorInput;

            cbSpellerRu.Checked = Settings.Default.SpellerRuLang;
            cbSpellerEn.Checked = Settings.Default.SpellerEnLang;
            cbSpellerUk.Checked = Settings.Default.SpellerUkLang;
            SpellerOptions options = (SpellerOptions)Settings.Default.SpellerOptions;

            cbIgnoreUppercase.Checked      = options.HasFlag(SpellerOptions.IgnoreUppercase);
            cbIgnoreDigits.Checked         = options.HasFlag(SpellerOptions.IgnoreDigits);
            cbIgnoreUrls.Checked           = options.HasFlag(SpellerOptions.IgnoreUrls);
            cbFindRepeatWords.Checked      = options.HasFlag(SpellerOptions.FindRepeatWords);
            cbIgnoreLatin.Checked          = options.HasFlag(SpellerOptions.IgnoreLatin);
            cbNoSuggest.Checked            = options.HasFlag(SpellerOptions.NoSuggest);
            cbFlagLatin.Checked            = options.HasFlag(SpellerOptions.FlagLatin);
            cbByWords.Checked              = options.HasFlag(SpellerOptions.ByWords);
            cbIgnoreCapitalization.Checked = options.HasFlag(SpellerOptions.IgnoreCapitalization);
            nudSpellerDelay.Value          = Settings.Default.SpellerHintDelay;
            tbSpellerInput.Text            = Settings.Default.SpellerInput;
            cbIncludeErrorWords.Checked    = Settings.Default.SpellerIncludeErrorWords;

            tbPredictorKey.Text      = Settings.Default.PredictorKey;
            tbDictionaryKey.Text     = Settings.Default.DictionaryKey;
            tbTranslatorKey.Text     = Settings.Default.TranslatorKey;
            tbPredictorBaseUrl.Text  = Settings.Default.PredictorBaseUrl;
            tbDictionaryBaseUrl.Text = Settings.Default.DictionaryBaseUrl;
            tbTranslatorBaseUrl.Text = Settings.Default.TranslatorBaseUrl;
            tbSpellerBaseUrl.Text    = Settings.Default.SpellerBaseUrl;
        }
Ejemplo n.º 3
0
        private void UpdateSpellerResult()
        {
            this.Invoke(new Action(() =>
            {
                try
                {
                    SpellerOptions options = 0;
                    if (cbIgnoreUppercase.Checked)
                    {
                        options |= SpellerOptions.IgnoreUppercase;
                    }
                    if (cbIgnoreDigits.Checked)
                    {
                        options |= SpellerOptions.IgnoreDigits;
                    }
                    if (cbIgnoreUrls.Checked)
                    {
                        options |= SpellerOptions.IgnoreUrls;
                    }
                    if (cbFindRepeatWords.Checked)
                    {
                        options |= SpellerOptions.FindRepeatWords;
                    }
                    if (cbIgnoreLatin.Checked)
                    {
                        options |= SpellerOptions.IgnoreLatin;
                    }
                    if (cbNoSuggest.Checked)
                    {
                        options |= SpellerOptions.NoSuggest;
                    }
                    if (cbFlagLatin.Checked)
                    {
                        options |= SpellerOptions.FlagLatin;
                    }
                    if (cbByWords.Checked)
                    {
                        options |= SpellerOptions.ByWords;
                    }
                    if (cbIgnoreCapitalization.Checked)
                    {
                        options |= SpellerOptions.IgnoreCapitalization;
                    }

                    List <Lang> langs = new List <Lang>();
                    if (cbSpellerRu.Checked)
                    {
                        langs.Add(Lang.Ru);
                    }
                    if (cbSpellerEn.Checked)
                    {
                        langs.Add(Lang.En);
                    }
                    if (cbSpellerUk.Checked)
                    {
                        langs.Add(Lang.Uk);
                    }

                    var response = Speller.CheckText(tbSpellerInput.Text, langs.ToArray(), options);
                    var errors   = response.Errors;

                    string input = tbSpellerInput.Text;

                    if (errors.Count != 0)
                    {
                        StringBuilder output   = new StringBuilder(input.Length);
                        int currentErrorNumber = 0;
                        int i                    = 0;
                        int lastInd              = 0;
                        Error currentError       = errors[0];
                        var highlightedCharPoses = new Dictionary <int, CharMistakeType>();
                        while (i < input.Length)
                        {
                            if (currentError.Column == i)
                            {
                                output.Append(input.Substring(lastInd, i - lastInd));
                                if (currentError.Steer != null)
                                {
                                    output.Append(currentError.Steer);
                                    var poses = Speller.OptimalStringAlignmentDistance(currentError.Word, currentError.Steer);
                                    foreach (var pos in poses)
                                    {
                                        highlightedCharPoses.Add(
                                            output.Length - currentError.Steer.Length + pos.Position,
                                            pos.Type);
                                    }
                                }
                                else if (cbIncludeErrorWords.Checked)
                                {
                                    output.Append(currentError.Word);
                                }

                                i += currentError.Length;
                                currentErrorNumber++;
                                if (currentErrorNumber < errors.Count)
                                {
                                    currentError = errors[currentErrorNumber];
                                }
                                lastInd = i;
                            }
                            else
                            {
                                i++;
                            }
                        }
                        output.Append(input.Substring(lastInd, i - lastInd));

                        rtbSpellerOutput.Text = output.ToString();
                        foreach (var pos in highlightedCharPoses)
                        {
                            if (pos.Value == CharMistakeType.Substitution)
                            {
                                rtbSpellerOutput.Select(pos.Key, 1);
                                rtbSpellerOutput.SelectionColor = Color.Red;
                            }
                            else if (pos.Value == CharMistakeType.Deletion)
                            {
                                if (pos.Key == 0)
                                {
                                    rtbSpellerOutput.Select(0, 1);
                                }
                                else
                                {
                                    rtbSpellerOutput.Select(pos.Key - 1, 2);
                                }
                                rtbSpellerOutput.SelectionBackColor = Color.Gold;
                            }
                            else if (pos.Value == CharMistakeType.Insertion)
                            {
                                rtbSpellerOutput.Select(pos.Key, 1);
                                rtbSpellerOutput.SelectionColor = Color.Blue;
                            }
                            else if (pos.Value == CharMistakeType.Transposition)
                            {
                                rtbSpellerOutput.Select(pos.Key, 2);
                                rtbSpellerOutput.SelectionBackColor = Color.Violet;
                            }
                        }
                    }
                    else
                    {
                        rtbSpellerOutput.Text = input;
                    }
                }
                catch (Exception ex)
                {
                    rtbSpellerOutput.Text = ex.ToString();
                }
            }));
        }
Ejemplo n.º 4
0
        private void frmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            Settings.Default.SelectedTabIndex = tcServices.SelectedIndex;

            Settings.Default.PredictorKey  = tbPredictorKey.Text;
            Settings.Default.DictionaryKey = tbDictionaryKey.Text;
            Settings.Default.TranslatorKey = tbTranslatorKey.Text;

            Settings.Default.PredictorLanguage     = cmbPredictorLangs.SelectedItem.ToString();
            Settings.Default.PredictorMaxHintCount = (int)nudMaxHintCount.Value;
            Settings.Default.PredictorHintDelay    = (int)nudPredictorDelay.Value;
            Settings.Default.PredictorInput        = tbPredictorInput.Text;

            Settings.Default.DictionaryLangPair     = cmbDictionaryLangPairs.SelectedItem.ToString();
            Settings.Default.DictionaryLangUi       = cmbDictionaryLangUi.SelectedItem.ToString();
            Settings.Default.DictionaryMorpho       = cbMorpho.Checked;
            Settings.Default.DictionaryFamily       = cbFamily.Checked;
            Settings.Default.DictionaryPartOfSpeech = cbPartOfSpeech.Checked;
            Settings.Default.DictionaryHintDelay    = (int)nudDictionaryDelay.Value;
            Settings.Default.DictionaryInput        = tbDictionaryInput.Text;
            Settings.Default.DictionaryFormatting   = cbDictionaryFormatting.Checked;
            Settings.Default.DictionaryOutputIndent = tbDictionaryIndent.Text;

            Settings.Default.TranslatorInputLang       = cmbTranslatorInputLang.SelectedItem.ToString();
            Settings.Default.TranslatorOutputLang      = cmbTranslatorOutputLang.SelectedItem.ToString();
            Settings.Default.TranslatorHintDelay       = (int)nudTranslatorDelay.Value;
            Settings.Default.TranslatorDetectInputLang = cbTranslatorDetectInputLang.Checked;
            Settings.Default.TranslatorInput           = tbTranslatorInput.Text;

            Settings.Default.SpellerRuLang = cbSpellerRu.Checked;
            Settings.Default.SpellerEnLang = cbSpellerEn.Checked;
            Settings.Default.SpellerUkLang = cbSpellerUk.Checked;
            SpellerOptions options = 0;

            if (cbIgnoreUppercase.Checked)
            {
                options |= SpellerOptions.IgnoreUppercase;
            }
            if (cbIgnoreDigits.Checked)
            {
                options |= SpellerOptions.IgnoreDigits;
            }
            if (cbIgnoreUrls.Checked)
            {
                options |= SpellerOptions.IgnoreUrls;
            }
            if (cbFindRepeatWords.Checked)
            {
                options |= SpellerOptions.FindRepeatWords;
            }
            if (cbIgnoreLatin.Checked)
            {
                options |= SpellerOptions.IgnoreLatin;
            }
            if (cbNoSuggest.Checked)
            {
                options |= SpellerOptions.NoSuggest;
            }
            if (cbFlagLatin.Checked)
            {
                options |= SpellerOptions.FlagLatin;
            }
            if (cbByWords.Checked)
            {
                options |= SpellerOptions.ByWords;
            }
            if (cbIgnoreCapitalization.Checked)
            {
                options |= SpellerOptions.IgnoreCapitalization;
            }
            Settings.Default.SpellerOptions           = (int)options;
            Settings.Default.SpellerHintDelay         = (int)nudSpellerDelay.Value;
            Settings.Default.SpellerInput             = tbSpellerInput.Text;
            Settings.Default.SpellerIncludeErrorWords = cbIncludeErrorWords.Checked;

            Settings.Default.PredictorBaseUrl  = tbPredictorBaseUrl.Text;
            Settings.Default.DictionaryBaseUrl = tbDictionaryBaseUrl.Text;
            Settings.Default.TranslatorBaseUrl = tbTranslatorBaseUrl.Text;
            Settings.Default.SpellerBaseUrl    = tbSpellerBaseUrl.Text;

            Settings.Default.Save();
        }