private SpellCheckResultsJson GetSuggestionsResponse(SpellCheckSuggestionsJson sp) { List<string> suggestedWords = new List<string>(); ; SpellCheckResultsJson results = new SpellCheckResultsJson(); // Get a list of suggestions on a word results.result = HunspellInstance.Suggest(sp.word); return results; }
private SpellCheckResultsJson GetCheckWordsResponse(SpellCheckJson sp) { List<string> mispelledWords = new List<string>(); foreach (string word in sp.Words) { // Check to see if the word is in the dictionary // if it is not, it is mispelled if (!HunspellInstance.Spell(word)) { mispelledWords.Add(word); } } SpellCheckResultsJson results = new SpellCheckResultsJson(); results.result = mispelledWords; return results; }
public void ProcessRequest(HttpContext context) { string request; using (System.IO.StreamReader sr = new System.IO.StreamReader(context.Request.InputStream)) { // pull in the whole request that was sent to us request = sr.ReadToEnd(); } try { // I had to use the DeserializeObject method to pull back an object because the JSON object // has a property called params which is a reserved C# keyword object o = Newtonsoft.Json.JsonConvert.DeserializeObject(request); var sp = SpellCheckBaseClass.GetObjectFromDeserializedJson(o); HunspellInstance = new NHunspell.Hunspell( context.Server.MapPath("~/HunspellDictionaries/" + sp.Language + ".aff"), context.Server.MapPath("~/HunspellDictionaries/" + sp.Language + ".dic")); SpellCheckResultsJson results = this.GetResponse(sp); context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(results)); } catch (Exception ex) { // If there is an error spit back an error JSON object SpellCheckResultsJson errorResults = new SpellCheckResultsJson(); errorResults.error = ex.Message; context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(errorResults)); } }