示例#1
0
    public void MemoryLeakTest()
    {
        // Libraries etc should be loaded two times to init the static backbone of the classes (first and repeat code path)
        // On the third run all code paths are established and all allocated memory should free
        Hyphen hyphen = new Hyphen("hyph_en_us.dic");

        hyphen.Hyphenate("Recommendation");
        hyphen.Dispose();

        hyphen = new Hyphen("hyph_en_us.dic");
        hyphen.Hyphenate("Recommendation");
        hyphen.Dispose();


        GC.Collect();
        GC.WaitForPendingFinalizers();
        long memoryOnBegin = GC.GetTotalMemory(true);

        hyphen = new Hyphen("hyph_en_us.dic");
        hyphen.Hyphenate("Recommendation");
        hyphen.Dispose();

        GC.Collect();
        GC.WaitForPendingFinalizers();
        long memoryOnEnd = GC.GetTotalMemory(true);


        Assert.AreEqual(memoryOnBegin, memoryOnEnd);
    }
示例#2
0
 /// <summary>
 /// Portugal portuguese dictionary.
 /// </summary>
 public Portugal()
 {
     // Load the data.
     _hyphen    = new Hyphen(Nequeo.Spelling.Properties.Resources.hyph_pt_PT);
     _thesaurus = new MyThes(Nequeo.Spelling.Properties.Resources.th_pt_PT);
     _hunspell  = new Hunspell(Nequeo.Spelling.Properties.Resources.pt_PT, Nequeo.Spelling.Properties.Resources.pt_PT1);
 }
示例#3
0
 /// <summary>
 /// Australia english dictionary.
 /// </summary>
 public Australia()
 {
     // Load the data.
     _hyphen    = new Hyphen(Nequeo.Spelling.Properties.Resources.hyph_en_AU);
     _thesaurus = new MyThes(Nequeo.Spelling.Properties.Resources.th_en_AU_v2);
     _hunspell  = new Hunspell(Nequeo.Spelling.Properties.Resources.en_AU, Nequeo.Spelling.Properties.Resources.en_AU1);
 }
