Пример #1
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");
        }
    }
Пример #2
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);
    }
Пример #3
0
 public void NemethTests()
 {
     using (Hyphen hyphen = new Hyphen("HyphenTests\\alt.pat"))
     {
         HyphenResult result;
         result = hyphen.Hyphenate("schiffahrt");
         Assert.IsTrue(result.HyphenatedWord == "schiff=fahrt");
     }
 }
Пример #4
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");
     }
 }
Пример #5
0
 public void CyrillicLanguagesTest()
 {
     using (Hyphen hyphen = new Hyphen("hyph_ru.dic"))
     {
         HyphenResult result;
         result = hyphen.Hyphenate("Понедельник");
         Assert.IsTrue(result.HyphenatedWord == "По=не=дель=ник");
     }
 }
Пример #6
0
 public HyphenResult GenerateHyphenResult()
 {
     try
     {
         string word = FormatWord(QueryName);
         return(_hyphen.Hyphenate(word));
     }
     catch (Exception) { }
     return(null);
 }
Пример #7
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);
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Hyphenate the word.
        /// </summary>
        /// <param name="word">The word to hyphenate.</param>
        /// <returns>The hyphenated result.</returns>
        public HyphenatedResult Hyphenate(string word)
        {
            if (_hyphen != null)
            {
                // Get the hyphenation.
                HyphenResult result = _hyphen.Hyphenate(word);
                HyphenatedResult hyResult = new HyphenatedResult(
                    result.HyphenatedWord,
                    result.HyphenationPoints,
                    result.HyphenationReplacements,
                    result.HyphenationPositions,
                    result.HyphenationCuts);

                // Return the result.
                return hyResult;
            }
            else
                throw new NotImplementedException();
        }
        public string Evaluate(Context context)
        {
            try
            {
                //Elements has Get attribute
                var getAttribute = context.Element.Attribute("Get");
                var searchWord   = context.Element.Value;
                if (getAttribute != null)
                {
                    #region Synonym
                    if (getAttribute.Value.Equals("synonym", StringComparison.InvariantCultureIgnoreCase))
                    {
                        var thesResult = _thes.Lookup(searchWord);

                        var foundList = new List <string>();
                        foreach (var meaning in thesResult.Meanings)
                        {
                            foreach (var synonym in meaning.Synonyms)
                            {
                                if (foundList.Contains(synonym) == false)
                                {
                                    foundList.Add(synonym);
                                }
                            }
                        }

                        if (foundList.Any())
                        {
                            var speakList = ReducedList(foundList, 4);//Todo: implement a speaking interface
                            var toReturn  = SynUtility.Text.GetFormattedSentence(speakList);
                            context.User.Vars["synonym"].Value = toReturn;
                        }
                    }
                    #endregion
                    #region Spell
                    else if (getAttribute.Value.Equals("spell", StringComparison.InvariantCultureIgnoreCase))
                    {
                        var foundList = new List <string>();

                        foreach (var suggest in _hunspell.Suggest(searchWord))
                        {
                            if (foundList.Contains(suggest) == false)
                            {
                                foundList.Add(suggest);
                            }
                        }

                        if (foundList.Any())
                        {
                            var speakList = ReducedList(foundList, 4);//Todo: implement a speaking interface
                            var toReturn  = SynUtility.Text.GetFormattedSentence(speakList);
                            context.User.Vars["spell"].Value = toReturn;
                        }
                    }
                    #endregion
                    #region Hyphenate
                    if (getAttribute.Value.Equals("hyphenate", StringComparison.InvariantCultureIgnoreCase))
                    {
                        var hyphenated = _hyphen.Hyphenate(searchWord);
                        context.User.Vars["Hyphenate"].Value = hyphenated.HyphenatedWord;
                    }
                    #endregion
                }
            }
            catch (Exception exception)
            {
                VA.Logger.Error(exception);
            }

            return(string.Empty);
        }
Пример #10
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();
        }