示例#1
0
 static public void OpenWordProvider(string link, string word)
 {
     if (word.Length > 1)
     {
         word = HebrewAlphabet.SetFinal(word, true);
     }
     SystemManager.TryCatchManage(ShowExceptionMode.OnlyMessage, () =>
     {
         var wordAnalyzed = RemoveNumberingAndDiacritics(word);
         var items        = wordAnalyzed.Word.Split(' ');
         if (!wordAnalyzed.IsUnicode)
         {
             items = items.Select(w => HebrewAlphabet.ToUnicode(HebrewAlphabet.SetFinal(w, true))).ToArray();
         }
         foreach (string item in items)
         {
             if (item.Length > 0)
             {
                 string url = link.Replace("%CUSTOM%", HebrewGlobals.GetCustomWebSearchPattern?.Invoke() ?? string.Empty)
                              .Replace("%WORD%", item)
                              .Replace("%FIRSTLETTER%", item[0].ToString());
                 SystemManager.RunShell(url, item);
                 Thread.Sleep(250);
             }
         }
     });
 }
    /// <summary>
    /// Remove diacritics and numbers Alef or Bet.
    /// </summary>
    static public (string Word, bool IsUnicode) RemoveNumberingAndDiacritics(string word)
    {
        word = word.RemoveDiacritics();
        bool isUnicode = HebrewAlphabet.ContainsUnicode(word);

        if (isUnicode && (word.EndsWith(" א") || word.EndsWith(" ב")))
        {
            word = word.Remove(word.Length - 2);
        }
        else
        if (word.StartsWith("a ") || word.StartsWith("b "))
        {
            word = word.Remove(0, 2);
        }
        return(word, isUnicode);
    }
    /// <summary>
    /// Checks clipboard content type.
    /// </summary>
    internal void CheckClipboardContentType()
    {
        string strContent = Clipboard.GetText();

        ActionPaste.Enabled = !strContent.IsNullOrEmpty() && strContent.Length <= Settings.HebrewTextBoxMaxLength;
        if (ActionPaste.Enabled)
        {
            var strLabel = HebrewAlphabet.IsValidUnicode(strContent)
                     ? HebrewTranslations.Unicode.GetLang()
                     : HebrewAlphabet.IsValidHebrew(strContent)
                       ? HebrewTranslations.Hebrew.GetLang()
                       : SysTranslations.Uncertain.GetLang();
            LabelClipboardContentType.Text = $"{strLabel}{Globals.NL}({strContent.Length})";
        }
        else
        {
            LabelClipboardContentType.Text = SysTranslations.UnknownSlot.GetLang().TrimFirstLast().Titleize();
        }
    }