示例#4
0
        public NounRule(NounJson source)
        {
            this.ValidateSource(source);

            string noun = source.Name;

            string[]      parts = noun.Split(Hyphen.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            List <string> rules = new List <string>();

            string[] variants = new string[]
            {
                source.Singular[1],
                source.Singular[2],
                source.Singular[3],
                source.Singular[4],
                source.Singular[5],
                source.Plural[0],
                source.Plural[1],
                source.Plural[2],
                source.Plural[3],
                source.Plural[4],
                source.Plural[5]
            };
            string[][] variantParts = variants.Select(x => x.Split(Hyphen.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)).ToArray();

            for (int i = 0; i < parts.Length; i++)
            {
                string   part    = parts[i];
                string[] variant = variantParts.Select(x => x.Length > i ? x[i] : null).ToArray();

                rules.Add(this.GetRuleString(part, variant));
            }

            this.Value = string.Join(WordSeparator, rules.ToArray());
        }
示例#5
0
 /// <summary>
 /// Croatia croatian dictionary.
 /// </summary>
 public Croatia()
 {
     // Load the data.
     _hyphen    = new Hyphen(Nequeo.Spelling.Properties.Resources.hyph_hr_HR);
     _thesaurus = null;
     _hunspell  = new Hunspell(Nequeo.Spelling.Properties.Resources.hr_HR, Nequeo.Spelling.Properties.Resources.hr_HR1);
 }
示例#6
0
 /// <summary>
 /// France french dictionary.
 /// </summary>
 public France()
 {
     // Load the data.
     _hyphen    = new Hyphen(Nequeo.Spelling.Properties.Resources.hyph_fr);
     _thesaurus = new MyThes(Nequeo.Spelling.Properties.Resources.thes_fr);
     _hunspell  = new Hunspell(Nequeo.Spelling.Properties.Resources.fr_moderne, Nequeo.Spelling.Properties.Resources.fr_moderne1);
 }
示例#7
0
 /// <summary>
 /// Lataina latin dictionary.
 /// </summary>
 public Lataina()
 {
     // Load the data.
     _hyphen    = new Hyphen(Nequeo.Spelling.Properties.Resources.hyph_la);
     _thesaurus = null;
     _hunspell  = new Hunspell(Nequeo.Spelling.Properties.Resources.la, Nequeo.Spelling.Properties.Resources.la1);
 }
示例#8
0
 /// <summary>
 /// Germany german dictionary.
 /// </summary>
 public Germany()
 {
     // Load the data.
     _hyphen    = new Hyphen(Nequeo.Spelling.Properties.Resources.hyph_de_DE);
     _thesaurus = new MyThes(Nequeo.Spelling.Properties.Resources.th_de_DE_v2);
     _hunspell  = new Hunspell(Nequeo.Spelling.Properties.Resources.de_DE_frami, Nequeo.Spelling.Properties.Resources.de_DE_frami1);
 }
        /// <summary>
        /// Checks if hunspell files were found, and loads them
        /// </summary>
        internal bool checkHuspell()
        {
            bool output; // = new Boolean();

            bool change = false;

            try
            {
                if (hunspellEngine == null)
                {
                    hunspellEngine = new Hunspell(affixFilePath, dictFilePath);
                    hunspellHypen  = new Hyphen(affixFilePath); // NHunspell.Hyphen(hunspellDictStream);

                    change = true;
                }
            }
            catch (Exception ex)
            {
                throw new aceGeneralException("checkHuspellFailed", ex, this, "Huspell check failed");

                return(false);
            }

            return(hunspellEngine != null);
        }
示例#10
0
 /// <summary>
 /// United states english dictionary.
 /// </summary>
 public UnitedStates()
 {
     // Load the data.
     _hyphen    = new Hyphen(Nequeo.Spelling.Properties.Resources.hyph_en_US);
     _thesaurus = new MyThes(Nequeo.Spelling.Properties.Resources.th_en_US_v2);
     _hunspell  = new Hunspell(Nequeo.Spelling.Properties.Resources.en_US, Nequeo.Spelling.Properties.Resources.en_US1);
 }
示例#11
0
        /// <summary>
        /// Dispose(bool disposing) executes in two distinct scenarios.
        /// If disposing equals true, the method has been called directly
        /// or indirectly by a user's code. Managed and unmanaged resources
        /// can be disposed.
        /// If disposing equals false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference
        /// other objects. Only unmanaged resources can be disposed.
        /// </summary>
        private void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    // dispose managed state (managed objects).
                    if (_hyphen != null)
                    {
                        _hyphen.Dispose();
                    }

                    if (_hunspell != null)
                    {
                        _hunspell.Dispose();
                    }
                }

                // free unmanaged resources (unmanaged objects) and override a finalizer below.
                // set large fields to null.

                _hyphen    = null;
                _hunspell  = null;
                _thesaurus = null;
                _disposed  = true;
            }
        }
示例#12
0
 /// <summary>
 /// Italy italian dictionary.
 /// </summary>
 public Italy()
 {
     // Load the data.
     _hyphen    = new Hyphen(Nequeo.Spelling.Properties.Resources.hyph_it_IT);
     _thesaurus = new MyThes(Nequeo.Spelling.Properties.Resources.th_it_IT_v2);
     _hunspell  = new Hunspell(Nequeo.Spelling.Properties.Resources.it_IT, Nequeo.Spelling.Properties.Resources.it_IT1);
 }
示例#13
0
 public void NemethTests()
 {
     using (Hyphen hyphen = new Hyphen("HyphenTests\\alt.pat"))
     {
         HyphenResult result;
         result = hyphen.Hyphenate("schiffahrt");
         Assert.IsTrue(result.HyphenatedWord == "schiff=fahrt");
     }
 }
示例#14
0
 public void UnicodeFilenameTest()
 {
     using (Hyphen hyphen = new Hyphen("hyph_de_de_ö.dic"))
     {
         HyphenResult result;
         result = hyphen.Hyphenate("Änderung");
         Assert.IsTrue(result.HyphenatedWord == "Än=de=rung");
     }
 }
