예제 #1
0
        public TextToCheck MakeFrequency(TextToCheck textToCheck)
        {
            foreach (char c in textToCheck.Text)
            {
                if (c >= 97 && c <= 122)
                {
                    textToCheck.Frequency[c - 97]++;
                }
                else
                {
                    textToCheck.Frequency[26]++;
                }
            }

            return(textToCheck);
        }
예제 #2
0
        public TextToCheck ComparingLanguage(TextToCheck textToCheck, Frequencies freq)
        {
            var frequencies = freq.DeserializeJson();

            List <int>      FreqId   = new List <int>();
            List <string>   LangName = new List <string>();
            List <double[]> Freq     = new List <double[]>();

            foreach (var item in frequencies.frequencies)
            {
                FreqId.Add(item.FrequencyId);
                LangName.Add(item.LanguageName);
                Freq.Add(item.Frequency);
            }

            // Comparison frequencies of text with frequencies language
            int a = 0;
            int i = 0;

            for (a = 0; a < 6; a++)
            {
                double[] TempText = new double[27];

                for (i = 0; i < 26; i++)
                {
                    TempText[i] = textToCheck.Frequency[i] / textToCheck.TextLength;
                    TempText[i] = TempText[i] - Freq[a][i];
                    if (TempText[i] < 0)
                    {
                        TempText[i] = -TempText[i];
                    }
                    textToCheck.Distance[a] = textToCheck.Distance[a] + TempText[i];
                }
            }

            double Language      = textToCheck.Distance.Min();
            int    WhichLanguage = Array.IndexOf(textToCheck.Distance, Language);

            textToCheck.WonLanguage = LangName[WhichLanguage];

            return(textToCheck);
        }