public static LetterFrequency GenerateFrequency(string Data) { LetterFrequency output = new LetterFrequency(); foreach (var character in Data) { output.Add(character); } return(output); }
public double Compare(LetterFrequency Other, Mode mode = Mode.Alphabet) { double difference = 0; for (int i = (mode == Mode.Alphabet ? 65 : 0); i < (mode == Mode.Alphabet ? 256 : 91); i++) { difference += Math.Abs((double)Other.Data[i] / Other.Total - (double)Data[i] / Total); } difference /= 2; return(1 - difference); }
public static Language LanguageDetection(this string Text) { var tempFrequnecy = LetterFrequency.GenerateFrequency(Text); double tempScore = -1; int tempID = -1; for (int ID = 0; ID < LetterFrequency.AllLanguages.Length; ID++) { double langScore = tempFrequnecy.Compare(LetterFrequency.AllLanguages[ID]); if (langScore > tempScore) { tempScore = langScore; tempID = ID; } } return((Language)tempID); }