//zwraca podobieństwo stringów wedle miary LV public float[] Laventshtein_On_User(string userinput) { float[] Point_Key_Simi = new float[3] { 0, 0, 0 }; int KEY = 0; float newval = 0; int counter = 0; StringSift2 SS2 = new StringSift2(); foreach (SynthPair sp in DataBase) { KEY = 0; foreach (string s in sp.In_Message) { newval = SS2.Similarity(userinput, s); /* Console.WriteLine("KEY: " + s + " USER: "******" SIMILARITY-> " + SS2.Similarity(s, userinput)); Console.ReadLine();*/ if (newval > Point_Key_Simi[2]) { Point_Key_Simi[0] = counter; Point_Key_Simi[1] = KEY; Point_Key_Simi[2] = newval; } ++KEY; } ++counter; } Console.WriteLine("Metoda pomiaru odl. Laventshteina osiagnela podobienstwo=" + Point_Key_Simi[2] + " wybrane zagadnienie-> " + DataBase[(int)Point_Key_Simi[0]].Key_Sentence + " Zgodność z-> " + DataBase[(int)Point_Key_Simi[0]].In_Message[(int)Point_Key_Simi[1]] + "\n"); return Point_Key_Simi; }
static void Main(string[] args) { Bot Bot = new Bot("Genowefa Grzebinoga"); StringSift2 SS2 = new StringSift2(); Console.WriteLine( SS2.Similarity("Zjem Cie Noobie","Zjem cie st")); Console.ReadLine(); }
static void Main(string[] args) { Bot Bot = new Bot("Genowefa Grzebinoga"); StringSift2 SS2 = new StringSift2(); Console.WriteLine(SS2.Similarity("Zjem Cie Noobie", "Zjem cie st")); Console.ReadLine(); }
public static float Distance(string s1, string s2) { StringSift2 aj = new StringSift2(); int maxOffset1 = aj.maxOffset; if (String.IsNullOrEmpty(s1)) { return (String.IsNullOrEmpty(s2) ? 0 : s2.Length); } if (String.IsNullOrEmpty(s2)) { return(s1.Length); } int c = 0; int offset1 = 0; int offset2 = 0; int dist = 0; while ((c + offset1 < s1.Length) && (c + offset2 < s2.Length)) { if (s1[c + offset1] != s2[c + offset2]) { offset1 = 0; offset2 = 0; for (int i = 0; i < maxOffset1; i++) { if ((c + i < s1.Length) && (s1[c + i] == s2[c])) { if (i > 0) { dist++; offset1 = i; } goto ender; } if ((c + i < s2.Length) && (s1[c] == s2[c + i])) { if (i > 0) { dist++; offset2 = i; } goto ender; } } dist++; } ender: c++; } return(dist + (s1.Length - offset1 + s2.Length - offset2) / 2 - c); }