locked
Adding a user dictionary to Hunspell RRS feed

  • Question

  • User-1705895729 posted

    I am using Hunspell in a C# MVC3 program to do Spell Checking. I would like to add a User Dictionary Feature where my routine would automaticly include the User saved words and allow the user to store words. Do I need to create an empty .aff and .dic files, if so how do I create, read and write to them?

    private const string AFF_FILE = "~/App_Data/en_us.aff";

    private const string DICT_FILE = "~/App_Data/en_us.dic";       

    //private const string USER_AFF_FILE = "user_us.aff";      

    //private const string USER_DIC_FILE = "user_us.dic";    

     public ActionResult Index(string text)      

    {             

    using(NHunspell.Hunspell hunspell = new NHunspell.Hunspell(Server.MapPath(AFF_FILE), Server.MapPath(DICT_FILE)))             

    {                    

    // Include User dictionary ???                   

    Dictionary<string, List<string>> incorrect = new Dictionary<string, List<string>>();                    

    text = HttpUtility.UrlDecode(text);                    

    string[] words = text.Split(new char[] { ' ' }, StringSplitOption.RemoveEmptyEntries);                    

    foreach ( string word in words)                    

    {                       

    if (!hunspell.Spell(word) && !incorrect.ContainsKey(word))                       

    {                            

    incorrect.Add(word, hunspell.Suggest(word));                       

    }                    

    }                    

    return Json(Incorrect);                 

    }               

    }               

    public ActionResult Suggest(string word)               

    {                    

    using(NHunspell.Hunspell hunspell = new NHunspell.Hunspell(Server.MapPath(AFF_FILE), Server.MapPath(DICT_FILE)))                    

    {                        

    word = HttpUtility.UrlDecode(word);                        

    return Json(hunspell.Suggest(word));                    

    }                

    }                

    public ActionResult Add(string word)                

    {                    

    using(NHunspell.Hunspell hunspell = new NHunspell.Hunspell(Server.MapPath(AFF_FILE), Server.MapPath(DICT_FILE)))                    

    {                          

    word = HttpUtility.UrlDecode(word);                         

    //Store User word to user dictionary????                          

    return new EmptyResult();                    

    }                  

    }

    Tuesday, January 29, 2013 8:42 AM

Answers

  • User-1705895729 posted

    I decied the easist way was to create a table in the database and write/read the table via userID codes. That is set the new table to have two colunms. One equals UserID, second conatins word. If user decides to add a new word, it will open table, write userID and word. When spell check is called, open table read all words associated with userID and add to current dictionary.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 29, 2013 1:36 PM