/// <summary> /// The suggest. /// </summary> /// <param name="word"> /// The word. /// </param> /// <returns> /// </returns> /// <exception cref="ObjectDisposedException"> /// </exception> /// <exception cref="InvalidOperationException"> /// </exception> public List <string> Suggest(string word) { if (this.IsDisposed) { throw new ObjectDisposedException("SpellFactory"); } if (this.hunspells == null) { throw new InvalidOperationException("Hunspell Dictionary isn't loaded"); } this.hunspellSemaphore.WaitOne(); Hunspell current = null; try { current = this.hunspells.Pop(); return(current.Suggest(word)); } finally { if (current != null) { this.hunspells.Push(current); } this.hunspellSemaphore.Release(); } }
private void SetLanguage(string language) { try { ClearLanguage(); var speller = new Hunspell(); var path = SpellCheckFolder(); var aff = Path.Combine(path, language + ".aff"); var dic = Path.Combine(path, language + ".dic"); if (File.Exists(aff) && File.Exists(dic)) { speller.Load(aff, dic); LoadCustomDictonary(speller); _speller = speller; _language = language; } else { Notify.Alert(language + " dictionary not found"); } } catch (Exception ex) { Notify.Alert($"{ex.Message} in {language ?? "null"} file"); } }
static void Main(string[] args) { Hunspell hunspell = new Hunspell("en_us.aff", "en_us.dic"); //The folliwng is the trying of the spell checking Console.WriteLine("Trying Spell Checking for the word 'Recommendation'"); Console.WriteLine(hunspell.Spell("Recommendation")); //The following is the trying of the suggesstions Console.WriteLine("\n\n"); Console.WriteLine("Trying the suggesstions of the word 'Recommnedatio'"); List<string> suggesstions = new List<string>(); suggesstions = hunspell.Suggest("Recommnedatio"); foreach (string item in suggesstions) { Console.WriteLine(" --" + item); } //The following is the trying of analysis of word Console.WriteLine("\n\n"); Console.WriteLine("Analyze the word 'children'"); List<string> morphs = hunspell.Analyze("children"); foreach (string morph in morphs) { Console.WriteLine("Morph is: " + morph); } //The following is the trying of Stemming Console.WriteLine("\n\n"); Console.WriteLine("Find the word stem of the word 'children'"); List<string> stems = hunspell.Stem("children"); foreach (string stem in stems) { Console.WriteLine("Word Stem is: " + stem); } //Now for the synonym functions Console.WriteLine("\n\n\nThesaurus/Synonym Functions"); Console.WriteLine("¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯"); //Creating a new instance of the thesarus MyThes thes = new MyThes("th_en_us_v2.dat"); //Synonyms for words Console.WriteLine("Get the synonyms of the plural word 'children'"); ThesResult tr = thes.Lookup("how", hunspell); if (tr.IsGenerated) Console.WriteLine("Generated over stem (The original word form wasn't in the thesaurus)"); foreach (ThesMeaning meaning in tr.Meanings) { Console.WriteLine(); Console.WriteLine(" Meaning: " + meaning.Description); foreach (string synonym in meaning.Synonyms) { Console.WriteLine(" Synonym: " + synonym); } } }
/// <summary> /// Look up the synonyms for the word. /// </summary> /// <param name="word"> /// The word. /// </param> /// <param name="useGeneration"> /// if set to <c>true</c> use generation to get synonyms over the word stem. /// </param> /// <returns> /// The <see cref="ThesResult"/>. /// </returns> public ThesResult LookupSynonyms(string word, bool useGeneration) { MyThes currentThes = null; Hunspell currentHunspell = null; try { currentThes = this.MyThesPop(); if (useGeneration) { currentHunspell = this.HunspellsPop(); return(currentThes.Lookup(word, currentHunspell)); } return(currentThes.Lookup(word)); } finally { if (currentThes != null) { this.MyThesPush(currentThes); } if (currentHunspell != null) { this.HunspellsPush(currentHunspell); } } }
private static List<string> Normalize(List<string> words) { var newWords = new List<string>(); using (Hunspell hunspell = new Hunspell("en_us.aff", "en_us.dic")) foreach (var word in words) newWords.Add(hunspell.Stem(word).FirstOrDefault()); return newWords; }
void HunspellsPush(Hunspell hunspell) { lock (hunspellsLock) { this.hunspells.Push(hunspell); } hunspellSemaphore.Release(); }
/// <summary> /// Look up the synonyms for the word. /// </summary> /// <param name="word"> /// The word. /// </param> /// <param name="useGeneration"> /// if set to <c>true</c> use generation to get synonyms over the word stem. /// </param> /// <returns> /// </returns> public ThesResult LookupSynonyms(string word, bool useGeneration) { if (this.IsDisposed) { throw new ObjectDisposedException("SpellFactory"); } if (this.myTheses == null) { throw new InvalidOperationException("MyThes Dictionary isn't loaded"); } if (useGeneration && this.hunspells == null) { throw new InvalidOperationException("Hunspell Dictionary isn't loaded"); } MyThes currentThes = null; Hunspell currentHunspell = null; this.myThesSemaphore.WaitOne(); if (useGeneration) { this.hunspellSemaphore.WaitOne(); } try { currentThes = this.myTheses.Pop(); if (useGeneration) { currentHunspell = this.hunspells.Pop(); return(currentThes.Lookup(word, currentHunspell)); } return(currentThes.Lookup(word)); } finally { if (currentThes != null) { this.myTheses.Push(currentThes); } if (currentHunspell != null) { this.hunspells.Push(currentHunspell); } this.myThesSemaphore.Release(); if (useGeneration) { this.hunspellSemaphore.Release(); } } }
protected override void OnKeyDown(KeyEventArgs e) { DirectoryInfo d = new DirectoryInfo("."); string d2 = d.FullName; if (e.KeyCode == Keys.Up && e.Alt) { using (Hunspell hunspell = new Hunspell(DictLanguage + ".aff", DictLanguage + ".dic")) { Dictionary<string, string> Replacements = new Dictionary<string, string>(); // string[] split = Text.Split(new char[] { ' ', '!', '?', '.', ',', ':', ';', '\n', '\r', '(', ')', '-', '=' }, StringSplitOptions.RemoveEmptyEntries); // foreach (string word in split) var mts = Regex.Matches(Text, "\\b\\w*\\b"); for (int i = 0; i < mts.Count; i++) { string word = mts[i].Value; if (Replacements.ContainsKey(word) || ignoreText.Contains(word)) continue; bool correct = hunspell.Spell(word); if (!correct) { frmSpeller sp = new frmSpeller(word, hunspell); sp.ShowDialog(); if (sp.ResultAction == frmSpeller.Action.Stop) break; if (sp.ResultAction == frmSpeller.Action.keep) { if (!ignoreText.Contains(word)) ignoreText.Add(word); } else { Replacements.Add(word, sp.ResultString); } } } string outv = this.Text; foreach (var item in Replacements.Keys) { outv = Regex.Replace(outv, "\\b" + item + "\\b", Replacements[item]); } this.Text = outv; //Console.WriteLine("Make suggestions for the word 'Recommendatio'"); //List<string> suggestions = hunspell.Suggest("Recommendatio"); //Console.WriteLine("There are " + suggestions.Count.ToString() + " suggestions"); //foreach (string suggestion in suggestions) //{ // Console.WriteLine("Suggestion is: " + suggestion); //} } } base.OnKeyDown(e); }
/// <summary> /// Lookups the specified word with word stemming and generation /// </summary> /// <param name="word"> /// The word. /// </param> /// <param name="stemming"> /// The <see cref="Hunspell"/> object for stemming and generation. /// </param> /// <returns> /// The <see cref="ThesResult"/>. /// </returns> public ThesResult Lookup(string word, Hunspell stemming) { if (this.synonyms.Count == 0) { throw new InvalidOperationException("Thesaurus not loaded"); } ThesResult result = this.Lookup(word); if (result != null) { return(result); } List <string> stems = stemming.Stem(word); if (stems == null || stems.Count == 0) { return(null); } var meanings = new List <ThesMeaning>(); foreach (var stem in stems) { ThesResult stemSynonyms = this.Lookup(stem); if (stemSynonyms != null) { foreach (var meaning in stemSynonyms.Meanings) { var currentSynonyms = new List <string>(); foreach (var synonym in meaning.Synonyms) { List <string> generatedSynonyms = stemming.Generate(synonym, word); foreach (var generatedSynonym in generatedSynonyms) { currentSynonyms.Add(generatedSynonym); } } if (currentSynonyms.Count > 0) { meanings.Add(new ThesMeaning(meaning.Description, currentSynonyms)); } } } } if (meanings.Count > 0) { return(new ThesResult(meanings, true)); } return(null); }
public SimpleWordParser() { try { hunspell = new Hunspell("en_US.aff", "en_US.dic"); } catch (FileNotFoundException) { Console.WriteLine("Dictionary not find."); } }
public SpellChecker(IKnownPatterns knownPatterns) { _knownPatterns = knownPatterns; using (var dictFile = ZipFile.Read(@"Dictionaries\dict-en.oxt")) { var affStream = new MemoryStream(); var dicStream = new MemoryStream(); dictFile.FirstOrDefault(z => z.FileName == "en_US.aff").Extract(affStream); dictFile.FirstOrDefault(z => z.FileName == "en_US.dic").Extract(dicStream); _speller = new Hunspell(affStream.ToArray(), dicStream.ToArray()); } }
public SpellChecker(string customDictionaryPath) { prefixes = Resources.customPrefixes.SplitToLines(); hunspell = new Hunspell(Resources.ru_RU_aff, Resources.ru_RU_dic); InitializeInternalCustomDicionary(hunspell); if (!string.IsNullOrEmpty(customDictionaryPath)) { InitializeCustomDictionary(hunspell, customDictionaryPath); } }
private void LoadCustomDictonary(Hunspell speller) { try { var file = CustomDictionaryFile(); foreach (var word in File.ReadAllLines(file)) speller.Add(word); } catch (Exception ex) { Notify.Alert($"{ex.Message} while loading custom dictionary"); } }
/// <summary> /// Generates the specified word by example. /// </summary> /// <param name="word"> /// The word. /// </param> /// <param name="sample"> /// The sample. /// </param> /// <returns> /// List of generated words, one per word stem /// </returns> public List <string> Generate(string word, string sample) { Hunspell hunspell = this.HunspellsPop(); try { return(hunspell.Generate(word, sample)); } finally { this.HunspellsPush(hunspell); } }
/// <summary> /// The suggest. /// </summary> /// <param name="word"> /// The word. /// </param> /// <returns> /// The <see cref="List{T}"/>. /// </returns> /// <exception cref="ObjectDisposedException"> /// </exception> /// <exception cref="InvalidOperationException"> /// </exception> public List <string> Suggest(string word) { Hunspell hunspell = this.HunspellsPop(); try { return(hunspell.Suggest(word)); } finally { this.HunspellsPush(hunspell); } }
/// <summary> /// Analyzes the specified word. /// </summary> /// <param name="word"> /// The word. /// </param> /// <returns> /// List of strings with the morphology. One string per word stem /// </returns> public List <string> Analyze(string word) { Hunspell hunspell = this.HunspellsPop(); try { return(hunspell.Analyze(word)); } finally { this.HunspellsPush(hunspell); } }
public NHunspell(YellowstonePathology.Business.Test.AccessionOrder accessionOrder) { this.m_AccessionOrder = accessionOrder; this.m_SpellCheckAccessionOrder = new SpellCheckAccessionOrder(this.m_AccessionOrder); this.m_Hunspell = new Hunspell(); this.m_Hunspell.Load(YellowstonePathology.Properties.Settings.Default.LocalAFFFile, YellowstonePathology.Properties.Settings.Default.LocalDICFile); this.m_SpellCheckAccessionOrder.SetErrorCounts(this.m_Hunspell); InitializeComponent(); this.DataContext = this; this.Loaded += NHunspell_Loaded; }
/// <summary> /// Spell check the specified word. /// </summary> /// <param name="word"> /// The word. /// </param> /// <returns> /// true if word is correct, otherwise false. /// </returns> public bool Spell(string word) { Hunspell hunspell = this.HunspellsPop(); try { return(hunspell.Spell(word)); } finally { this.HunspellsPush(hunspell); } }
internal string CheckEnglishSpelling() { bool correct; List<string> suggestions = new List<string>(); //Generate XML for the AtD plugin to read. StringWriter stringwriter = new StringWriter(); XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; XmlWriter xmlWriter = XmlWriter.Create(stringwriter, settings); xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("results"); string lastWord = string.Empty; //We create hunspell object and pass the location of the english dictionary. using (Hunspell hunspell = new Hunspell(System.Web.HttpContext.Current.Server.MapPath("~/Content/Dictionaries/en_US.aff"), System.Web.HttpContext.Current.Server.MapPath("~/Content/Dictionaries/en_US.dic"))) { //Split the paragraph to words List<string> words = Regex.Split(EnglishSynopsis, @"\W+").ToList(); foreach (string word in words) { //Check the spelling and returns true or false correct = hunspell.Spell(word); if (!correct) { xmlWriter.WriteStartElement("error"); xmlWriter.WriteElementString("string", word); xmlWriter.WriteElementString("description", "Spelling"); xmlWriter.WriteElementString("precontext", lastWord); xmlWriter.WriteStartElement("suggestions"); //Returns list of suggestion for the incorrect word suggestions = hunspell.Suggest(word); foreach (string suggestion in suggestions) { xmlWriter.WriteElementString("option", suggestion); } xmlWriter.WriteEndElement(); xmlWriter.WriteElementString("type", "spelling"); xmlWriter.WriteEndElement(); } lastWord = word; } } xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Close(); return stringwriter.ToString(); }
public static int CheckSpelling(string body) { int errors = 0; string[] contents = body.Split(' '); using (Hunspell spell = new Hunspell()) { foreach (var item in contents) { if (!(spell.Spell(item))) { errors++; } } } return errors; }
static void Main(string[] args) { MyThes thes = new MyThes(/*"th_en_us_new.idx", */ "th_en_us_new.dat"); hunspl = new NHunspell.Hunspell("en_US.aff", "en_US.dic"); A18 = new Hashtable(); A25 = new Hashtable(); A35 = new Hashtable(); A50 = new Hashtable(); A65 = new Hashtable(); Male18 = new Hashtable(); Male25 = new Hashtable(); Male35 = new Hashtable(); Male50 = new Hashtable(); Male65 = new Hashtable(); fMale18 = new Hashtable(); fMale25 = new Hashtable(); fMale35 = new Hashtable(); fMale50 = new Hashtable(); fMale65 = new Hashtable(); int chc = GetChoice(); while (chc != 4) { switch (chc) { case 0: WriteToFiles(); break; case 1: LoadFiles(); break; case 2: Learn(); break; case 3: Evaluate(); break; case 4: Environment.Exit(0); break; default: chc = GetChoice(); break; } chc = GetChoice(); } }
private void InitializeCustomDictionary(Hunspell _hunspell, string[] dictionaryLines) { foreach (var dictionaryLine in dictionaryLines) { if (string.IsNullOrEmpty(dictionaryLine) || dictionaryLine.StartsWith("#")) continue; var tokens = dictionaryLine.Split(':'); if (tokens.Length == 1) { _hunspell.Add(tokens[0].Trim()); } else { _hunspell.AddWithAffix(tokens[0].Trim(), tokens[1].Trim()); } } }
/// <summary> /// Gets spelling suggestions for the specified word /// </summary> /// <param name="affFile">The affFile path</param> /// <param name="dicFile">The dictionary file path</param> /// <param name="word">The word to get suggestions</param> /// <returns>A json list of suggestions for the specified word.</returns> public static string GetWordSuggestions(string affFile, string dicFile, string word) { List<string> suggestions = new List<string>(); try { using (Hunspell hunspell = new Hunspell(affFile, dicFile)) { suggestions = hunspell.Suggest(word); } } catch (Exception exception) { //need to handle this better and/or add logging } return JsonConvert.SerializeObject(suggestions); }
public static IList<string> SplitToWords(string sentence, bool correct = false) { //if (lemmatize) //{ // return DoLemmatize(sentence); //} var words = SplitToWordsNoLemmatize(sentence); if (_spell == null) { _spell = new Hunspell("en_us.aff", "en_us.dic"); } var stems = new List<string>(); foreach (var word in words) { var tmpWord = _multipleCharacterRegex.Replace(word, "$1$1"); if (correct) { var correctlySpelled = _spell.Spell(word); if (!correctlySpelled) { var tmp = _spell.Suggest(word); if (tmp != null && tmp.Count == 1) { tmpWord = tmp[0]; } } } var wordStems = _spell.Stem(tmpWord); if (wordStems.Count > 0) { stems.AddRange(wordStems); } else { stems.Add(word); } } return stems; }
public List<Word> Parse() { var words = new Dictionary<string, int>(); using (var hunspell = new Hunspell("ru_RU.aff", "ru_RU.dic")) { foreach (var e in text.ToLower().Split().Select(e => e.CleanTrim()).Where(e => !isDullWord(e))) { var beginWord = hunspell.Stem(e); var word = e; if (beginWord.Count == 1) word = beginWord[0]; if (!words.ContainsKey(word)) words.Add(word, 1); else words[word]++; } } return words.Select(e => new Word(e.Key, e.Value)).ToList(); }
static void Main(string[] args) { Console.WriteLine("Initializing Bot..."); bot = new TelegramBot(File.ReadAllText("apikey.txt")); Console.WriteLine("Bot initialized."); Console.WriteLine("Initializing Hunspell..."); hunspell = new Hunspell("en_us.aff", "en_us.dic"); Console.WriteLine("Hunspell initialized. {0} words.", File.ReadAllLines("en_us.dic").Count()); Console.WriteLine("Connecting to SQLite Database..."); database = new DatabaseContext(); Console.WriteLine("Database connected. {0} words.", database.GetWordCount()); Console.WriteLine("Hi, i'm {0}! ID: {1}", bot.Me.FirstName, bot.Me.Id); new Task(PollMessages).Start(); Console.ReadLine(); }
/*public ODtextBox(System.ComponentModel.IContainer container) { /// /// Required for Windows.Forms Class Composition Designer support /// container.Add(this); InitializeComponent(); }*/ ///<summary></summary> public ODtextBox(){ InitializeComponent();// Required for Windows.Forms Class Composition Designer support spellCheckIsEnabled=true; this.AcceptsTab=true;//Causes CR to not also trigger OK button on a form when that button is set as AcceptButton on the form. this.DetectUrls=false; if(System.ComponentModel.LicenseManager.UsageMode!=System.ComponentModel.LicenseUsageMode.Designtime && HunspellGlobal==null) { HunspellGlobal=new Hunspell(Properties.Resources.en_US_aff,Properties.Resources.en_US_dic); } ListCorrect=new List<string>(); ListCorrect.Add("\n"); //ListCorrect.Add("\r\n"); ListCorrect.Add("\t"); ListIncorrect=new List<string>(); EventHandler onClick=new EventHandler(menuItem_Click); MenuItem menuItem; contextMenu.MenuItems.Add("",onClick);//These five menu items will hold the suggested spelling for misspelled words. If no misspelled words, they will not be visible. contextMenu.MenuItems.Add("",onClick); contextMenu.MenuItems.Add("",onClick); contextMenu.MenuItems.Add("",onClick); contextMenu.MenuItems.Add("",onClick); contextMenu.MenuItems.Add("-"); contextMenu.MenuItems.Add("Add to Dictionary",onClick); contextMenu.MenuItems.Add("Disable Spell Check",onClick); contextMenu.MenuItems.Add("-"); menuItem=new MenuItem(Lan.g(this,"Insert Date"),onClick,Shortcut.CtrlD); contextMenu.MenuItems.Add(menuItem); menuItem=new MenuItem(Lan.g(this,"Insert Quick Note"),onClick,Shortcut.CtrlQ); contextMenu.MenuItems.Add(menuItem); contextMenu.MenuItems.Add("-"); menuItem=new MenuItem(Lan.g(this,"Cut"),onClick,Shortcut.CtrlX); contextMenu.MenuItems.Add(menuItem); menuItem=new MenuItem(Lan.g(this,"Copy"),onClick,Shortcut.CtrlC); contextMenu.MenuItems.Add(menuItem); menuItem=new MenuItem(Lan.g(this,"Paste"),onClick,Shortcut.CtrlV); contextMenu.MenuItems.Add(menuItem); }
public SpellChecker() { myPluginPath = Path.GetDirectoryName(Assembly.GetAssembly(typeof (SpellChecker)).Location) + Path.DirectorySeparatorChar; Hunspell.NativeDllPath = myPluginPath; myHunspell = new Hunspell(myPluginPath + "dic/en_us.aff", myPluginPath + "dic/en_us.dic"); try { myCustomDictionary.AddRange(File.ReadAllLines(myPluginPath + CustomDictionaryPath)); myCustomDictionary.ForEach(s => myHunspell.Add(s)); } catch { } string userDicDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ResharperSpellChecker"); if (!Directory.Exists(userDicDirectory)) { Directory.CreateDirectory(userDicDirectory); } myUserDicFilename = Path.Combine(userDicDirectory, "user.dic"); try { string[] readAllLines = File.ReadAllLines(myUserDicFilename); foreach (var line in readAllLines) { myUserDictionary.Add(line); myHunspell.Add(line); } } catch { } }
/// <summary> /// Checks the spelling of the specified text /// </summary> /// <param name="affFile">The affFile path</param> /// <param name="dicFile">The dictionary file path</param> /// <param name="text">The text to spell check</param> /// <returns></returns> public static string CheckSpelling(string affFile, string dicFile, string text) { bool success = true; List<string> misspelledWords = new List<string>(); List<List<string>> data = new List<List<string>>(); try { using (Hunspell hunspell = new Hunspell(affFile, dicFile)) { var words = text.Split((char[])null); //check the spelling of each word foreach (var word in words) { if (!hunspell.Spell(word)) misspelledWords.Add(word); } data.Add(misspelledWords); } } catch (Exception exception) { //need to add logging success = false; } var results = new SpellCheckResults { Outcome = success ? "success" : "error", Data = success ? data : null }; return JsonConvert.SerializeObject(results); }
/// <summary> /// Lookups the specified word with word stemming and generation /// </summary> /// <param name="word"> /// The word. /// </param> /// <param name="stemming"> /// The <see cref="Hunspell"/> object for stemming and generation. /// </param> /// <returns> /// The <see cref="ThesResult"/>. /// </returns> public ThesResult Lookup(string word, Hunspell stemming) { if (this.synonyms.Count == 0) { throw new InvalidOperationException("Thesaurus not loaded"); } ThesResult result = this.Lookup(word); if (result != null) { return result; } List<string> stems = stemming.Stem(word); if (stems == null || stems.Count == 0) { return null; } var meanings = new List<ThesMeaning>(); foreach (var stem in stems) { ThesResult stemSynonyms = this.Lookup(stem); if (stemSynonyms != null) { foreach (var meaning in stemSynonyms.Meanings) { var currentSynonyms = new List<string>(); foreach (var synonym in meaning.Synonyms) { List<string> generatedSynonyms = stemming.Generate(synonym, word); foreach (var generatedSynonym in generatedSynonyms) { currentSynonyms.Add(generatedSynonym); } } if (currentSynonyms.Count > 0) { meanings.Add(new ThesMeaning(meaning.Description, currentSynonyms)); } } } } if (meanings.Count > 0) { return new ThesResult(meanings, true); } return null; }
static void Main(string[] args) { string InPath = "./pan/"; string OutPath = "./Results/"; ReadConfig(); if (args.Count() == 0) { Console.WriteLine("NO PATH TO INPUT AND OUTPUT DIRECTORIES PROVIDED (e.g. c:/intrinsic/authpr -i c:/pan/intrinsic -o c:/output/) or (e.g. c:/intrinsic/authpr c:/pan/intrinsic c:/output/)"); //Environment.Exit(0); } else { //string[] ars = args.Split(' '); if (args[0] == "-i" && args[2] == "-o") { InPath = args[1]; OutPath = args[3]; } else { InPath = args[0]; OutPath = args[1]; } //Console.WriteLine(args[1] + "------------" + args[3]); } MyThes thes = new MyThes(/*"th_en_us_new.idx", */ AppDomain.CurrentDomain.BaseDirectory + "/th_en_us_new.dat"); hunspl = new NHunspell.Hunspell(AppDomain.CurrentDomain.BaseDirectory + "/en_US.aff", AppDomain.CurrentDomain.BaseDirectory + "/en_US.dic"); // ANALYSIS done on per three sentence basis with sliding window of one sentence, where ist sentence always belongs to author A // favourite single character // favourite pair of characters // start of each sentence with noun or noun following stop word, pronoun or verb // type of sentence // sentence ending on noun or verb // favourite word and word pair // use of punctuations // use of more longer complex words having length more than 5 words. // part of speech used after , // specific non alphanumeric charcter used in sentence other than , // form of sentence, present, past future //WinResult = new List<string>(); //ConnectingSen = new List<string>(); combinedindices = new List <string>(); SenLen = new List <int>(); ss1 = new List <string>(); FileStream fss = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "/txtDir/5000.dat", FileMode.Open); BinaryReader br = new BinaryReader(fss); int i = 0; while (i < 4350) { try { string[] a = br.ReadString().Split(' ');//WF.ReadLine().Split('\t'); if (a[0] != "") { ht.Add(a[0].Trim(), Int32.Parse(a[1].Trim())); //bw.Write(a[0].Trim('�') + " " + a[1].Trim()); } i++; } catch (EndOfStreamException ex) { br.Close(); } } fss.Close(); Listfiller(anger, "anger.dat"); Listfiller(confusion, "confusion.dat"); Listfiller(curiosity, "curiosity.dat"); Listfiller(happy, "happy.dat"); Listfiller(inspired, "inspired.dat"); Listfiller(negative, "negative.dat"); Listfiller(positive, "positive.dat"); Listfiller(relaxed, "relaxed.dat"); Listfiller(satisfied, "satisfied.dat"); Listfiller(urgency, "urgency.dat"); //string fo = OutPath; DirectoryInfo di = new DirectoryInfo(InPath); FileInfo[] fi = di.GetFiles("*.txt"); int nofiles = 0; foreach (var ff in fi) { int al = ff.Name.Length - 4; truthfile = OutPath + "/" + ff.Name.Remove(al).ToString() + ".truth"; StreamReader fs = new StreamReader(ff.FullName); string sd = fs.ReadToEnd(); fs.Close(); //ss1 = SplitSentences(fs.ReadToEnd()); int sindex = 0; int senindex = 0; for (i = 0; i < sd.Length; i++) { try { if ((sd[i] == '.' && (sd[i + 1] == ' ' || sd[i + 1] == '\n' || sd[i + 1] == '\r' || sd[i + 1] == '\t')) || (sd[i] == '?' && sd[i + 1] == ' ') || (sd[i] == '!' && sd[i + 1] == ' ')) // make sentence { senindex++; ss1.Add(sd.Substring(sindex, senindex)); SenLen.Add(senindex); sindex = i + 1; senindex = 0; } else { senindex++; } } catch (Exception ex) { if (sd[i] == '.' || sd[i] == '?' || sd[i] == '!') // make sentence { senindex++; ss1.Add(sd.Substring(sindex, senindex)); SenLen.Add(senindex); sindex = i + 1; senindex = 0; } } } int c1 = ss1.Count(); if (c1 < 6) { CreateOutput(); continue; } i = 0; int j = 4; int c = 2; int MWindex = 0; combinedindices.Add(i.ToString() + "-" + (i + 1).ToString() + "-" + (i + c).ToString()); combinedindices.Add((i + c).ToString() + "-" + (i + (j - 1)).ToString() + "-" + (i + j).ToString()); SentencWindow[0] = GetMergedSentences(MWindex); currentindex = 0; GetFavSingleChar(); SentencWindow[1] = GetMergedSentences(MWindex + 1); currentindex = 1; GetFavSingleChar(); SentencWindow[2] = ss1[c + i]; currentindex = 2; GetFavSingleChar(); MWindex += 1; while ((i + j) < (c1)) { double Similarity = FindSentenceDifference(0, 1, true); if (Similarity >= Diffr) // means ok to merge sentences through a combined index c and get next 3 sentences { i += 1; c += 1; j += 1; string swin = GetCombinedIndices((i + c), (i + (j - 1)), (i + j)); if (swin == null) { break; } combinedindices.Add(swin); } else // else get the distance of combined index c from both sharing sentences { double sim1 = FindSentenceDifference(0, 2, false); double sim2 = FindSentenceDifference(1, 2, false); if (sim1 > sim2 || sim1 == sim2) // in both cases combined index will stay with first window { combinedindices.RemoveAt(MWindex); // remove the next index and make new combined sentence windows i += 3; string swin = GetCombinedIndices((i + c) - 2, (i + c) - 1, (i + c)); if (swin == null) { break; } combinedindices.Add(swin); swin = GetCombinedIndices((i + c), i + (j - 1), (i + j)); if (swin == null) { break; } combinedindices.Add(swin); } else // combined index will stay with second window and we will update the first one { combinedindices.RemoveAt(MWindex - 1); combinedindices.Insert(MWindex - 1, ((c + i) - 2).ToString() + "-" + ((c + i) - 1).ToString()); // remove the next index and make new combined sentence windows i += 2; string swin = GetCombinedIndices((i + c), i + (j - 1), (i + j)); if (swin == null) { break; } combinedindices.Add(swin); } } SentencWindow[0] = GetMergedSentences(MWindex); currentindex = 0; GetFavSingleChar(); SentencWindow[1] = GetMergedSentences(MWindex + 1); currentindex = 1; GetFavSingleChar(); SentencWindow[2] = ss1[c + i]; currentindex = 2; GetFavSingleChar(); MWindex += 1; // increment the merged window to add next sentence window }// end while CreateOutput(); combinedindices.Clear(); Json.Clear(); MWindex = 0; ss1.Clear(); SenLen.Clear(); //nofiles++; //if (nofiles == 15) // break; } // end foreach() }
public void ClearLanguage() { _speller = null; }
public void EnableSpellCheck() { if (localeId == null) { return; } try { string dictPath = baseDir + "/dict/" + localeId; spellDict = new Hunspell(dictPath + ".aff", dictPath + ".dic"); LoadUserDictionary(); listeners.Add(new System.EventHandler(this.textbox_TextChanged)); this.textbox.TextChanged += (System.EventHandler)listeners[0]; cntl = new CustomPaintTextBox(this.textbox, this); SpellCheck(); } catch (Exception e) { MessageBox.Show(e.Message); } }
static void FillHash(Hashtable Age1, string name, int count) { int topics = 10; StreamWriter lda = new StreamWriter("train_LDA.bat"); if (count == 1) { lda.WriteLine("Gibbs_lda.exe -est -niters 500 -savestep 501 -ntopics 10 -twords 10 -dfile data.txt"); topics = 10; } else if (count < 5) { lda.WriteLine("Gibbs_lda.exe -est -niters 400 -savestep 401 -ntopics " + count.ToString() + " -twords 25 -dfile data.txt"); topics = 25; } else if (count >= 5 && count <= 10) { lda.WriteLine("Gibbs_lda.exe -est -niters 300 -savestep 301 -ntopics " + count.ToString() + " -twords 15 -dfile data.txt"); topics = 15; } else if (count > 10 && count < 20) { lda.WriteLine("Gibbs_lda.exe -est -niters 200 -savestep 201 -ntopics " + count.ToString() + " -twords 10 -dfile data.txt"); topics = 10; } else if (count >= 20) { lda.WriteLine("Gibbs_lda.exe -est -niters 100 -savestep 101 -ntopics " + count.ToString() + " -twords 5 -dfile data.txt"); topics = 5; } lda.Close(); lda.Dispose(); int[] arr = new int[Age1.Count]; Age1.Values.CopyTo(arr, 0); decimal AvgSenLen = (decimal)arr.Average(); decimal AvgSentencs = decimal.Divide(arr.Count(), count); Process p = new Process(); p.StartInfo.UseShellExecute = true; p.StartInfo.RedirectStandardOutput = false; p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; p.StartInfo.FileName = "train_LDA"; StreamWriter sw = new StreamWriter("Data.txt"); sw.WriteLine(Age1.Count.ToString()); foreach (DictionaryEntry str in Age1) { string g = str.Key.ToString().Trim('\n', ' ', '\t', '?', '@', '%', '.'); g = Regex.Replace(g, @"[^\u0000-\u007F]", string.Empty); if (g.Length > 3) { sw.WriteLine(g); } } sw.Close(); sw.Dispose(); //p.Refresh(); p.Start(); p.WaitForExit(); p.Close(); p.Dispose(); Age1.Clear(); StreamReader sr = new StreamReader("model-final.twords"); int ind = 0; while (!sr.EndOfStream) { if (ind == 0 || ind == topics) { string ae = sr.ReadLine(); ind = 0; } string[] ww = sr.ReadLine().Trim().Split(' '); try { List <string> ab = hunspl.Stem(ww[0].Trim('*', ':', ',', '.', '{', '}', '(', ')', ',', ';', '?', '!', ' ', '-', '[', ']', ' ', '\t', '\n', '\r').ToLower()); if (ab.Count > 1) { ww[0] = ab.ElementAt(1).ToString(); } else if (ab.Count == 1) { ww[0] = ab.ElementAt(0).ToString(); } } catch { hunspl = new NHunspell.Hunspell("en_US.aff", "en_US.dic"); } if (!Age1.ContainsKey(ww[0])) { Age1.Add(ww[0], ww[3]); } else { decimal w = decimal.Parse(Age1[ww[0]].ToString()); Age1[ww[0]] = w + decimal.Parse(ww[3]); } ind++; } sr.Close(); sr.Dispose(); if (name != null) { StreamWriter sw1 = new StreamWriter("xml_dic/" + name + ".txt"); sw1.WriteLine(AvgSenLen.ToString() + ":" + AvgSentencs.ToString()); //Age1.Add(AvgSenLen.ToString(), AvgSentencs); foreach (DictionaryEntry ent in Age1) { sw1.WriteLine(ent.Key.ToString() + ":" + ent.Value.ToString()); } sw1.Close(); sw1.Dispose(); } }
static void Main(string[] args) { #region OpenFiles // get the file reader StreamReader reader; try { reader = new StreamReader(args[0]); } catch(Exception e) { Console.WriteLine("an error occurred while opening the file: " + e.Message); return; } // get the file writer if (!File.Exists(RESULT_FILE)) File.Create(RESULT_FILE); StreamWriter writer = new StreamWriter(RESULT_FILE); writer.WriteLine(DataFileManager.minitabFileHeader); #endregion Word word; int numWords = 0; HashSet<string> okWords = new HashSet<string>(); HashSet<string> ignoreWords = new HashSet<string>(); Console.WriteLine("Going through file...\n"); using (Hunspell checker = new Hunspell("en_us.aff", "en_us.dic")) { reader.ReadLine(); while (!reader.EndOfStream) { word = DataFileManager.MinitabFileLine(reader.ReadLine()); if (checker.Spell(word.ToString()) || okWords.Contains(word.ToString())) { writer.WriteLine(DataFileManager.MinitabFileLine(word)); } else if(!ignoreWords.Contains(word.ToString())) { ColorWrite("Word #: " + numWords, ConsoleColor.Green); Console.Write(word.Source + ": '" + word.ToString() + "'" + " was not recognized as a word. Do you want to keep it? (y/n): "); if (Console.ReadKey().Key == ConsoleKey.Y) { writer.WriteLine(DataFileManager.MinitabFileLine(word)); okWords.Add(word.ToString()); } else { Console.Write("\nDo you want to offer an alternate spelling? (y/n): "); if (Console.ReadKey().Key == ConsoleKey.Y) { Console.Write("\nspelling: "); string input = Console.ReadLine(); foreach(string s in Sampler.Tokenize(input)) { Word newWord = new Word(s, word.Source, word.SourceDate, word.Topic); writer.WriteLine(DataFileManager.MinitabFileLine(newWord)); okWords.Add(newWord.ToString()); } } else { ColorWrite("\nThe word will be ignored.", ConsoleColor.Red); ignoreWords.Add(word.ToString()); } } Console.WriteLine("\n"); } numWords++; } } // End the program ColorWrite(numWords + " words processed.", ConsoleColor.Green); reader.Close(); writer.Close(); }
private void InitializeCustomDictionary(Hunspell _hunspell, string customDictionaryPath) { var dictionaryLines = File.ReadAllLines(customDictionaryPath); InitializeCustomDictionary(_hunspell, dictionaryLines); }
private void ApplyConfig(Config config) { if (config.InterfaceStyle == 0) //System toolStrip1.RenderMode = ToolStripRenderMode.System; else if (config.InterfaceStyle == 1) //Office 2003 toolStrip1.RenderMode = ToolStripRenderMode.ManagerRenderMode; //rtbIMText.BackColor = instance.Config.CurrentConfig.BgColour; if (instance.Config.CurrentConfig.EnableSpelling) { dicfile = instance.Config.CurrentConfig.SpellLanguage; // "en_GB.dic"; this.instance.AffFile = afffile = dicfile + ".aff"; this.instance.DictionaryFile = dicfile + ".dic"; dic = dir + dicfile; dicfile += ".dic"; if (!System.IO.File.Exists(dic + ".csv")) { //System.IO.File.Create(dic + ".csv"); using (StreamWriter sw = File.CreateText(dic + ".csv")) { sw.Dispose(); } } hunspell.Dispose(); hunspell = new Hunspell(); hunspell.Load(dir + afffile, dir + dicfile); ReadWords(); } else { hunspell.Dispose(); } }
private void InitializeInternalCustomDicionary(Hunspell _hunspell) { var dictionaryLines = Resources.customDictionary.SplitToLines(); InitializeCustomDictionary(_hunspell, dictionaryLines); }
public void SetErrorCount(Hunspell hunspell) { int errorCount = 0; foreach(Match match in this.Matches) { if(hunspell.Spell(match.Value) == false) { errorCount += 1; } } this.m_ErrorCount = errorCount; }
public Language() { hunspell = new Hunspell(@"Language\en_us.aff", @"Language\en_us.dic"); thes = new MyThes(@"Language\th_en_us_v2.dat"); }
/// <summary> /// It evaluates the responses provided by the student with the responses given by a instructor to grade a test using two separate XMLs. /// MCQs and Fill in the blanks type of questions are graded by comparing the responses, while Essay question is graded based on the /// number of keywords or their synonyms used, grammatical errors, spellcheck, word limit and paragraphs. /// </summary> private void CalculateMarks() { XmlSerializer ser = new XmlSerializer(typeof(Test)); finalTest = ser.Deserialize(new FileStream("D:\\test.xml", FileMode.Open)) as Test; totalQuestions = test.Question.Count(); ser = new XmlSerializer(typeof(TestAnswers)); finalTestAnswer = ser.Deserialize(new FileStream("D:\\StudentResponse.xml", FileMode.Open)) as TestAnswers; List<TestQuestion> quesList = new List<TestQuestion>(); for (int i = 0; i < totalQuestions; i++) { quesList.Add(finalTest.Question[i]); } int j = 0; double essayMarks = 100.0f; foreach (var question in quesList) { if (question.Type == QuesTypeVal.MCQ.ToString()) { if (question.Option1.Answer == "Yes" && question.Option1.Value == finalTestAnswer.Answer[j].Value) { marks += 5; } else if (question.Option2.Answer == "Yes" && question.Option2.Value == finalTestAnswer.Answer[j].Value) { marks += 5; } else if (question.Option3.Answer == "Yes" && question.Option3.Value == finalTestAnswer.Answer[j].Value) { marks += 5; } else if (question.Option4.Answer == "Yes" && question.Option4.Value == finalTestAnswer.Answer[j].Value) { marks += 5; } j++; } else if (question.Type == QuesTypeVal.Text.ToString()) { if (question.Answer.Text == finalTestAnswer.Answer[j].Value) { marks += 5; } j++; } else if (question.Type == QuesTypeVal.EssayText.ToString()) { string essayResponse = finalTestAnswer.Answer[j].Value; int nKeyword = question.Answer.Keyword.Count(); double keywordMark = 40.0 / (double)nKeyword; int checkSynonym = 0; double wordMarks = 0.0f; List<string> essayList = new List<string>(); var essayString = Regex.Split(essayResponse, @"[\n]+"); int noParagraphs = essayString.Count(); bool nParaCorrect = false; for (int i = 0; i < noParagraphs; i++) { if (essayString[i] != string.Empty) essayList.Add(essayString[i]); } if (essayList.Count() != question.NumberOfParagraphs) { essayMarks = 20; } else { List<string> wordList = new List<string>(); foreach (string essayPara in essayList) { var s = Regex.Split(essayPara, @"[,\s\n]+"); foreach (string k in s) { wordList.Add(k); } } if (wordList.Count >= question.TotalNumberOfWords) { essayMarks = 20; } else { bool grammarCheck = true; Microsoft.Office.Interop.Word.Application myWord = new Microsoft.Office.Interop.Word.Application(); foreach (string essay in essayList) { grammarCheck = myWord.CheckGrammar(essay); if (!grammarCheck) { essayMarks -= 5; } } wordMarks = 40.0 / (double)wordList.Count(); foreach (string word in wordList) { using (Hunspell hunspell = new Hunspell("en_us.aff", "en_us.dic")) { if (!hunspell.Spell(word)) { essayMarks -= wordMarks; } } } bool keyPresent = false; for (int i = 0; i < nKeyword; i++) { if (!essayResponse.Contains(question.Answer.Keyword[i])) { List<string> stringArr = new List<string>(); stringArr.Add(question.Answer.Keyword[i]); SynonymInfo theSynonyms = myWord.SynonymInfo[question.Answer.Keyword[i]]; foreach (var Meaning in theSynonyms.MeaningList as Array) { if (stringArr.Contains(Meaning) == false) stringArr.Add((string)Meaning); } for (int ii = 0; ii < stringArr.Count; ii++) { theSynonyms = myWord.SynonymInfo[stringArr[ii]]; foreach (string Meaning in theSynonyms.MeaningList as Array) { if (stringArr.Contains(Meaning)) continue; stringArr.Add(Meaning); } if (stringArr.Count >= 10) { stringArr.ToArray(); break; } } foreach (string key in stringArr) { if (essayResponse.Contains(key)) { keyPresent = true; } } if (!keyPresent) { essayMarks -= keywordMark; } } } } } } } marks += essayMarks; }
/// <summary> /// This method is used to register different events and initialize attributes /// </summary> private void registerEvents() { spellChecker = new Hunspell("dic/ur.aff", "dic/ur.dic"); //spellChecker.Load("dic/ur.aff", "dic/ur.dic"); keyboardLayout = "phonetic"; processKeyStrokes = new ProcessKeyStrokes(); urduSelected = true; changeUIText(); // if the default language has been changed Settings.Default.PropertyChanged += new PropertyChangedEventHandler(Default_PropertyChanged); // set zoom factor to 1 initially zoomFactor = 1.0f; // selection fon size selectionFontSize = 0; fontCollection = new PrivateFontCollection(); fontWatcher = new FileSystemWatcher(@"fonts"); // font size of the selected text should be shown in the font size combo box document.SelectionChanged += new EventHandler(document_SelectionChanged); // keep an eye on fonts fontWatcher.Filter = ".ttf"; fontWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; fontWatcher.IncludeSubdirectories = true; fontWatcher.Changed += new FileSystemEventHandler(fontWatcher_Changed); fontWatcher.Renamed += new RenamedEventHandler(fontWatcher_Renamed); fontWatcher.Deleted += new FileSystemEventHandler(fontWatcher_Deleted); fontWatcher.Created += new FileSystemEventHandler(fontWatcher_Created); // set fonts repositoryItemFontEdit.AutoComplete = true; FontEdit fontEdit = new FontEdit(); fontEdit.Properties.Items.AddRange(fontCollection.Families); }
public void SetLanguage(SpellingLanguages language) { speller = new Hunspell(); var languageKey = LangLookup[language]; var assembly = Assembly.GetExecutingAssembly(); var dictionaryFileStart = string.Format("{0}.Document.SpellCheck.Dictionaries.{1}", assembly.GetName().Name, languageKey); var dictionaryFiles = assembly .GetManifestResourceNames() .Where(name => name.StartsWith(dictionaryFileStart)) .ToArray(); var affixes = dictionaryFiles.Where(name => name.EndsWith(".aff")).OrderBy(s => s); var dictionaries = dictionaryFiles.Where(name => name.EndsWith(".dic")).OrderBy(s => s); var dictionaryPairs = affixes.Zip(dictionaries, (aff, dic) => new { aff, dic }); foreach (var pair in dictionaryPairs) { using (var affStream = assembly.GetManifestResourceStream(pair.aff)) using (var dicStream = assembly.GetManifestResourceStream(pair.dic)) { if (affStream != null && dicStream != null) { var affBytes = new BinaryReader(affStream).ReadBytes((int)affStream.Length); var dicBytes = new BinaryReader(dicStream).ReadBytes((int)dicStream.Length); speller.Load(affBytes, dicBytes); } } } }