public static void AnalizeReadyText(SingleInput input, string text) { if (input == null) { return; } var textLength = Convert.ToDouble(text.Length); if (textLength > 0) { input.newLinesPerText = Convert.ToDouble(text.Count(f => f == '\n')) / textLength; } else { input.newLinesPerText = 0; } input.polishChars = Convert.ToInt16(Regex.Match(text, "[ĄąĆ毿ŹźÓ󣳌ś]").Success); if (Regex.Matches(text, "[.,?!:;]").Count > 0) //there are any punctuations { input.spacesBeforePunctuation = Convert.ToDouble(Regex.Matches(text, " [.,?!:;]").Count) / Convert.ToDouble(Regex.Matches(text, "[.,?!:;]").Count); input.spacesAfterPunctuation = Convert.ToDouble(Regex.Matches(text, "[.,?!:;] ").Count) / Convert.ToDouble(Regex.Matches(text, "[.,?!:;]").Count); } }
private static double GetProbabilityAmong(SingleInput itemParams, SingleInput perfectParams) { double sum = 0; for (int i = 0; i < 6; i++) { //foreach param sum += Math.Abs(itemParams[i] - perfectParams[i]) * weights[i]; } return(1 - (sum / weights.Sum())); }
private static void NormalizeAmongAllUsers() { double[] max = new double[6]; double[] min = { 1, 1, 1, 1, 1, 1 }; foreach (UserData data in Config.allUsersData) { for (int i = 0; i < 6; i++) { //foreach param if (max[i] < data.inputs.Max(s => s[i])) { max[i] = data.inputs.Max(s => s[i]); } if (min[i] > data.inputs.Min(s => s[i])) { min[i] = data.inputs.Min(s => s[i]); } } } UserData tmp; SingleInput inp; foreach (UserData data in Config.allUsersData) { tmp = new UserData(); tmp.userName = data.userName; inp = new SingleInput(); for (int i = 0; i < 6; i++) { //foreach param if ((max[i] - min[i]) == 0) { inp[i] = data.GetAvgParam(i); continue; } inp[i] = (data.GetAvgParam(i) - min[i]) / (max[i] - min[i]); } tmp.inputs.Add(inp); Config.allUsersNormalized.Add(tmp); } }
private void NewSpeech() { currentInput = new SingleInput(); textBoxInput.Text = ""; textBoxInput.Focus(); }
public static void AnalizeFreshInput(SingleInput input, string text) { if (text.Length <= 2) { return; } char lastChar = text[text.Length - 1]; char secondLastChar = text[text.Length - 2]; char[] lastChars = { secondLastChar, lastChar }; string sLastChars = new string(lastChars); if (!isWordTypedNow && Regex.Matches(sLastChars, "[.,?!:;) ][A-z]").Count == 1) { //poczatek wyrazu isWordTypedNow = true; singleWordTime.Restart(); textLenAtWordStart = text.Length; } if (isWordTypedNow && Regex.Matches(sLastChars, "[A-z][\r.,?!:;( ]").Count == 1) { //koniec wyrazu double output; isWordTypedNow = false; singleWordTime.Stop(); if (text.Length - textLenAtWordStart <= 2) { return; //pomijamy 1 oraz 2 literowe slowa } if (input.avgLetterTime != 0) { output = ((singleWordTime.ElapsedMilliseconds / (text.Length - textLenAtWordStart)) + input.avgLetterTime * totalWordsCount) / (totalWordsCount + 2); } else { output = singleWordTime.ElapsedMilliseconds / (text.Length - textLenAtWordStart); } if (output > 0) //ujemna wartosc = BŁĄD (np. przez usuniecie wyrazu backspace) { input.avgLetterTime = output; totalWordsCount++; } } if (shiftDownTime.IsRunning && Regex.Matches(lastChar.ToString(), "[A-Z!@#$%^&*()]").Count == 1) { shiftDownTime.Stop(); double output; if (input.avgCapitalLetterTime != 0) { output = (shiftDownTime.ElapsedMilliseconds + input.avgCapitalLetterTime * totalShiftUsed) / (totalShiftUsed + 2); } else { output = shiftDownTime.ElapsedMilliseconds; } if (output > 0) //ujemna wartosc = BŁĄD (np. przez usuniecie wyrazu backspace) { input.avgCapitalLetterTime = output; totalShiftUsed++; } } }