示例#4
0
    private void CreateSearchResults()
    {
        if (SelectSearchInBook.SelectedItem is null)
        {
            return;
        }
        ClearSearchResults();
        //
        bool checkWordHebrew(WordRow row) => row.Hebrew.Contains(SearchWord1) || row.Hebrew.Contains(SearchWord2);
        bool checkTranslatedAll(VerseRow verse) => verse.HasTranslation;
        bool checkTranslatedAllFully(VerseRow verse) => verse.IsFullyTranslated;
        bool checkTranslatedAllPartially(VerseRow verse) => verse.IsPartiallyTranslated;
        bool checkTranslatedAllUntranslated(VerseRow verse) => !verse.HasTranslation;
        bool checkWordTranslation(WordRow row) => checkWordNoHebrew(row.Translation.ToLower().RemoveDiacritics());
        bool checkVerseComment(VerseRow row) => checkWordNoHebrew(row.Comment.ToLower().RemoveDiacritics());
        bool checkWordNoHebrew(string str)
        => SearchWord1.RawContains(SearchSeparatorString)
         ? SearchWord1.Split(SearchSeparatorChar).Select(item => item.Trim()).Any(item => item.Length >= 2 && str.RawContains(item))
         : str.RawContains(SearchWord1);

        //
        if (SelectSearchType.SelectedTab == SelectSearchTypeHebrew)
        {
            SearchWord1 = EditSearchWord.TextBox.Text;
            SearchWord2 = HebrewAlphabet.SetFinal(SearchWord1, true);
            CheckWord   = checkWordHebrew;
        }
        else
        if (SelectSearchType.SelectedTab == SelectSearchTypeTranslation)
        {
            SearchWord1 = EditSearchTranslation.Text.ToLower().RemoveDiacritics();
            if (SelectSearchTranslationOnlyTranslations.Checked)
            {
                CheckWord  = checkWordTranslation;
                CheckVerse = null;
            }
            else
            if (SelectSearchTranslationIncludeComments.Checked)
            {
                CheckWord  = checkWordTranslation;
                CheckVerse = checkVerseComment;
            }
            else
            if (SelectSearchTranslationOnlyComments.Checked)
            {
                CheckWord  = null;
                CheckVerse = checkVerseComment;
            }
            else
            {
                throw new AdvNotImplementedException(nameof(SelectSearchTypeTranslation));
            }
        }
        else
        if (SelectSearchType.SelectedTab == SelectSearchTypeVerses)
        {
            if (SelectSearchRequestAllTranslated.Checked)
            {
                CheckVerse = checkTranslatedAll;
            }
            if (SelectSearchRequestAllFullyTranslated.Checked)
            {
                CheckVerse = checkTranslatedAllFully;
            }
            if (SelectSearchRequestAllPartiallyTranslated.Checked)
            {
                CheckVerse = checkTranslatedAllPartially;
            }
            if (SelectSearchRequestAllUntranslated.Checked)
            {
                CheckVerse = checkTranslatedAllUntranslated;
            }
        }
        else
        {
            throw new AdvNotImplementedException(SelectSearchType.SelectedTab.Text);
        }
        //
        int bookSelected = Settings.SearchInBookSelectedNumber;

        bool isBookSelected(int index)
        {
            return((Settings.SearchInTorah && index <= BooksBounds.Torah.Max) ||
                   (Settings.SearchInNeviim && index >= BooksBounds.Neviim.Min && index <= BooksBounds.Neviim.Max) ||
                   (Settings.SearchInKetouvim && index >= BooksBounds.Ketouvim.Min) ||
                   (index == bookSelected && !Settings.SearchInTorah && !Settings.SearchInNeviim && !Settings.SearchInKetouvim));
        }

        //
        IEnumerable <ReferenceItem> createSearch(Func <VerseRow, WordRow, bool> check)
        => from book in ApplicationDatabase.Instance.Books
        from chapter in book.Chapters
        from verse in chapter.Verses
        from word in verse.Words
            where isBookSelected(book.Number) &&
        chapter.BookID == book.ID &&
        verse.ChapterID == chapter.ID &&
        word.VerseID == verse.ID &&
        check(verse, word)
        select new ReferenceItem(book, chapter, verse);

        //
        if (SearchWord1.Length >= 2 && CheckWord is not null && CheckVerse is not null)
        {
            SearchResults = createSearch((verse, word) => CheckWord(word) || CheckVerse(verse));
        }
    private void ImportWordsConcordances()
    {
        //CreateWordsConcordances();
        LoadingForm.Instance.Initialize("Importing strong's concordances...",
                                        ApplicationDatabase.Instance.Books.Sum(book => book.Chapters.Count));
        LoadingForm.Instance.TopMost = false;
        var errors    = new List <string>();
        int indexBook = -1;

        try
        {
            foreach (BookRow book in ApplicationDatabase.Instance.Books)
            {
                indexBook++;
                int indexVerse = -1;
                if (indexBook >= 1)
                {
                    break;
                }
                foreach (ChapterRow chapter in book.Chapters)
                {
                    LoadingForm.Instance.DoProgress();
                    foreach (VerseRow verse in chapter.Verses)
                    {
                        indexVerse++;
                        int indexWord = -1;
                        int countBad  = 0;
                        var words     = Program.JsonBibleBookGenesis[indexVerse].Items;
                        //.SelectMany(w => new { strong = w.I, word = w.Word.Split('#') })//.Replace("-", "").Replace("׃", "").Split(' '))
                        //.ToArray();

                        /*if ( verse.Words.Length != words.Length )
                         * {
                         * errors.Add("##### " + new ReferenceItem(book, chapter, verse).ToString() + " words count mismatch");
                         * //indexVerse--;
                         * continue;
                         * }*/
                        if (indexVerse < Program.JsonBibleBookGenesis.Length)
                        {
                            foreach (WordRow word in verse.Words)
                            {
                                indexWord++;
                                if (indexWord < words.Length)
                                {
                                    var unicode = words[indexWord].Word;
                                    var hebrew  = HebrewAlphabet.ToHebrewFont(unicode);
                                    hebrew = HebrewAlphabet.OnlyHebrewFont(hebrew);
                                    int nc = CommonCount(word.Hebrew, hebrew);
                                    if (word.Hebrew == hebrew || nc >= Math.Min(word.Hebrew.Length, hebrew.Length) - 1)
                                    {
                                        // update fields
                                        countBad = 0;
                                    }
                                    else
                                    {
                                        errors.Add($"{new ReferenceItem(book, chapter, verse)}.{indexWord + 1}\t\t" +
                                                   $"{word.Hebrew} <=> {hebrew}\t\t" +
                                                   $"{word.Unicode} <=> {unicode}\t\t{words[indexWord].Number} : {words[indexWord].Text}");
                                        countBad++;
                                        if (countBad >= 4)
                                        {
                                            errors.Add("!!!!! Verse mismatch !!!!!");
                                            //indexVerse--;
                                            //continue;
                                        }
                                    }
                                }
                                else
                                {
                                    errors.Add($"{new ReferenceItem(book, chapter, verse)}.{indexWord + 1}\t\t" +
                                               $"{word.Hebrew} is missing or at wrong place\t\t" +
                                               $"{word.Unicode} is missing or at wrong place");
                                    countBad++;
                                    if (countBad >= 4)
                                    {
                                        errors.Add("!!!!! Verse mismatch !!!!!");
                                        //indexVerse--;
                                        //continue;
                                    }
                                }
                            }
                        }
                        else
                        {
                            errors.Add($"{new ReferenceItem(book, chapter, verse)} is missing.");
                        }
                    }
                }
            }
            // TableAdapterManager.UpdateAll(DataSet);
        }
        catch (Exception ex)
        {
            ex.Manage();
        }
        finally
        {
            LoadingForm.Instance.Hide();
        }
        using var form        = new ImportStrongForm();
        form.RichTextBox.Text = errors.Take(10000).AsMultiLine();
        form.ShowDialog();
    }