示例#1
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;
    }
示例#2
0
    private static void UpdateLetterStatistics(string dynamic_text)
    {
        if (String.IsNullOrEmpty(dynamic_text)) return;

        if (s_letter_statistics != null)
        {
            s_letter_statistics.Clear();
            for (int i = 0; i < dynamic_text.Length; i++)
            {
                // calculate letter frequency
                bool is_found = false;
                for (int j = 0; j < s_letter_statistics.Count; j++)
                {
                    if (dynamic_text[i] == s_letter_statistics[j].Letter)
                    {
                        s_letter_statistics[j].Frequency++;
                        is_found = true;
                        break;
                    }
                }

                // add entry into dictionary
                if (!is_found)
                {
                    LetterStatistic letter_statistic = new LetterStatistic();
                    letter_statistic.Order = s_letter_statistics.Count + 1;
                    letter_statistic.Letter = dynamic_text[i];
                    letter_statistic.Frequency++;
                    s_letter_statistics.Add(letter_statistic);
                }
            }
        }
    }
示例#3
0
    /// <summary>
    /// Calculate letter statistics for the given text.
    /// </summary>
    /// <param name="text"></param>
    /// <param name="phrase"></param>
    /// <param name="frequency_sum_type"></param>
    /// <returns>Result is stored in LetterStatistics.</returns>
    public void CalculateLetterStatistics(string text)
    {
        if (String.IsNullOrEmpty(text)) return;

        if (NumerologySystem != null)
        {
            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, "");

        m_letter_statistics.Clear();
        for (int i = 0; i < text.Length; i++)
        {
            bool is_found = false;
            for (int j = 0; j < m_letter_statistics.Count; j++)
            {
                if (text[i] == m_letter_statistics[j].Letter)
                {
                    is_found = true;
                    m_letter_statistics[j].Frequency++;
                }
            }

            if (!is_found)
            {
                LetterStatistic letter_statistic = new LetterStatistic();
                letter_statistic.Order = m_letter_statistics.Count + 1;
                letter_statistic.Letter = text[i];
                letter_statistic.Frequency++;
                m_letter_statistics.Add(letter_statistic);
            }
        }
    }