/// <summary>
 /// Loads the dictionary in to the <see cref="Dictionary"/> property.
 /// </summary>
 /// <param name="dictionaryFile">The dictionary file (*.dic).</param>
 /// <param name="affixFile">The affix file (*.aff).</param>
 public static void LoadDictionary(string dictionaryFile, string affixFile)
 {
     // read the data from the streams and dispose of them..
     using (var dictionaryStream = File.OpenRead(dictionaryFile))
     {
         using (var affixStream = File.OpenRead(affixFile))
         {
             // create a new dictionary..
             Dictionary = WordList.CreateFromStreams(dictionaryStream, affixStream);
         }
     }
 }
        static WordList Load(string languageCode)
        {
            const string resourceNamespaceBase = "WeCantSpell.Roslyn.DefaultDictionaries.";
            var          languageResourceName  = resourceNamespaceBase + languageCode;
            var          affName = languageResourceName + ".aff.compressed";
            var          dicName = languageResourceName + ".dic.compressed";

            var assembly = typeof(EmbeddedSpellChecker).GetTypeInfo().Assembly;

            using (var affCompressedStream = assembly.GetManifestResourceStream(affName))
                using (var affStream = new DeflateStream(affCompressedStream, CompressionMode.Decompress))
                    using (var dicCompressedStream = assembly.GetManifestResourceStream(dicName))
                        using (var dicStream = new DeflateStream(dicCompressedStream, CompressionMode.Decompress))
                        {
                            return(WordList.CreateFromStreams(dicStream, affStream));
                        }
        }
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log(LoadResourceTextfile("en_GB"));

        dictionary = WordList.CreateFromStreams(LoadResourceTextfile("en_GB"), LoadResourceTextfile("aff"));
    }
示例#4
0
        public void SpellCheckTest()
        {
            const string dictionariesPath = @"..\..\..\dictionaries";
            var          i           = 0;
            var          errorsCount = 0;
            var          message     = $"Next keys have spell check issues:\r\n\r\n";

            //var list = new List<SpellCheckExclude>();

            var groupByLng = TranslationFiles
                             .GroupBy(t => t.Language)
                             .Select(g => new
            {
                Language = g.Key,
                Files    = g.ToList()
            })
                             .ToList();

            foreach (var group in groupByLng)
            {
                try
                {
                    var language = SpellCheck.GetDictionaryLanguage(group.Language);

                    //var spellCheckExclude = new SpellCheckExclude(group.Language);

                    using (var dictionaryStream = File.OpenRead(Path.Combine(dictionariesPath, language, $"{language}.dic")))
                        using (var affixStream = File.OpenRead(Path.Combine(dictionariesPath, language, $"{language}.aff")))
                        {
                            var dictionary = WordList.CreateFromStreams(dictionaryStream, affixStream);

                            foreach (var g in group.Files)
                            {
                                foreach (var item in g.Translations)
                                {
                                    var result = SpellCheck.HasSpellIssues(item.Value, group.Language, dictionary);

                                    if (result.HasProblems)
                                    {
                                        message += $"{++i}. lng='{group.Language}' file='{g.FilePath}'\r\nkey='{item.Key}' value='{item.Value}'\r\nIncorrect words:\r\n{string.Join("\r\n", result.SpellIssues.Select(issue => $"'{issue.Word}' Suggestion: '{issue.Suggestions.FirstOrDefault()}'"))}\r\n\r\n";
                                        errorsCount++;


                                        /*foreach (var word in result.SpellIssues
                                         *  .Where(issue => issue.Suggestions.Any())
                                         *  .Select(issue => issue.Word))
                                         * {
                                         *  if (!spellCheckExclude.Excludes.Contains(word))
                                         *  {
                                         *      spellCheckExclude.Excludes.Add(word);
                                         *  }
                                         * }*/
                                    }
                                }
                            }
                        }

                    //spellCheckExclude.Excludes.Sort();

                    //list.Add(spellCheckExclude);
                }
                catch (NotSupportedException)
                {
                    // Skip not supported
                    continue;
                }
            }

            //string json = JsonConvert.SerializeObject(list, Formatting.Indented);
            //File.WriteAllText("../../../spellcheck-excludes.json", json);

            Assert.AreEqual(0, errorsCount, message);
        }