Exemple #1
0
        /// </summary>
        /// <param name="first_verse">First verse in sentence</param>
        /// <param name="start_position">Position in verse of first letter of first word in sentence</param>
        /// <param name="last_verse">Last verse in sentence</param>
        /// <param name="end_position">Position in verse of last letter of last word in sentence</param>
        /// <param name="text">Complete text of sentence within its verse or across multiple verses</param>
        public Sentence(Verse first_verse, int start_position, Verse last_verse, int end_position, string text)
        {
            this.first_verse = first_verse;
            this.start_position = start_position;
            this.last_verse = last_verse;
            this.end_position = end_position;
            this.text = text;

            this.chapter_count = last_verse.Chapter.Number - first_verse.Chapter.Number + 1;
            this.verse_count = last_verse.Number - first_verse.Number + 1;

            string text_mode = first_verse.Book.Title;
            string simplified_text = this.text.SimplifyTo(text_mode);

            this.word_count = simplified_text.Split().Length;

            this.letter_count = simplified_text.Length - word_count + 1;

            List<char> unique_letters = new List<char>();
            foreach (char letter in simplified_text)
            {
                if (letter == ' ') continue;

                if (!unique_letters.Contains(letter))
                {
                    unique_letters.Add(letter);
                }
            }
            this.unique_letter_count = unique_letters.Count;
        }
Exemple #2
0
 public Prostration(int number, ProstrationType type, Verse verse)
 {
     this.number = number;
     this.type = type;
     this.verse = verse;
     if (verse != null)
     {
         verse.Prostration = this;
     }
 }
Exemple #3
0
        public Word(Verse verse, int number_in_verse, int position, string text)
        {
            this.verse = verse;
            //this.number = number; // to be filled by book.SetupNumbers
            this.number_in_verse = number_in_verse;
            //this.number_in_chapter = number_in_chapter; // to be filled by book.SetupNumbers
            this.position = position;
            this.text     = text;

            if ((Globals.EDITION == Edition.Grammar) || (Globals.EDITION == Edition.Ultimate))
            {
                this.parts = new List <WordPart>();
            }

            this.letters = new List <Letter>();
            string simplified_text = null;

            if (text != null)
            {
                if (text.IsArabicWithDiacritics())
                {
                    simplified_text = text.SimplifyTo("Original");
                }
                else
                {
                    simplified_text = text;
                }
            }

            if (this.letters != null)
            {
                int letter_number_in_word = 0;
                foreach (char character in simplified_text)
                {
                    if (character == '_')
                    {
                        continue;
                    }

                    letter_number_in_word++;

                    Letter letter = new Letter(this, letter_number_in_word, character);
                    this.letters.Add(letter);
                }
            }
        }
