async void Check() { var grammar = await grammarBot.CheckAsync("I loves music."); if (grammar.Success) { foreach (var item in grammar.CheckContent.Matches) { Debug.Log(item.offset); Debug.Log(item.Message); } } else { Debug.Log(grammar.Message); } }
// Call GrammarBot API to check grammar of user's input async void CheckGrammar(string content) { var grammar = await grammarBot.CheckAsync(content); double grammarScore = 5.0f; if (grammar.Success) // if there is grammar mistakes or not started with uppercase letter { int posOffset = 0; foreach (var item in grammar.CheckContent.Matches) { if (item.Message != "This sentence does not start with an uppercase letter") { int pos = (int)item.offset; int len = (int)item.Length; playerContent.text = playerContent.text.Substring(0, pos + posOffset) + "<color=red>" + playerContent.text.Substring(pos + posOffset, len) + "</color>" + playerContent.text.Substring(pos + len + posOffset); posOffset += 19; GrammarMessage.text = GrammarMessage.text + item.Message + "\n"; File.AppendAllText(userLogPath, GrammarMessage.text + "\n"); correctSent = false; grammarScore -= 1f; } else // if there is no grammar mistakes { //CrossOutWord(content); File.AppendAllText(userLogPath, "No grammar mistake\n"); correctSent = true; } } } else // if there is no grammar mistakes { File.AppendAllText(userLogPath, "No grammar mistake\n"); correctSent = true; } if (grammarScore < 0) { grammarScore = 0; } scoreRound += grammarScore; }
async void CheckGrammar(string content) //Call the grammarbot and display any errors { var grammar = await grammarBot.CheckAsync(content); if (grammar.Success) // if there is grammar mistakes or not started with uppercase letter { int posOffset = 0; foreach (var item in grammar.CheckContent.Matches) { if (item.Message != "This sentence does not start with an uppercase letter") { int pos = (int)item.offset; int len = (int)item.Length; playerContent.text = playerContent.text.Substring(0, pos + posOffset) + "<color=red>" + playerContent.text.Substring(pos + posOffset, len) + "</color>" + playerContent.text.Substring(pos + len + posOffset); posOffset += 19; GrammarMessage.text = GrammarMessage.text + item.Message + "\n"; Debug.Log(item.Message); correctSent = false; } else // if there is no grammar mistakes { correctSent = true; } } } else // if there is no grammar mistakes { Debug.Log(grammar.Message); correctSent = true; } }