示例#15
0
 public void CyrillicLanguagesTest()
 {
     using (Hyphen hyphen = new Hyphen("hyph_ru.dic"))
     {
         HyphenResult result;
         result = hyphen.Hyphenate("Понедельник");
         Assert.IsTrue(result.HyphenatedWord == "По=не=дель=ник");
     }
 }
示例#16
0
    public void CreationAndDestructionTest()
    {
        Hyphen hyphen = new Hyphen("hyph_en_us.dic");

        Assert.IsFalse(hyphen.IsDisposed);

        // Multiple dispose must be allowed
        hyphen.Dispose();
        Assert.IsTrue(hyphen.IsDisposed);
        hyphen.Dispose();
        Assert.IsTrue(hyphen.IsDisposed);
    }
示例#17
0
    public void GermanUmlautTest()
    {
        using (Hyphen hyphen = new Hyphen("hyph_de_de.dic"))
        {
            HyphenResult result;
            result = hyphen.Hyphenate("Änderung");
            Assert.IsTrue(result.HyphenatedWord == "Än=de=rung");

            result = hyphen.Hyphenate("Störung");
            Assert.IsTrue(result.HyphenatedWord == "Stö=rung");

            result = hyphen.Hyphenate("Begründung");
            Assert.IsTrue(result.HyphenatedWord == "Be=grün=dung");
        }
    }
 public ThesaurusAdapter()
 {
     try
     {
         var resourceDirectory = VA.SettingsManager["VA"]["resources-directory"].Value;
         var spellDirectory    = Path.Combine(resourceDirectory, "Spell");
         _hunspell = new Hunspell(Path.Combine(spellDirectory, "en_us.aff"), Path.Combine(spellDirectory, "en_us.dic"));
         _thes     = new MyThes(Path.Combine(spellDirectory, "th_en_US_new.dat"));
         _hyphen   = new Hyphen(Path.Combine(spellDirectory, "hyph_en_US.dic"));
     }
     catch (Exception exception)
     {
         VA.Logger.Error(exception);
     }
 }
示例#19
0
 public WordNetPlugin(string wordNetDirectory)
 {
     try
     {
         string spellPath = wordNetDirectory + "\\spell";
         string dictPath  = wordNetDirectory + "\\dict\\";
         _wordNet  = new WN(dictPath);
         _hunspell = new Hunspell(Path.Combine(spellPath, "en_us.aff"), Path.Combine(spellPath, "en_us.dic"));
         _thes     = new MyThes(Path.Combine(spellPath, "th_en_US_new.dat"));
         _hyphen   = new Hyphen(Path.Combine(spellPath, "hyph_en_US.dic"));
     }
     catch (Exception ex)
     {
         VirtualAssistant.Instance.Logger.Error(ex);
     }
 }
示例#20
0
        private void HyphenPseudoSyllabe()
        {
            //Create list of compund syllabes
            for (int x = 0; x < i_maxletters; x++)
            {
                st_nonpseudosyllabes.Add(CreateNewPseudoSyllabe());
            }

            //Split them to syllabes
            foreach (string pseuodsyllabe in st_nonpseudosyllabes)
            {
                Hyphen       hyphen     = new Hyphen(Libs.Dictionary);
                HyphenResult hr         = hyphen.Hyphenate(pseuodsyllabe);
                string       presyllabe = hr.HyphenatedWord;

                List <string> syllabes = new List <string>();
                string        mem      = "";
                int           count    = 0;
                foreach (char ch in presyllabe)
                {
                    count++;
                    if (ch == '=')
                    {
                        syllabes.Add(mem);
                        mem = "";
                        continue;
                    }
                    else
                    {
                        mem += ch;
                    }

                    if (presyllabe.Count() == count)
                    {
                        syllabes.Add(mem);
                        mem = "";
                        continue;
                    }
                }

                foreach (string syllabe in syllabes)
                {
                    st_pseudosyllabes.Add(syllabe);
                }
            }
        }
