Exemple #1
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            string key   = textBoxOcrFixKey.Text.Trim();
            string value = textBoxOcrFixValue.Text.Trim();

            if (key.Length == 0 || value.Length == 0 || key == value)
            {
                return;
            }

            var languageString = LanguageString;

            if (languageString == null)
            {
                return;
            }

            try
            {
                var ci = new CultureInfo(languageString.Replace("_", "-"));
                _threeLetterIsoLanguageName = ci.ThreeLetterISOLanguageName;
            }
            catch (CultureNotFoundException exception)
            {
                MessageBox.Show(exception.Message);
                return;
            }
            var ocrFixReplaceList = OcrFixReplaceList.FromLanguageId(_threeLetterIsoLanguageName);

            ocrFixReplaceList.AddWordOrPartial(key, value);
            DialogResult = DialogResult.OK;
            NewSource    = key;
            NewTarget    = value;
        }
        public void OcrFixReplaceListRemovePartialLineReload()
        {
            // Arrange
            string fileName = Path.Combine(Directory.GetCurrentDirectory(), Guid.NewGuid() + ".xml");
            var    fixList  = new OcrFixReplaceList(fileName);

            fixList.PartialLineWordBoundaryReplaceList.Clear();
            fixList.AddWordOrPartial("from me", "to you");
            fixList = new OcrFixReplaceList(fileName);
            fixList.RemoveWordOrPartial("from me");

            // Act
            fixList = new OcrFixReplaceList(fileName);

            // Assert
            Assert.IsTrue(!fixList.WordReplaceList.ContainsKey("from me"));

            // Clean up
            try
            {
                File.Delete(fileName);
            }
            catch
            {
            }
        }
Exemple #3
0
        private void LoadOcrFixList(bool reloadListBox)
        {
            if (comboBoxWordListLanguage.Items.Count == 0 || !(comboBoxWordListLanguage.Items[comboBoxWordListLanguage.SelectedIndex] is Settings.ComboBoxLanguage cb))
            {
                return;
            }

            _ocrFixReplaceList = OcrFixReplaceList.FromLanguageId(cb.CultureInfo.GetThreeLetterIsoLanguageName());
            if (reloadListBox)
            {
                listBoxOcrFixList.BeginUpdate();
                listBoxOcrFixList.Items.Clear();
                listBoxOcrFixList.Items.AddRange(_ocrFixReplaceList.WordReplaceList.Select(p => p.Key + " --> " + p.Value).ToArray<object>());
                listBoxOcrFixList.Items.AddRange(_ocrFixReplaceList.PartialLineWordBoundaryReplaceList.Select(p => p.Key + " --> " + p.Value).ToArray<object>());
                listBoxOcrFixList.Sorted = true;
                listBoxOcrFixList.EndUpdate();
            }
        }
        private void buttonOK_Click(object sender, EventArgs e)
        {
            string key   = textBoxOcrFixKey.Text.RemoveControlCharacters().Trim();
            string value = textBoxOcrFixValue.Text.RemoveControlCharacters().Trim();

            if (key.Length == 0 || value.Length == 0 || key == value)
            {
                return;
            }

            var languageString = LanguageString;

            if (languageString == null)
            {
                return;
            }
            try
            {
                var ci = CultureInfo.GetCultureInfo(languageString.Replace('_', '-'));
                _threeLetterIsoLanguageName = ci.GetThreeLetterIsoLanguageName();
            }
            catch (CultureNotFoundException exception)
            {
                try
                {
                    // try for fix e.g. "es-ANY"
                    var arr = languageString.Replace('_', '-').Split('-');
                    var ci2 = CultureInfo.GetCultureInfo(arr[0] + "-" + arr[0]);
                    _threeLetterIsoLanguageName = ci2.GetThreeLetterIsoLanguageName();
                }
                catch
                {
                    MessageBox.Show(exception.Message);
                    return;
                }
            }
            var ocrFixReplaceList = OcrFixReplaceList.FromLanguageId(_threeLetterIsoLanguageName);

            ocrFixReplaceList.AddWordOrPartial(key, value);
            DialogResult = DialogResult.OK;
            NewSource    = key;
            NewTarget    = value;
        }
        /// <summary>
        /// Advanced OCR fixing via replace/spelling dictionaries + some hardcoded rules
        /// </summary>
        /// <param name="threeLetterIsoLanguageName">E.g. eng for English</param>
        /// <param name="hunspellName">Name of hunspell dictionary</param>
        /// <param name="parentForm">Used for centering/show spell check dialog</param>
        public OcrFixEngine(string threeLetterIsoLanguageName, string hunspellName, Form parentForm)
        {
            if (threeLetterIsoLanguageName == "per")
            {
                threeLetterIsoLanguageName = "fas";
            }

            this.threeLetterIsoLanguageName = threeLetterIsoLanguageName;
            this.parentForm = parentForm;

            spellCheck = new OcrSpellCheck { StartPosition = FormStartPosition.Manual };
            spellCheck.Location = new Point(parentForm.Left + (parentForm.Width / 2 - spellCheck.Width / 2),
                                             parentForm.Top + (parentForm.Height / 2 - spellCheck.Height / 2));

            ocrFixReplaceList = OcrFixReplaceList.FromLanguageId(threeLetterIsoLanguageName);
            LoadSpellingDictionaries(threeLetterIsoLanguageName, hunspellName); // Hunspell etc.

            AutoGuessesUsed = new List<string>();
            UnknownWordsFound = new List<string>();
        }
        public void OcrFixReplaceListAddWord()
        {
            // Arrange
            string fileName = Path.Combine(Directory.GetCurrentDirectory(), Guid.NewGuid() + ".xml");
            var    fixList  = new OcrFixReplaceList(fileName);

            fixList.WordReplaceList.Clear();

            // Act
            fixList.AddWordOrPartial("from", "to");

            // Assert
            Assert.IsTrue(fixList.WordReplaceList["from"] == "to");

            // Clean up
            try
            {
                File.Delete(fileName);
            }
            catch
            {
            }
        }