Пример #1
0
 private static List<Word> DoFindWords(List<Verse> source, string phrase, int letter_frequency_sum, FrequencySumType frequency_sum_type)
 {
     List<Word> result = new List<Word>();
     if (!string.IsNullOrEmpty(phrase))
     {
         if (source != null)
         {
             if (source.Count > 0)
             {
                 Book book = source[0].Book;
                 if (!String.IsNullOrEmpty(phrase))
                 {
                     if (letter_frequency_sum > 0)
                     {
                         foreach (Verse verse in source)
                         {
                             if (verse != null)
                             {
                                 foreach (Word word in verse.Words)
                                 {
                                     string text = word.Text;
                                     if (CalculateLetterFrequencySum(text, phrase, frequency_sum_type) == letter_frequency_sum)
                                     {
                                         result.Add(word);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return result;
 }
Пример #2
0
 // find by letter frequency sum
 public static List<Word> FindWords(Book book, FindScope find_scope, Selection current_selection, List<Verse> previous_result, string phrase, int letter_frequency_sum, FrequencySumType frequency_sum_type)
 {
     return DoFindWords(book, find_scope, current_selection, previous_result, phrase, letter_frequency_sum, frequency_sum_type);
 }
Пример #3
0
    private static List<Sentence> DoFindSentences(List<Verse> source, string phrase, int letter_frequency_sum, FrequencySumType frequency_sum_type)
    {
        List<Sentence> result = new List<Sentence>();
        if (!string.IsNullOrEmpty(phrase))
        {
            if (source != null)
            {
                if (source.Count > 0)
                {
                    if (!String.IsNullOrEmpty(phrase))
                    {
                        if (letter_frequency_sum > 0)
                        {
                            List<Word> words = new List<Word>();
                            foreach (Verse verse in source)
                            {
                                words.AddRange(verse.Words);
                            }

                            // scan linearly for sequence of words with total Text matching letter_frequency_sum
                            for (int i = 0; i < words.Count - 1; i++)
                            {
                                StringBuilder str = new StringBuilder();

                                // start building word sequence
                                str.Append(words[i].Text);

                                string stopmark_text;
                                switch (words[i].Stopmark)
                                {
                                    case Stopmark.None: // none
                                        stopmark_text = "";
                                        break;
                                    case Stopmark.MustContinue:
                                        stopmark_text = "ۙ"; // Laaa
                                        break;
                                    case Stopmark.ShouldContinue:
                                        stopmark_text = "ۖ"; // Sala
                                        break;
                                    case Stopmark.CanStop:
                                        stopmark_text = "ۚ"; // Jeem
                                        break;
                                    case Stopmark.CanStopAtOneOnly:
                                        stopmark_text = "ۛ"; // Dots
                                        break;
                                    case Stopmark.ShouldStop:
                                        stopmark_text = "ۗ"; // Qala
                                        break;
                                    case Stopmark.MustPause:
                                        stopmark_text = "ۜ"; // Seen
                                        break;
                                    case Stopmark.MustStop:
                                        stopmark_text = "ۘ"; // Meem
                                        break;
                                    default:
                                        stopmark_text = "ۘ"; // Meem;
                                        break;
                                }

                                // if word has no stopmark or must continue
                                if ((words[i].Stopmark == Stopmark.None) || (words[i].Stopmark == Stopmark.MustContinue))
                                {
                                    // continue building with next words until a stopmark
                                    for (int j = i + 1; j < words.Count; j++)
                                    {
                                        str.Append(" " + words[j].Text);

                                        if (words[j].Stopmark == Stopmark.None)
                                        {
                                            continue; // continue building sentence
                                        }
                                        else // there is a stopmark
                                        {
                                            if (NumerologySystem.TextMode.Contains("Original"))
                                            {
                                                str.Append(" " + stopmark_text);
                                            }

                                            if (words[j].Stopmark == Stopmark.MustContinue)
                                            {
                                                continue; // continue building sentence
                                            }
                                            else if (
                                                (words[j].Stopmark == Stopmark.CanStopAtOneOnly) ||
                                                (words[j].Stopmark == Stopmark.ShouldContinue) ||
                                                (words[j].Stopmark == Stopmark.CanStop) ||
                                                (words[j].Stopmark == Stopmark.ShouldStop)
                                                )
                                            {
                                                // a sub sentence completed
                                                Sentence sentence = new Sentence(words[i].Verse, words[i].Position, words[j].Verse, words[j].Position + words[j].Text.Length, str.ToString());
                                                if (sentence != null)
                                                {
                                                    if (CalculateLetterFrequencySum(str.ToString(), phrase, frequency_sum_type) == letter_frequency_sum)
                                                    {
                                                        result.Add(sentence);
                                                    }
                                                }
                                                continue; // continue building a longer senetence
                                            }
                                            else if (words[j].Stopmark == Stopmark.MustPause)
                                            {
                                                if (
                                                    (words[j].Text.Simplify29() == "مَنْ".Simplify29()) ||
                                                    (words[j].Text.Simplify29() == "بَلْ".Simplify29())
                                                   )
                                                {
                                                    continue; // continue building a longer senetence
                                                }
                                                else if (
                                                    (words[j].Text.Simplify29() == "عِوَجَا".Simplify29()) ||
                                                    (words[j].Text.Simplify29() == "مَّرْقَدِنَا".Simplify29()) ||
                                                    (words[j].Text.Simplify29() == "مَالِيَهْ".Simplify29())
                                                    )
                                                {
                                                    // a sub sentence completed
                                                    Sentence sentence = new Sentence(words[i].Verse, words[i].Position, words[j].Verse, words[j].Position + words[j].Text.Length, str.ToString());
                                                    if (sentence != null)
                                                    {
                                                        if (CalculateLetterFrequencySum(str.ToString(), phrase, frequency_sum_type) == letter_frequency_sum)
                                                        {
                                                            result.Add(sentence);
                                                        }
                                                    }
                                                    continue; // continue building a longer senetence
                                                }
                                                else // unknown case
                                                {
                                                    throw new Exception("Unknown stopmark in Quran text.");
                                                }
                                            }
                                            else if (words[j].Stopmark == Stopmark.MustStop)
                                            {
                                                // sentence completed
                                                Sentence sentence = new Sentence(words[i].Verse, words[i].Position, words[j].Verse, words[j].Position + words[j].Text.Length, str.ToString());
                                                if (sentence != null)
                                                {
                                                    if (CalculateLetterFrequencySum(str.ToString(), phrase, frequency_sum_type) == letter_frequency_sum)
                                                    {
                                                        result.Add(sentence);
                                                    }
                                                }

                                                i = j; // start a new sentence after j
                                                break; // break j, start next i = j
                                            }
                                            else // unknown case
                                            {
                                                throw new Exception("Unknown stopmark in Quran text.");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return result;
    }
Пример #4
0
 private static List<Word> DoFindWords(Book book, FindScope find_scope, Selection current_selection, List<Verse> previous_result, string phrase, int letter_frequency_sum, FrequencySumType frequency_sum_type)
 {
     List<Verse> source = GetSourceVerses(book, find_scope, current_selection, previous_result);
     return DoFindWords(source, phrase, letter_frequency_sum, frequency_sum_type);
 }
Пример #5
0
    private static int CalculateLetterFrequencySum(string text, string phrase, FrequencySumType frequency_sum_type)
    {
        if (String.IsNullOrEmpty(phrase)) return 0;
        if (s_numerology_system == null) return -1;

        int result = 0;

        text = text.SimplifyTo(NumerologySystem.TextMode);
        text = text.Replace("\r", "");
        text = text.Replace("\n", "");
        text = text.Replace("\t", "");
        text = text.Replace(" ", "");
        text = text.Replace(Verse.OPEN_BRACKET, "");
        text = text.Replace(Verse.CLOSE_BRACKET, "");

        phrase = phrase.SimplifyTo(NumerologySystem.TextMode);
        phrase = phrase.Replace("\r", "");
        phrase = phrase.Replace("\n", "");
        phrase = phrase.Replace("\t", "");
        phrase = phrase.Replace(" ", "");
        phrase = phrase.Replace(Verse.OPEN_BRACKET, "");
        phrase = phrase.Replace(Verse.CLOSE_BRACKET, "");
        if (frequency_sum_type == FrequencySumType.NoDuplicates)
        {
            phrase = phrase.RemoveDuplicates();
        }

        for (int i = 0; i < phrase.Length; i++)
        {
            int frequency = 0;
            for (int j = 0; j < text.Length; j++)
            {
                if (phrase[i] == text[j])
                {
                    frequency++;
                }
            }

            if (frequency > 0)
            {
                result += frequency;
            }
        }

        return result;
    }
Пример #6
0
    private void FindByFrequencySumTypeLabel_Click(object sender, EventArgs e)
    {
        if (m_frequency_sum_type == FrequencySumType.NoDuplicates)
        {
            m_frequency_sum_type = FrequencySumType.Duplicates;
            FindByFrequencySumTypeLabel.Text = "DUPLICATE LETTERS";
            FindByFrequencySumTypeLabel.BackColor = Color.PaleVioletRed;
            ToolTip.SetToolTip(FindByFrequencySumTypeLabel, "include duplicate phrase letters");
        }
        else if (m_frequency_sum_type == FrequencySumType.Duplicates)
        {
            m_frequency_sum_type = FrequencySumType.NoDuplicates;
            FindByFrequencySumTypeLabel.Text = "NO DUPLICATE LETTERS";
            FindByFrequencySumTypeLabel.BackColor = Color.DarkGray;
            ToolTip.SetToolTip(FindByFrequencySumTypeLabel, "exclude duplicate phrase letters");
        }
        FindByFrequencyControls_Enter(null, null);

        CalculatePhraseLetterStatistics();
        DisplayPhraseLetterStatistics();
    }
Пример #7
0
 /// <summary>
 /// Find verses with required letter frequency sum in their text of the given phrase.
 /// </summary>
 /// <param name="phrase"></param>
 /// <param name="letter_frequency_sum"></param>
 /// <param name="frequency_sum_type"></param>
 /// <returns>Number of found verses. Result is stored in FoundVerses.</returns>
 public int FindVerses(string phrase, int letter_frequency_sum, FrequencySumType frequency_sum_type)
 {
     m_found_verses = Server.FindVerses(m_book, m_find_scope, m_selection, m_found_verses, phrase, letter_frequency_sum, frequency_sum_type);
     if (m_found_verses != null)
     {
         return m_found_verses.Count;
     }
     return 0;
 }
Пример #8
0
    /// <summary>
    /// Calculate letter statistics for the given phrase in text.
    /// </summary>
    /// <param name="text"></param>
    /// <param name="phrase"></param>
    /// <param name="frequency_sum_type"></param>
    /// <returns>Letter frequency sum. Result is stored in PhraseLetterStatistics.</returns>
    public int CalculatePhraseLetterStatistics(string text, string phrase, FrequencySumType frequency_sum_type)
    {
        if (String.IsNullOrEmpty(text)) return 0;
        if (String.IsNullOrEmpty(phrase)) return 0;
        if (NumerologySystem == null) return -1;
        if (m_phrase_letter_statistics == null) return -1;

        text = text.SimplifyTo(NumerologySystem.TextMode);
        text = text.Replace("\r", "");
        text = text.Replace("\n", "");
        text = text.Replace("\t", "");
        text = text.Replace(" ", "");
        text = text.Replace(Verse.OPEN_BRACKET, "");
        text = text.Replace(Verse.CLOSE_BRACKET, "");

        phrase = phrase.SimplifyTo(NumerologySystem.TextMode);
        phrase = phrase.Replace("\r", "");
        phrase = phrase.Replace("\n", "");
        phrase = phrase.Replace("\t", "");
        phrase = phrase.Replace(" ", "");
        phrase = phrase.Replace(Verse.OPEN_BRACKET, "");
        phrase = phrase.Replace(Verse.CLOSE_BRACKET, "");
        if (frequency_sum_type == FrequencySumType.NoDuplicates)
        {
            phrase = phrase.RemoveDuplicates();
        }

        int letter_frequency_sum = 0;
        m_phrase_letter_statistics.Clear();
        for (int i = 0; i < phrase.Length; i++)
        {
            int frequency = 0;
            for (int j = 0; j < text.Length; j++)
            {
                if (phrase[i] == text[j])
                {
                    frequency++;
                }
            }

            if (frequency > 0)
            {
                LetterStatistic phrase_letter_statistic = new LetterStatistic();
                phrase_letter_statistic.Order = m_phrase_letter_statistics.Count + 1;
                phrase_letter_statistic.Letter = phrase[i];
                phrase_letter_statistic.Frequency = frequency;
                m_phrase_letter_statistics.Add(phrase_letter_statistic);
                letter_frequency_sum += frequency;
            }
        }

        return letter_frequency_sum;
    }
Пример #9
0
    // find by letter frequency sum
    /// <summary>
    /// Find words with required letter frequency sum in their text of the given phrase.
    /// </summary>
    /// <param name="phrase"></param>
    /// <param name="letter_frequency_sum"></param>
    /// <param name="frequency_sum_type"></param>
    /// <returns>Number of found words. Result is stored in FoundWords.</returns>
    public int FindWords(string phrase, int letter_frequency_sum, FrequencySumType frequency_sum_type)
    {
        m_found_words = Server.FindWords(m_book, m_find_scope, m_selection, m_found_verses, phrase, letter_frequency_sum, frequency_sum_type);
        if (m_found_words != null)
        {
            m_found_verses = new List<Verse>();
            m_found_phrases = new List<Phrase>();
            foreach (Word word in m_found_words)
            {
                if (word != null)
                {
                    Verse verse = word.Verse;
                    if (!m_found_verses.Contains(verse))
                    {
                        m_found_verses.Add(verse);
                    }
                }

                Phrase word_phrase = new Phrase(word.Verse, word.Position, word.Text);
                m_found_phrases.Add(word_phrase);
            }

            return m_found_words.Count;
        }
        return 0;
    }