示例#21
0
        static void Main(string[] args)
        {
            using (Hunspell hunspell = new Hunspell("en_us.aff", "en_us.dic"))
            {
                var correct = hunspell.Spell("houses");
                var suggest = hunspell.Suggest("haise");
                foreach (var x in suggest)
                {
                    Console.WriteLine(x);
                }
            }


            /*
             * var test = new SpellEngineTests();
             * test.CreationAndDestructionTest();
             * test.FunctionsTest();
             * return;
             */


            // var test = new HyphenTests();
            // test.CreationAndDestructionTest();
            // test.MemoryLeakTest();
            // test.UnicodeFilenameTest();
            // test.GermanUmlautTest();
            // test.CyrillicLanguagesTest();
            // test.NemethTests();

            var test = new HunspellTests();

            // test.AllDictionariesTest();
            test.SpellComplexWordsTest();
            test.AddWordTest();
            // test.GermanUmlautTest();
            // test.UnicodeFilenameTest();
            // test.MemoryLeakTest();

            /*
             * var test = new InteropTests();
             * test.Init();
             * test.ArrayInteropTests();
             * test.StringInteropTests();
             *
             *
             * Console.WriteLine("");
             * Console.WriteLine("Press any key to continue...");
             * Console.ReadKey();
             *
             * return;
             */
            Console.WriteLine("NHunspell functions and classes demo");

            /*
             * Console.WriteLine("Thesaurus with Thes");
             * Thes thes = new Thes();
             * thes.LoadOpenOffice("th_en_us_new.dat");
             */


            Console.WriteLine("");
            Console.WriteLine("Thesaurus with Thes");
            MyThes thes = new MyThes("th_en_us_new.dat");

            using (Hunspell hunspell = new Hunspell("en_us.aff", "en_us.dic"))
            {
                ThesResult result = thes.Lookup("cars", hunspell);
                foreach (ThesMeaning meaning in result.Meanings)
                {
                    Console.WriteLine("  Meaning:" + meaning.Description);
                    foreach (string synonym in meaning.Synonyms)
                    {
                        Console.WriteLine("    Synonym:" + synonym);
                    }
                }
            }

            Console.WriteLine("");
            Console.WriteLine("Spell Check with with Hunspell");

            // Important: Due to the fact Hunspell will use unmanaged memory you have to serve the IDisposable pattern
            // In this block of code this is be done by a using block. But you can also call hunspell.Dispose()
            using (Hunspell hunspell = new Hunspell("en_us.aff", "en_us.dic"))
            {
                Console.WriteLine("Check if the word 'Recommendation' is spelled correct");
                bool correct = hunspell.Spell("Recommendation");
                Console.WriteLine("Recommendation is spelled " + (correct ? "correct" : "not correct"));

                Console.WriteLine("");
                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);
                }

                Console.WriteLine("");
                Console.WriteLine("Analyze the word 'decompressed'");
                List <string> morphs = hunspell.Analyze("decompressed");
                foreach (string morph in morphs)
                {
                    Console.WriteLine("Morph is: " + morph);
                }

                Console.WriteLine("");
                Console.WriteLine("Stem the word 'decompressed'");
                List <string> stems = hunspell.Stem("decompressed");
                foreach (string stem in stems)
                {
                    Console.WriteLine("Stem is: " + stem);
                }

                /*
                 * for (; ; )
                 * {
                 *  Console.WriteLine("");
                 *  Console.WriteLine("Word1:");
                 *  string word = Console.ReadLine();
                 *  Console.WriteLine("Word2:");
                 *  string word2 = Console.ReadLine();
                 *
                 *  List<string> generated = hunspell.Generate(word, word2); // Generate("Girl","Boys");
                 *  foreach (string stem in generated)
                 *  {
                 *      Console.WriteLine("Generated is: " + stem);
                 *  }
                 * }
                 */
            }

            Console.WriteLine("");
            Console.WriteLine("Hyphenation with Hyph");

            // Important: Due to the fact Hyphen will use unmanaged memory you have to serve the IDisposable pattern
            // In this block of code this is be done by a using block. But you can also call hyphen.Dispose()
            using (Hyphen hyphen = new Hyphen("hyph_en_us.dic"))
            {
                Console.WriteLine("Get the hyphenation of the word 'Recommendation'");
                HyphenResult hyphenated = hyphen.Hyphenate("Recommendation");
                Console.WriteLine("'Recommendation' is hyphenated as: " + hyphenated.HyphenatedWord);

                hyphenated = hyphen.Hyphenate("eighteen");
                hyphenated = hyphen.Hyphenate("eighteen");
            }

            Console.WriteLine("");
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
示例#22
0
        /*
         * /// <summary>
         * /// Priprema Hunspell engine i ostale privremene podatke
         * /// </summary>
         * public void prepareHunspellEngine()
         * {
         *  diagnosticReport = "";
         *
         *  if (_hunspellEngine == null)
         *  {
         *
         *      if ((hunspellAffixStream != null) && (hunspellDictStream != null))
         *      {
         *          try
         *          {
         *              _hunspellEngine = new Hunspell(hunspellAffixStream, hunspellDictStream);
         *          }
         *          catch (Exception ex)
         *          {
         *              diagnosticReport += "Hunspell error: " + ex.Message + Environment.NewLine;
         *              logSystem.log("Hunspell error: " + ex.Message, logType.Warning);
         *          }
         *      }
         *      else
         *      {
         *          diagnosticReport += "Affix / Dict streams not ready" + Environment.NewLine;
         *      }
         *  }
         * }
         */

        //public bool checkDictFile(bool allowSetup = true, bool forceSelect = false)
        //{
        //    bool output = true;
        //    dialogPolicy dp = dialogPolicy.openIfNeeded;
        //    if (!allowSetup) dp = dialogPolicy.disableDialog;
        //    if (hunspellDictStream == null)
        //    {
        //        basicLanguageFileIO.loadFromFile(this, basicLanguageFileFormatType.huspellDict, dp, dictFilePath);
        //    }
        //    return output;
        //}


        ///// <summary>
        ///// Poziva na selektovanje potrebnog fajla
        ///// </summary>
        ///// <param name="fileFormat"></param>
        ///// <returns></returns>
        //public string selectFilePath(basicLanguageFileFormatType fileFormat)
        //{
        //    string pt = "";
        //    switch (fileFormat)
        //    {
        //        case basicLanguageFileFormatType.huspellAffix:
        //            pt = affixFilePath;
        //            break;
        //        case basicLanguageFileFormatType.huspellDict:
        //            pt = dictFilePath;
        //            break;
        //    }
        //    pt =
        //        @select.selectFile(fileFormat, pt, imbCore.environment.files.enums.dialogPolicy.forceDialog).relatedPath;

        //    if (!string.IsNullOrEmpty(pt))
        //    {
        //        switch (fileFormat)
        //        {
        //            case basicLanguageFileFormatType.huspellAffix:
        //                affixFilePath = pt;
        //                checkAiffFile(false);
        //                break;
        //            case basicLanguageFileFormatType.huspellDict:
        //                dictFilePath = pt;
        //                checkDictFile(false);
        //                break;
        //        }
        //    }
        //    return pt;
        //}

        //private bool checkAiffFile(bool allowSetup = true)
        //{
        //    bool output = true;
        //    dialogPolicy dp = dialogPolicy.openIfNeeded;
        //    if (!allowSetup) dp = dialogPolicy.disableDialog;

        //    if (hunspellAffixStream == null)
        //    {
        //        basicLanguageFileIO.loadFromFile(this, basicLanguageFileFormatType.huspellAffix, dp, affixFilePath);
        //    }
        //    return output;
        //}


        /// <summary>
        /// Static method extension
        /// </summary>
        public bool checkHuspell(bool allowSetup = true)
        {
            bool output; // = new Boolean();


            bool change = false;

            try
            {
                if (hunspellEngine == null)
                {
                    // hunspellEngine = new Hunspell(imbLanguageFrameworkManager.PATH_hunspell_aff, imbLanguageFrameworkManager.PATH_hunspell_dict);
                    // hunspellHypen = new Hyphen(imbLanguageFrameworkManager.PATH_hunspell_dict); // NHunspell.Hyphen(hunspellDictStream);

                    hunspellEngine = new Hunspell(affixFilePath, dictFilePath);
                    hunspellHypen  = new Hyphen(affixFilePath); // NHunspell.Hyphen(hunspellDictStream);

                    imbLanguageFrameworkManager.log.log("Affix file: " + affixFilePath);
                    imbLanguageFrameworkManager.log.log("Dict file: " + dictFilePath);

                    change = true;
                }
            }
            catch (Exception ex)
            {
                //logSystem.log("Engine init failed : " + ex.Message + " for model: " + iso2Code,
                //  logType.CriticalWarning, true);
                throw new aceGeneralException("checkHuspellFailed", ex, this, "Huspell check failed");

                return(false);
            }

            try
            {
                if (hunspellHypen == null)
                {
                    hunspellHypen = new Hyphen(imbLanguageFrameworkManager.PATH_hunspell_dict); // NHunspell.Hyphen(hunspellDictStream);
                    change        = true;
                }
            }
            catch (Exception ex)
            {
                //logSystem.log("Engine init failed : " + ex.Message + " for model: " + iso2Code,
                //  logType.CriticalWarning, true);
                throw new aceGeneralException("hunspellHypen", ex, this, "Huspell check failed");

                return(false);
            }

            //if (change)
            //{
            //    setModified();

            //    if (hunspellEngine != null)
            //    {
            //        if (parent != null)
            //        {
            //           // parent.execute(imbSqlEntityCollectionOperation.saveChanges);
            //        }
            //        else
            //        {
            //           // imbLanguageFrameworkManager.languages.execute(imbSqlEntityCollectionOperation.saveChanges);
            //        }
            //    }
            //}
            //saveItem(false);

            return(hunspellEngine != null);
        }
