Ejemplo n.º 1
0
        /// <summary>
        /// Crawls the directory containing Hunspell dictionary and affix files.
        /// </summary>
        /// <param name="path">The path to search the dictionaries from.</param>
        /// <returns>List&lt;HunspellData&gt;.</returns>
        public static List <HunspellData> CrawlDirectory(string path)
        {
            // create a new instance of the DirectoryCrawler class by user given "arguments"..
            DirectoryCrawler crawler = new DirectoryCrawler(path, DirectoryCrawler.SearchTypeMatch.Regex,
                                                            "*.dic", true);

            // search for the Hunspell dictionary files (*.dic)..
            var files = crawler.GetCrawlResult();

            // initialize a return value..
            List <HunspellData> result = new List <HunspellData>();

            // loop through the found dictionary files (*.dic)..
            foreach (var file in files)
            {
                try
                {
                    // create a new HunspellData class instance..
                    var data = HunspellData.FromDictionaryFile(file);

                    // validate that there is a affix (*.aff) pair for the found dictionary file (*.dic)..
                    if (!File.Exists(data.DictionaryFile) || !File.Exists(data.AffixFile))
                    {
                        // ..if not, do continue..
                        continue;
                    }

                    // the validation was successful, so add the data to the result..
                    result.Add(data);
                }
                catch (Exception ex)
                {
                    // log the exception..
                    ExceptionLogAction?.Invoke(ex);
                }
            }

            // return the result..
            return(result);
        }