예제 #1
0
        public static Dictionary <string, double> BigramFrequancy(string path, bool touchable, bool spaces)
        {
            var cleartext = TextPrepearing.Remove_Nonlaters(TextPrepearing.Parse(path), spaces);

            var allbigrams = Ngrams.AllBigrams();
            var bigrams    = new Dictionary <string, double>();

            foreach (string x in allbigrams)
            {
                bigrams.Add(x, 0);
            }

            if (touchable)
            {
                for (int i = 0; i < cleartext.Length - 1; i++)
                {
                    bigrams[$"{cleartext[i]}" + $"{cleartext[i + 1]}"]++;
                }
            }
            else
            {
                for (int i = 0; i < cleartext.Length - 1; i += 2)
                {
                    bigrams[$"{cleartext[i]}" + $"{cleartext[i + 1]}"]++;
                }
            }
            int final_lenght;

            if (touchable)
            {
                final_lenght = cleartext.Length - 1;
            }
            else
            {
                final_lenght = cleartext.Length / 2;
            }

            bigrams = bigrams.ToDictionary(kvp => kvp.Key, kvp => kvp.Value / final_lenght);

            return(bigrams.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value));;
        }
예제 #2
0
        public static Dictionary <char, double> MonogarmsFrequency(string path, bool spaces)
        {
            var cleartext = TextPrepearing.Remove_Nonlaters(TextPrepearing.Parse(path), spaces);

            var alphabet  = Ngrams.Alphabet();
            var monograms = new Dictionary <char, double>();

            foreach (char c in alphabet)
            {
                monograms.Add(c, 0);
            }

            foreach (char x in cleartext)
            {
                monograms[x]++;
            }

            var final_lenght = cleartext.Length;

            monograms = monograms.ToDictionary(kvp => kvp.Key, kvp => kvp.Value / final_lenght);

            return(monograms.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value));;
        }