示例#23
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Hangman Game!");
            Console.WriteLine("Your mission is to find the secret word");
            Console.WriteLine("You can guess infinitely");

            string        pathToFileWord = args[0];
            string        secretWord;
            List <string> listWord = new List <string>();

            StreamReader sr = new StreamReader(pathToFileWord);

            secretWord = sr.ReadLine();
            while (secretWord != null)
            {
                listWord.Add(secretWord);
                secretWord = sr.ReadLine();
            }

            Random r = new Random();

            string result = listWord[r.Next(0, listWord.Count)];

            char[] guessArray = new char[result.Length];
            guessArray = Hyphen.hyphen(guessArray);

            Console.WriteLine("----------------------------------------");
            Console.WriteLine("Let the game begins!!!");
            Console.WriteLine("This word has " + result.Length + " characters");

            string guessString = String.Join("", guessArray);

            Console.WriteLine(guessString);

            Console.WriteLine("Please make your first guess");
            try
            {
                char guess = Convert.ToChar(Console.ReadLine());

                List <int> find;
                find = FindCharacter.findCharacter(result, guess);

                while (true)
                {
                    if (find.Count == 0)
                    {
                        Console.WriteLine("No character " + "'" + guess + "'" + " in the word. Please guess again");
                        Console.WriteLine(String.Join("", guessArray));
                        guess = Convert.ToChar(Console.ReadLine());
                        find  = FindCharacter.findCharacter(result, guess);
                    }
                    else
                    {
                        foreach (var item in find)
                        {
                            guessArray[item] = guess;
                        }

                        if (String.Join("", guessArray) == result)
                        {
                            Console.WriteLine("CONGRATULATIONS!!! YOU WIN THE GAME");
                            Console.WriteLine("The secret word is: " + result);
                            break;
                        }

                        Console.WriteLine("Oh yeah!!! One step closer to glory");
                        Console.WriteLine(String.Join("", guessArray));
                        guess = Convert.ToChar(Console.ReadLine());
                        find  = FindCharacter.findCharacter(result, guess);
                    }
                }
            }
            catch (FormatException f)
            {
                Console.WriteLine(f.Message);
            }
        }
示例#24
0
 public HyphenConverter(Hyphen hyphen)
 {
     _hyphen = hyphen;
 }