Exemple #4
0
        public bool HasRelatedWordsTo(Verse target)
        {
            if (target != null)
            {
                // make a copy to null used words
                List <Word> source_words = new List <Word>(this.Words);

                int common_word_count = 0;
                foreach (Word target_word in target.Words)
                {
                    for (int i = 0; i < source_words.Count; i++)
                    {
                        if (source_words[i] != null)
                        {
                            bool found = false;
                            foreach (string root in source_words[i].Roots)
                            {
                                if (target_word.Roots != null)
                                {
                                    if (target_word.Roots.Contains(root))
                                    {
                                        source_words[i] = null; // remove it from list so not to be reused

                                        common_word_count++;
                                        found = true;
                                        break;
                                    }
                                }
                            }
                            if (found)
                            {
                                break;
                            }
                        }
                    }
                }

                if (common_word_count >= this.Words.Count)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #5
0
        /// </summary>
        /// <param name="first_verse">First verse in sentence</param>
        /// <param name="start_position">Position in verse of first letter of first word in sentence</param>
        /// <param name="last_verse">Last verse in sentence</param>
        /// <param name="end_position">Position in verse of last letter of last word in sentence</param>
        /// <param name="text">Complete text of sentence within its verse or across multiple verses</param>
        public Sentence(Verse first_verse, int start_position, Verse last_verse, int end_position, string text)
        {
            this.first_verse    = first_verse;
            this.start_position = start_position;
            this.last_verse     = last_verse;
            this.end_position   = end_position;
            this.text           = text.Trim();

            this.chapter_count = last_verse.Chapter.SortedNumber - first_verse.Chapter.SortedNumber + 1;

            this.verse_count = last_verse.Number - first_verse.Number + 1;

            string text_mode = first_verse.Book.TextMode;

            text = text.SimplifyTo(text_mode);
            text = text.Trim();
            while (text.Contains("  "))
            {
                text = text.Replace("  ", " ");
            }

            this.word_count = text.Split().Length;

            this.letter_count = text.Length - word_count + 1;

            List <char> unique_letters = new List <char>();

            foreach (char letter in text)
            {
                if (letter == ' ')
                {
                    continue;
                }

                if (!unique_letters.Contains(letter))
                {
                    unique_letters.Add(letter);
                }
            }
            this.unique_letter_count = unique_letters.Count;
        }
Exemple #6
0
        public Word(Verse verse, int number_in_verse, int position_in_verse, string text, Stopmark stopmark)
        {
            this.verse = verse;
            this.number_in_verse = number_in_verse;
            this.position = position_in_verse;
            this.text = text;
            this.stopmark = stopmark;

            if ((Globals.EDITION == Edition.Grammar) || (Globals.EDITION == Edition.Research))
            {
                this.parts = new List<WordPart>();
            }

            this.letters = new List<Letter>();
            if (this.Letters != null)
            {
                int letter_number_in_word = 0;

                // for correct UniqueLetters calculation in Original text
                string simplified_text = this.text;
                if (this.text.IsArabicWithDiacritics())
                {
                    simplified_text = this.text.Simplify29();
                }

                foreach (char character in simplified_text)
                {
                    if (Constants.ARABIC_LETTERS.Contains(character))
                    {
                        letter_number_in_word++;

                        Letter letter = new Letter(this, character, letter_number_in_word);
                        this.Letters.Add(letter);
                    }
                }
            }
        }
Exemple #7
0
 private static long AdjustVerseValue(Verse verse)
 {
     long result = 0L;
     if (s_numerology_system != null)
     {
         if (verse != null)
         {
             if (s_numerology_system.AddToVerseVNumber)
             {
                 result += verse.NumberInChapter;
             }
             if (s_numerology_system.AddToVerseCNumber)
             {
                 result += verse.Chapter.Number;
             }
             if (s_numerology_system.AddToVerseVDistance)
             {
                 result += verse.DistanceToPrevious.dV;
             }
             if (s_numerology_system.AddToVerseCDistance)
             {
                 result += verse.DistanceToPrevious.dC;
             }
         }
     }
     return result;
 }
Exemple #8
0
 private void DisplayVerse(Verse verse)
 {
     if (m_client != null)
     {
         if (m_client.Book != null)
         {
             if (verse != null)
             {
                 if (verse.Chapter != null)
                 {
                     int chapter_number = verse.Chapter.Number;
                     int verse_number_in_chapter = verse.NumberInChapter;
                     int verse_number = m_client.Book.GetVerseNumber(chapter_number, verse_number_in_chapter);
                     if ((verse_number >= VerseNumericUpDown.Minimum) && (verse_number <= VerseNumericUpDown.Maximum))
                     {
                         VerseNumericUpDown.Focus();
                         VerseNumericUpDown.Value = verse_number;
                     }
                 }
             }
         }
     }
 }
Exemple #9
0
    private void DisplayTafseer(Verse verse)
    {
        //if (TabControl.SelectedTab == TafseerTabPage)
        {
            this.Cursor = Cursors.WaitCursor;
            if (verse != null)
            {
                string tafseers_folder = Directory.GetCurrentDirectory() + "/" + Globals.TAFSEERS_FOLDER;
                string filename = (verse.Chapter.Number.ToString("000") + verse.NumberInChapter.ToString("000") + ".htm");
                string tafseer_langauge = m_tafseer.Substring(0, m_tafseer.IndexOf(" - "));
                string tafseer_folder = m_tafseer.Substring(m_tafseer.IndexOf(" - ") + 3);
                string path = tafseers_folder + "/" + tafseer_langauge + "/" + tafseer_folder + "/" + filename;
                try
                {
                    TafseerWebBrowser.Url = new Uri(path);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "\r\n" + path, Application.ProductName);
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }

                m_tafseer_verses.Clear();
                m_tafseer_verses.Add(verse);
            }
        }
    }
Exemple #10
0
    private static bool Compare(Verse verse, NumberQuery query)
    {
        if (verse != null)
        {
            long value = 0L;

            if (query.NumberNumberType == NumberType.None)
            {
                if (query.Number > 0)
                {
                    if (!Numbers.Compare(verse.NumberInChapter, query.Number, query.NumberComparisonOperator))
                    {
                        return false;
                    }
                }
            }
            else
            {
                if (!Numbers.IsNumberType(verse.NumberInChapter, query.NumberNumberType))
                {
                    return false;
                }
            }

            if (query.WordCountNumberType == NumberType.None)
            {
                if (query.WordCount > 0)
                {
                    if (!Numbers.Compare(verse.Words.Count, query.WordCount, query.WordCountComparisonOperator))
                    {
                        return false;
                    }
                }
            }
            else
            {
                if (!Numbers.IsNumberType(verse.Words.Count, query.WordCountNumberType))
                {
                    return false;
                }
            }

            if (query.LetterCountNumberType == NumberType.None)
            {
                if (query.LetterCount > 0)
                {
                    if (!Numbers.Compare(verse.LetterCount, query.LetterCount, query.LetterCountComparisonOperator))
                    {
                        return false;
                    }
                }
            }
            else
            {
                if (!Numbers.IsNumberType(verse.LetterCount, query.LetterCountNumberType))
                {
                    return false;
                }
            }

            if (query.UniqueLetterCountNumberType == NumberType.None)
            {
                if (query.UniqueLetterCount > 0)
                {
                    if (!Numbers.Compare(verse.UniqueLetters.Count, query.UniqueLetterCount, query.UniqueLetterCountComparisonOperator))
                    {
                        return false;
                    }
                }
            }
            else
            {
                if (!Numbers.IsNumberType(verse.UniqueLetters.Count, query.UniqueLetterCountNumberType))
                {
                    return false;
                }
            }

            if (query.ValueNumberType == NumberType.None)
            {
                if (query.Value > 0)
                {
                    if (value == 0L) { value = CalculateValue(verse); }
                    if (!Numbers.Compare(value, query.Value, query.ValueComparisonOperator))
                    {
                        return false;
                    }
                }
            }
            else
            {
                if (value == 0L) { value = CalculateValue(verse); }
                if (!Numbers.IsNumberType(value, query.ValueNumberType))
                {
                    return false;
                }
            }

            if (query.ValueDigitSumNumberType == NumberType.None)
            {
                if (query.ValueDigitSum > 0)
                {
                    if (value == 0L) { value = CalculateValue(verse); }
                    if (!Numbers.Compare(Numbers.DigitSum(value), query.ValueDigitSum, query.ValueDigitSumComparisonOperator))
                    {
                        return false;
                    }
                }
            }
            else
            {
                if (value == 0L) { value = CalculateValue(verse); }
                if (!Numbers.IsNumberType(Numbers.DigitSum(value), query.ValueDigitSumNumberType))
                {
                    return false;
                }
            }

            if (query.ValueDigitalRootNumberType == NumberType.None)
            {
                if (query.ValueDigitalRoot > 0)
                {
                    if (value == 0L) { value = CalculateValue(verse); }
                    if (!Numbers.Compare(Numbers.DigitalRoot(value), query.ValueDigitalRoot, query.ValueDigitalRootComparisonOperator))
                    {
                        return false;
                    }
                }
            }
            else
            {
                if (value == 0L) { value = CalculateValue(verse); }
                if (!Numbers.IsNumberType(Numbers.DigitalRoot(value), query.ValueDigitalRootNumberType))
                {
                    return false;
                }
            }
        }

        // passed all tests successfully
        return true;
    }
Exemple #11
0
    private void DoPlayVerse(Verse verse)
    {
        try
        {
            if (m_client != null)
            {
                if (verse != null)
                {
                    if (m_mp3player != null)
                    {
                        if (m_mp3player.Closed)
                        {
                            PlayerOpenAudioFile(verse);
                        }

                        if (m_mp3player.Opened)
                        {
                            if (m_mp3player.MuteAll)
                            {
                                m_mp3player.VolumeAll = 0;
                            }
                            else
                            {
                                m_mp3player.VolumeAll = m_audio_volume;
                            }

                            m_mp3player.Play();
                            PlayerTimer.Enabled = true;
                            PlayerStopLabel.Enabled = true;
                            PlayerStopLabel.Refresh();
                        }
                    }

                    // simulate mouse click to continue playing next verse and not restart from 1
                    m_active_textbox.Focus();
                    m_is_selection_mode = false;
                }
                else // invalid verse
                {
                    MessageBox.Show("No verse available.", Application.ProductName);

                    // reset player buttons
                    PlayerStopLabel_Click(null, null);
                }
            }
        }
        catch
        {
            PlayerStopLabel_Click(null, null);
        }
    }
Exemple #12
0
 private static long CalculateBeginningPartValue(Verse verse, int to_letter_index)
 {
     return CalculateMiddlePartValue(verse, 0, to_letter_index);
 }
Exemple #13
0
    private static long CalculateMiddlePartValue(Verse verse, int from_letter_index, int to_letter_index)
    {
        if (verse == null) return 0L;

        long result = 0L;
        if (s_numerology_system != null)
        {
            // adjust value of verse
            if ((from_letter_index == 0) && (to_letter_index == verse.LetterCount - 1))
            {
                result += AdjustVerseValue(verse);
            }

            int word_index = -1;   // in verse
            int letter_index = -1; // in verse
            foreach (Word word in verse.Words)
            {
                word_index++;

                // adjust value of word (if fully selected)
                if ((from_letter_index <= word.Letters[0].NumberInVerse - 1)                    // if selection starts before or at first letter in word
                    &&                                                                          // AND
                    (to_letter_index >= word.Letters[word.Letters.Count - 1].NumberInVerse - 1) // if selection ends   at or after  last  letter in word
                   )
                {
                    result += AdjustWordValue(word);
                }

                foreach (Letter letter in word.Letters)
                {
                    letter_index++;

                    if (letter_index < from_letter_index) continue;
                    if (letter_index > to_letter_index) break;

                    // adjust value of letter
                    result += AdjustLetterValue(letter);

                    // calculate the letter static value
                    result += s_numerology_system.CalculateValue(letter.Character);
                }
            }
        }
        return result;
    }
Exemple #14
0
    private void GotoDoubleClickedVerseInItsChapter(Verse verse)
    {
        this.Cursor = Cursors.WaitCursor;
        try
        {
            MainTextBox.SelectionChanged -= new EventHandler(MainTextBox_SelectionChanged);
            MainTextBox.BeginUpdate();

            if (verse != null)
            {
                if (verse.Chapter != null)
                {
                    if (m_client != null)
                    {
                        // select chapter and display it and colorize target verse
                        m_client.Selection = new Selection(m_client.Book, SelectionScope.Chapter, new List<int>() { verse.Chapter.Number - 1 });
                        if (m_client.Selection != null)
                        {
                            if ((m_mp3player.Playing) || (m_mp3player.Paused))
                            {
                                PlayerStopLabel_Click(null, null);
                            }

                            SwitchToMainTextBox();

                            BookmarkTextBox.Enabled = true;
                            // display selection's note (if any)
                            DisplayNote(m_client.GetBookmark(m_client.Selection));

                            m_is_selection_mode = false;

                            AutoCompleteHeaderLabel.Visible = false;
                            AutoCompleteListBox.Visible = false;
                            AutoCompleteListBox.SendToBack();

                            this.Text = Application.ProductName + " | " + GetSummarizedFindScope();
                            UpdateFindScope();

                            UpdateHeaderLabel();

                            DisplaySelectionText();

                            CalculateCurrentValue();

                            CalculateLetterStatistics();
                            DisplayLetterStatistics();

                            CalculatePhraseLetterStatistics();
                            DisplayPhraseLetterStatistics();

                            MainTextBox.ClearHighlight();
                            MainTextBox.AlignToStart();

                            m_current_selection_verse_index = 0;
                            PrepareVerseToPlay();

                            DisplayVersesWordsLetters(verse);

                            m_similarity_current_verse = verse;
                            DisplayTranslations(verse);

                            HighlightVerse(verse);

                            if (m_client.NumerologySystem.TextMode.Contains("Images"))
                            {
                                PictureBoxPanel.BringToFront();
                                PictureBoxPanel.Visible = true;
                                DisplayCurrentPage();
                            }
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, Application.ProductName);
        }
        finally
        {
            MainTextBox.EndUpdate();
            MainTextBox.SelectionChanged += new EventHandler(MainTextBox_SelectionChanged);
            this.Cursor = Cursors.Default;
        }
    }
Exemple #15
0
    private void GotoVerse(Verse verse)
    {
        try
        {
            m_active_textbox.SelectionChanged -= new EventHandler(MainTextBox_SelectionChanged);
            m_active_textbox.BeginUpdate();

            if (m_client != null)
            {
                if (verse != null)
                {
                    int start = GetVerseDisplayStart(verse);

                    // re-wire MainTextBox_SelectionChanged event to
                    // updates verse position and value when cursor goes to start of verse
                    // #######
                    m_active_textbox.SelectionChanged += new EventHandler(MainTextBox_SelectionChanged);
                    m_active_textbox.Select(start, 0);

                    SetCurrentVerse(verse);
                }
                else
                {
                    m_active_textbox.SelectionChanged += new EventHandler(MainTextBox_SelectionChanged);
                }
            }
        }
        finally
        {
            m_active_textbox.EndUpdate();
            // already re-wired above, see #######
            //m_active_textbox.SelectionChanged += new EventHandler(MainTextBox_SelectionChanged);
        }
    }
Exemple #16
0
    private int GetVerseDisplayStart(Verse verse)
    {
        int start = 0;
        if (m_client != null)
        {
            List<Verse> verses = null;
            if (m_found_verses_displayed)
            {
                verses = m_client.FoundVerses;
            }
            else
            {
                if (m_client.Selection != null)
                {
                    verses = m_client.Selection.Verses;
                }
            }

            if (verses != null)
            {
                if (verse != null)
                {
                    foreach (Verse v in verses)
                    {
                        if (v == verse) break;

                        if (m_found_verses_displayed)
                        {//                            \t                  \n
                            start += v.Address.Length + 1 + v.Text.Length + 1;
                        }
                        else
                        {
                            start += v.Text.Length + v.Endmark.Length;
                        }
                    }
                }
            }
        }
        return start;
    }
Exemple #17
0
 private int GetVerseIndex(Verse verse)
 {
     List<Verse> verses = null;
     if (m_found_verses_displayed)
     {
         verses = m_client.FoundVerses;
     }
     else
     {
         if (m_client.Selection != null)
         {
             verses = m_client.Selection.Verses;
         }
     }
     if (verses != null)
     {
         int verse_index = -1;
         foreach (Verse v in verses)
         {
             verse_index++;
             if (v == verse)
             {
                 return verse_index;
             }
         }
     }
     return -1;
 }
Exemple #18
0
 private int GetVerseDisplayLength(Verse verse)
 {
     int length = 0;
     if (verse != null)
     {
         if (m_found_verses_displayed)
         {//                                \t                       \n
             length = verse.Address.Length + 1 + verse.Text.Length + 1;
         }
         else
         {//                                 { # }  or  \n
             length = verse.Text.Length + verse.Endmark.Length;
         }
     }
     return length;
 }
Exemple #19
0
    private void FindBySimilarity()
    {
        if (m_client != null)
        {
            PrepareNewSearch();

            SimilarityMethod find_by_similarity_method = SimilarityMethod.SimilarText;
            if (FindBySimilaritySimilarTextRadioButton.Checked)
            {
                find_by_similarity_method = SimilarityMethod.SimilarText;
            }
            else if (FindBySimilaritySimilarWordsRadioButton.Checked)
            {
                find_by_similarity_method = SimilarityMethod.SimilarWords;
            }
            else if (FindBySimilaritySimilarFirstHalfRadioButton.Checked)
            {
                find_by_similarity_method = SimilarityMethod.SimilarFirstHalf;
            }
            else if (FindBySimilaritySimilarLastHalfRadioButton.Checked)
            {
                find_by_similarity_method = SimilarityMethod.SimilarLastHalf;
            }
            else if (FindBySimilaritySimilarFirstWordRadioButton.Checked)
            {
                find_by_similarity_method = SimilarityMethod.SimilarFirstWord;
            }
            else if (FindBySimilaritySimilarLastWordRadioButton.Checked)
            {
                find_by_similarity_method = SimilarityMethod.SimilarLastWord;
            }
            else
            {
                //
            }

            double similarity_percentage = (double)FindBySimilarityPercentageTrackBar.Value / 100.0D;

            string similarity_source = null;
            if (m_similarity_source == SimilaritySource.Verse)
            {
                if (m_similarity_current_verse == null)
                {
                    m_similarity_current_verse = GetCurrentVerse();
                }
                if (m_similarity_current_verse != null)
                {
                    if (m_similarity_current_verse.Chapter != null)
                    {
                        m_client.FindVerses(m_similarity_current_verse, find_by_similarity_method, similarity_percentage);
                        similarity_source = " to verse " + m_similarity_current_verse.Chapter.Name + " " + m_similarity_current_verse.NumberInChapter + " ";
                    }
                }
            }
            else if (m_similarity_source == SimilaritySource.Book)
            {
                m_client.FindVerseRanges(find_by_similarity_method, similarity_percentage);
                similarity_source = null;
            }
            else
            {
                //
            }

            if (m_client.FoundVerses != null)
            {
                int verse_count = m_client.FoundVerses.Count;
                m_find_result_header = verse_count + ((verse_count == 1) ? " verse" : " verses") + " with " + find_by_similarity_method.ToString() + similarity_source + " in " + m_client.FindScope.ToString();

                DisplayFoundVerses(true);
            }
        }
    }
Exemple #20
0
    private void DownloadVerseAudioFile(Verse verse)
    {
        // mirror remote_folder locally
        string audio_folder = Globals.AUDIO_FOLDER + "/" + m_reciter;
        if (!Directory.Exists(audio_folder))
        {
            Directory.CreateDirectory(audio_folder);
        }

        // generate audio_filename from verse address
        string audio_filename = null;
        string full_audio_folder = null;
        if (verse == null)
        {
            audio_filename = "001000" + "." + RecitationInfo.FileType; // audhubillah
            full_audio_folder = audio_folder + "/" + "001";
        }
        else
        {
            if (verse.Chapter != null)
            {
                audio_filename = verse.Chapter.Number.ToString("000") + verse.NumberInChapter.ToString("000") + "." + RecitationInfo.FileType;
                full_audio_folder = audio_folder + "/" + verse.Chapter.Number.ToString("000");
            }
        }

        // fill up local_audio_filename to return to caller
        m_downloaded_audio_filename = full_audio_folder + "/" + audio_filename;
        string outer_downloaded_audio_filename = audio_folder + "/" + audio_filename;
        if (File.Exists(m_downloaded_audio_filename))
        {
            // no need to download
        }
        else if (File.Exists(outer_downloaded_audio_filename))
        {
            if (!Directory.Exists(full_audio_folder))
            {
                Directory.CreateDirectory(full_audio_folder);
            }

            if (Directory.Exists(full_audio_folder))
            {
                File.Move(outer_downloaded_audio_filename, m_downloaded_audio_filename);
            }
        }
        else
        {
            // try to download audio file

            string recitation_url = null;
            foreach (string key in m_client.Book.RecitationInfos.Keys)
            {
                if (m_client.Book.RecitationInfos[key].Folder == m_reciter)
                {
                    recitation_url = RecitationInfo.UrlPrefix + m_client.Book.RecitationInfos[key].Url + "/" + audio_filename;
                    break;
                }
            }

            DownloadFile(recitation_url, m_downloaded_audio_filename);
        }
    }
Exemple #21
0
 public static List<Phrase> BuildPhrases(Verse verse, MatchCollection matches)
 {
     List<Phrase> result = new List<Phrase>();
     foreach (Match match in matches)
     {
         foreach (Capture capture in match.Captures)
         {
             string text = capture.Value;
             int position = capture.Index;
             Phrase phrase = new Phrase(verse, position, text);
             if (phrase != null)
             {
                 result.Add(phrase);
             }
         }
     }
     return result;
 }
Exemple #22
0
    private void HighlightVerse(Verse verse)
    {
        try
        {
            m_active_textbox.SelectionChanged -= new EventHandler(MainTextBox_SelectionChanged);
            m_active_textbox.BeginUpdate();

            if (m_client != null)
            {
                // de-highlight previous verse
                if (m_previous_highlighted_verse != null)
                {
                    int start = GetVerseDisplayStart(m_previous_highlighted_verse);
                    int length = GetVerseDisplayLength(m_previous_highlighted_verse);
                    m_active_textbox.ClearHighlight(start, length);
                }

                // highlight this verse
                if (verse != null)
                {
                    int start = GetVerseDisplayStart(verse);
                    int length = GetVerseDisplayLength(verse);
                    m_active_textbox.Highlight(start, length - 1, Color.Lavender); // -1 so de-highlighting can clean the last \n at the end of all text

                    // re-wire MainTextBox_SelectionChanged event to
                    // updates verse position and value when cursor goes to start of verse
                    // #######
                    m_active_textbox.SelectionChanged += new EventHandler(MainTextBox_SelectionChanged);
                    m_active_textbox.Select(start, 0);

                    SetCurrentVerse(verse);

                    // backup highlighted verse
                    m_previous_highlighted_verse = verse;
                }
                else
                {
                    m_active_textbox.SelectionChanged += new EventHandler(MainTextBox_SelectionChanged);
                }
            }
        }
        finally
        {
            m_active_textbox.EndUpdate();
            // already re-wired above, see #######
            //m_active_textbox.SelectionChanged += new EventHandler(MainTextBox_SelectionChanged);
        }
    }
Exemple #23
0
    public static List<Phrase> BuildPhrasesAndOriginify(Verse verse, MatchCollection matches)
    {
        List<Phrase> result = new List<Phrase>();
        foreach (Match match in matches)
        {
            foreach (Capture capture in match.Captures)
            {
                string text = capture.Value;
                int position = capture.Index;
                Phrase phrase = new Phrase(verse, position, text);

                if (s_numerology_system.TextMode.Contains("Original"))
                {
                    OriginifyPhrase(ref phrase);
                }

                if (phrase != null)
                {
                    result.Add(phrase);
                }
            }
        }
        return result;
    }
Exemple #24
0
    private void DisplayTranslationAllowingEdit(Verse verse)
    {
        if (verse != null)
        {
            StringBuilder str = new StringBuilder();
            if (TranslatorComboBox.SelectedItem != null)
            {
                string name = TranslatorComboBox.SelectedItem.ToString();
                string key = m_client.GetTranslationKey(name);
                if (verse.Translations.ContainsKey(key))
                {
                    str.Append(verse.PaddedAddress + VERSE_ADDRESS_TRANSLATION_SEPARATOR + verse.Translations[key]);
                }
            }
            TranslationTextBox.WordWrap = true;
            TranslationTextBox.Text = str.ToString();
            TranslationTextBox.Refresh();
            m_translated_verses.Clear();
            m_translated_verses.Add(verse);

            m_readonly_mode = false;
            TranslationTextBox_ToggleReadOnly();
            EditVerseTranslationLabel.Visible = true;
        }
    }
Exemple #25
0
 private static long CalculateEndPartValue(Verse verse, int from_letter_index)
 {
     return CalculateMiddlePartValue(verse, from_letter_index, verse.LetterCount - 1);
 }
Exemple #26
0
 private static List<Verse> DoFindVerses(Book book, FindScope find_scope, Selection current_selection, List<Verse> previous_result, Verse verse, SimilarityMethod similarity_method, double similarity_percentage)
 {
     List<Verse> source = GetSourceVerses(book, find_scope, current_selection, previous_result);
     return DoFindVerses(source, find_scope, current_selection, previous_result, verse, similarity_method, similarity_percentage);
 }
Exemple #27
0
    public static Book BuildSimplifiedBook(string numerology_system_name)
    {
        Book book = null;

        string[] parts = numerology_system_name.Split('_');
        if (parts.Length == 3)
        {
            string text_mode = parts[0];

            string[] verse_stopmarks = DataAccess.LoadVerseStopmarks(); // (c)2014 Hadi Al-Thehabi
            string[] verse_texts = DataAccess.LoadVerseTexts(text_mode);    // load Original text

            // load simplification rules
            LoadSimplificationSystem(text_mode);

            if (text_mode.Contains("Shadda"))
            {
                for (int l = 0; l < verse_texts.Length; l++)
                {
                    StringBuilder str = new StringBuilder(verse_texts[l]);
                    for (int i = 1; i < str.Length; i++)
                    {
                        if (str[i] == 'ّ') // replace shedda with previous letter
                        {
                            str[i] = str[i - 1];
                        }
                    }
                    verse_texts[l] = str.ToString();
                }
            }

            List<Verse> verses = new List<Verse>(Verse.MAX_NUMBER);
            for (int i = 0; i < verse_texts.Length; i++)
            {
                string simplified_text = s_simplification_system.Simplify(verse_texts[i]);

                // set stopmark for verse as complied by Hadi Al-Thehabi
                Stopmark verse_stopmark = Stopmark.None;
                switch (verse_stopmarks[i])
                {
                    case "": // treat empty line as Meem
                        verse_stopmark = Stopmark.MustStop;
                        break;
                    case "ۙ": // Laaa
                        verse_stopmark = Stopmark.MustContinue;
                        break;
                    case "ۖ": // Sala
                        verse_stopmark = Stopmark.ShouldContinue;
                        break;
                    case "ۚ": // Jeem
                        verse_stopmark = Stopmark.CanStop;
                        break;
                    case "ۛ": // Dots
                        verse_stopmark = Stopmark.CanStopAtOneOnly;
                        break;
                    case "ۗ": // Qala
                        verse_stopmark = Stopmark.ShouldStop;
                        break;
                    case "ۜ": // Seen
                        verse_stopmark = Stopmark.MustPause;
                        break;
                    case "ۘ": // Meem
                        verse_stopmark = Stopmark.MustStop;
                        break;
                    default:
                        verse_stopmark = Stopmark.MustStop;
                        break;
                }
                Verse verse = new Verse(i + 1, simplified_text, verse_stopmark);

                // update word stopmarks
                verse.BuildWords(text_mode, verse_texts[i]);
                verses.Add(verse);
            }

            book = new Book(text_mode, verses);
            if (book != null)
            {
                DataAccess.LoadRecitationInfos(book);
                DataAccess.LoadTranslationInfos(book);
                DataAccess.LoadTranslations(book);
                DataAccess.LoadWordMeanings(book);
                DataAccess.LoadRootWords(book);
                DataAccess.LoadWordRoots(book);
                if ((Globals.EDITION == Edition.Grammar) || (Globals.EDITION == Edition.Research))
                {
                    DataAccess.LoadWordParts(book);
                }

                // load numerology system
                LoadNumerologySystem(numerology_system_name, book, book.Text);

                // must be done after loading word info (because they assume 77878 words)
                if (text_mode.Contains("Waw"))
                {
                    UpdateBookBySplittingWawWordsIntoTwo(book);
                }
            }
        }

        return book;
    }
Exemple #28
0
 // find by similarity - verse similar to given verse
 public static List<Verse> FindVerses(Book book, FindScope find_scope, Selection current_selection, List<Verse> previous_result, Verse verse, SimilarityMethod similarity_method, double similarity_percentage)
 {
     return DoFindVerses(book, find_scope, current_selection, previous_result, verse, similarity_method, similarity_percentage);
 }
Exemple #29
0
    public static long CalculateValue(Verse verse)
    {
        if (verse == null) return 0L;

        long result = 0L;
        if (s_numerology_system != null)
        {
            // adjust value of verse
            result += AdjustVerseValue(verse);

            foreach (Word word in verse.Words)
            {
                // adjust value of word
                result += AdjustWordValue(word);

                foreach (Letter letter in word.Letters)
                {
                    // adjust value of letter
                    result += AdjustLetterValue(letter);

                    // calculate the letter static value
                    result += s_numerology_system.CalculateValue(letter.Character);
                }
            }

            verse.Value = result;
        }
        return result;
    }
Exemple #30
0
 private void DisplayVersesWordsLetters(Verse verse)
 {
     if (verse != null)
     {
         int verse_count = 1;
         int word_count = verse.Words.Count;
         int letter_count = verse.LetterCount;
         int verse_number_sum = verse.NumberInChapter;
         int word_number_sum = 0;
         int letter_number_sum = 0;
         foreach (Word word in verse.Words)
         {
             word_number_sum += word.NumberInVerse;
             foreach (Letter letter in word.Letters)
             {
                 letter_number_sum += letter.NumberInWord;
             }
         }
         DisplayVersesWordsLetters(verse_count, word_count, letter_count, verse_number_sum, word_number_sum, letter_number_sum);
     }
 }
Exemple #31
0
 private static List<Verse> DoFindVerses(List<Verse> source, FindScope find_scope, Selection current_selection, List<Verse> previous_result, Verse verse, SimilarityMethod find_similarity_method, double similarity_percentage)
 {
     List<Verse> result = new List<Verse>();
     if (source != null)
     {
         if (source.Count > 0)
         {
             Book book = source[0].Book;
             if (verse != null)
             {
                 switch (find_similarity_method)
                 {
                     case SimilarityMethod.SimilarText:
                         {
                             for (int j = 0; j < source.Count; j++)
                             {
                                 if (verse.Text.IsSimilarTo(source[j].Text, similarity_percentage))
                                 {
                                     result.Add(source[j]);
                                 }
                             }
                         }
                         break;
                     case SimilarityMethod.SimilarWords:
                         {
                             for (int j = 0; j < source.Count; j++)
                             {
                                 if (verse.Text.HasSimilarWordsTo(source[j].Text, (int)Math.Round((Math.Min(verse.Words.Count, source[j].Words.Count) * similarity_percentage)), 1.0))
                                 {
                                     result.Add(source[j]);
                                 }
                             }
                         }
                         break;
                     case SimilarityMethod.SimilarFirstHalf:
                         {
                             for (int j = 0; j < source.Count; j++)
                             {
                                 if (verse.Text.HasSimilarFirstHalfTo(source[j].Text, similarity_percentage))
                                 {
                                     result.Add(source[j]);
                                 }
                             }
                         }
                         break;
                     case SimilarityMethod.SimilarLastHalf:
                         {
                             for (int j = 0; j < source.Count; j++)
                             {
                                 if (verse.Text.HasSimilarLastHalfTo(source[j].Text, similarity_percentage))
                                 {
                                     result.Add(source[j]);
                                 }
                             }
                         }
                         break;
                     case SimilarityMethod.SimilarFirstWord:
                         {
                             for (int j = 0; j < source.Count; j++)
                             {
                                 if (verse.Text.HasSimilarFirstWordTo(source[j].Text, similarity_percentage))
                                 {
                                     result.Add(source[j]);
                                 }
                             }
                         }
                         break;
                     case SimilarityMethod.SimilarLastWord:
                         {
                             for (int j = 0; j < source.Count; j++)
                             {
                                 if (verse.Text.HasSimilarLastWordTo(source[j].Text, similarity_percentage))
                                 {
                                     result.Add(source[j]);
                                 }
                             }
                         }
                         break;
                     default:
                         break;
                 }
             }
         }
     }
     return result;
 }
Exemple #32
0
 public Phrase(Verse verse, int position, string text)
 {
     this.verse = verse;
     this.text = text;
     this.position = position;
 }
Exemple #33
0
 public Phrase(Verse verse, int position, string text)
 {
     this.verse    = verse;
     this.text     = text;
     this.position = position;
 }
Exemple #34
0
    private void DisplayTranslations(Verse verse)
    {
        if (verse != null)
        {
            if (EditVerseTranslationLabel.Visible)
            {
                // display in edit mode
                DisplayTranslationAllowingEdit(verse);
            }
            else
            {
                //[ar.emlaaei   ]	001:006 اهْدِنَا الصِّرَاطَ الْمُسْتَقِيمَ
                //[en.pickthall ]	001:006 Show us the straight path,
                //[en.qarai     ]	001:006 Guide us on the straight path,
                //[en.transliter]	001:006 Ihdina alssirata almustaqeema
                //[en.wordbyword]	001:006 Guide us	(to) the path,	the straight,
                StringBuilder str = new StringBuilder();
                if (m_checked_keys.Count > 0)
                {
                    foreach (string key in m_checked_keys)
                    {
                        if (verse.Translations.ContainsKey(key))
                        {
                            str.AppendLine("[" + key.Pad(13) + "]\t" + verse.PaddedAddress + VERSE_ADDRESS_TRANSLATION_SEPARATOR + verse.Translations[key]);
                        }
                    }
                    if (str.Length > 2)
                    {
                        str.Remove(str.Length - 2, 2);
                    }
                }

                m_translated_verses.Clear();
                m_translated_verses.Add(verse);

                TranslationTextBox.WordWrap = false;
                TranslationTextBox.Text = str.ToString();
                TranslationTextBox.Refresh();

                m_readonly_mode = false;
                TranslationTextBox_ToggleReadOnly();
                EditVerseTranslationLabel.Visible = false;
            }
        }
        else
        {
            TranslationTextBox.WordWrap = false;
            TranslationTextBox.Text = "";
            TranslationTextBox.Refresh();

            m_readonly_mode = false;
            TranslationTextBox_ToggleReadOnly();
            EditVerseTranslationLabel.Visible = false;
        }
    }