Exemplo n.º 1
0
        private static async Task RunSpellingAsync(List <string> allText, ISpellChecker spellChecker, IReporter reporter)
        {
            int total       = allText.Count;
            int current     = 0;
            int lastPercent = 0;

            foreach (var message in allText)
            {
                SpellCheckResult spellCheckResult = null;
                try
                {
                    spellCheckResult = await spellChecker.CheckSpellingAsync(message);
                }
                catch (Exception e) { Console.WriteLine(e.Message); }

                if (spellCheckResult != null && spellCheckResult.suggestions != null && spellCheckResult.suggestions.Any())
                {
                    foreach (var spellSuggest in spellCheckResult.suggestions)
                    {
                        var reportText = ReportSpelling($"Word: '{spellSuggest.original}' - did you mean: '{spellSuggest.suggestion}'? Character number: {spellSuggest.wordLocation}", message);
                        reporter.ReportMessage(reportText);
                        Console.WriteLine(reportText);
                    }
                }
                current++;

                var percent = (int)((double)current / total * 100.0);
                if (percent > lastPercent)
                {
                    lastPercent = percent;
                    Console.WriteLine($"{percent}% Spell Checked");
                }
            }
        }
Exemplo n.º 2
0
        private void ResetIgnoreLists(IContextBoundSettingsStore boundSettings)
        {
            CachedSpellChecker oldIgnoreDictionaries;
            var           selectedIgnoreDictionaries = new HashSet <string>(boundSettings.EnumEntryIndices <SpellCheckSettings, string, byte>(x => x.IgnoreDictionaries));
            var           activeIgnoreDictionaries   = YouCantSpell.SpellChecker.GetAllAvailableDictionaryNames().Where(selectedIgnoreDictionaries.Contains).ToList();
            ISpellChecker newIgnoreDictionaries      = null;

            if (activeIgnoreDictionaries.Count > 0)
            {
                newIgnoreDictionaries = activeIgnoreDictionaries.Count == 1
                                        ? (ISpellChecker) new SpellChecker(activeIgnoreDictionaries[0])
                                        : new SpellCheckerCollection(activeIgnoreDictionaries.Select(x => new SpellChecker(x)).Cast <ISpellChecker>());
            }

            var ignoreWords            = new HashSet <string>(boundSettings.EnumEntryIndices <SpellCheckSettings, string, byte>(x => x.IgnoreEntries));
            var ignoreWordsInsensitive = new HashSet <string>(ignoreWords, StringComparer.CurrentCultureIgnoreCase);

            lock (_ignoredSync) {
                oldIgnoreDictionaries = _ignoreDictionaries;
                _ignored            = ignoreWords;
                _ignoredInsensitive = ignoreWordsInsensitive;
                _ignoreDictionaries = null == newIgnoreDictionaries ? null : new CachedSpellChecker(newIgnoreDictionaries, true);
            }

            if (null != oldIgnoreDictionaries)
            {
                oldIgnoreDictionaries.Dispose();
            }
        }
Exemplo n.º 3
0
        public void Check_That_FileAndServe_Is_Misspelled()
        {
            spellChecker = new DictionaryDotComSpellChecker();
            var asyncTask = spellChecker.CheckAsync("FileAndServe");

            Assert.IsFalse(asyncTask.Result);
        }
        public void CheckComment(
            ICSharpCommentNode commentNode,
            IHighlightingConsumer highlightingConsumer, CommentSettings settings)
        {
            // Ignore it unless it's something we're re-evalutating
            if (!_daemonProcess.IsRangeInvalidated(commentNode.GetDocumentRange()))
            {
                return;
            }

            // Only look for ones that are not doc comments
            if (commentNode.CommentType != CommentType.END_OF_LINE_COMMENT &&
                commentNode.CommentType != CommentType.MULTILINE_COMMENT)
            {
                return;
            }

            ISpellChecker spellChecker = SpellCheckManager.GetSpellChecker(_settingsStore, _solution, settings.DictionaryNames);

            SpellCheck(
                commentNode.GetDocumentRange().Document,
                commentNode,
                spellChecker,
                _solution, highlightingConsumer, _settingsStore, settings);
        }
Exemplo n.º 5
0
 public void TestFixtureSetUp()
 {
     //spellChecker = new MnemonicSpellCheckerIBeforeE();
     spellChecker = new ServiceCollection()
                    .AddScoped <ISpellChecker, MnemonicSpellCheckerIBeforeE>()
                    .BuildServiceProvider().GetService <ISpellChecker>();
 }
Exemplo n.º 6
0
 public IdentifierSpellCheckHighlighting(IDeclaration declaration, LexerToken token,
                                         ISolution solution, ISpellChecker spellChecker, IContextBoundSettingsStore settingsStore)
     : base(GetRange(declaration), token.Value, solution, spellChecker, settingsStore)
 {
     _lexerToken  = token;
     _declaration = declaration;
 }
Exemplo n.º 7
0
        public void Check_Word_That_Contains_I_Before_E_Is_Spelled_Incorrectly()
        {
            spellChecker = new MnemonicSpellCheckerIBeforeE();
            var asyncTask = spellChecker.CheckAsync("science");

            Assert.IsFalse(asyncTask.Result);
        }
        public void SetUp()
        {
            var provider = GetServiceProvider();

            _spellChecker = provider.GetService <ISpellChecker>();
            _testWriter   = (TestWriter)provider.GetService <IOutputWriter>();
        }
Exemplo n.º 9
0
 public void TestFixureSetUp()
 {
     //spellChecker = new DictionaryDotComSpellChecker();
     spellChecker = new ServiceCollection()
                    .AddScoped <ISpellChecker, DictionaryDotComSpellChecker>()
                    .BuildServiceProvider().GetService <ISpellChecker>();
 }
Exemplo n.º 10
0
        /// <summary>
        /// Sets the spell checker represented by id
        /// as a Guid or name.
        /// </summary>
        /// <param name="idOrName">GUID or name of the spell checker</param>
        /// <returns>true on success</returns>
        public bool SetActiveSpellChecker(String idOrName)
        {
            bool retVal;
            var  guid = Guid.Empty;

            if (!Guid.TryParse(idOrName, out guid))
            {
                guid = _spellCheckers.GetByName(idOrName);
            }

            var type = Guid.Equals(idOrName, Guid.Empty) ?
                       typeof(NullSpellChecker) :
                       _spellCheckers.Lookup(guid);

            if (type != null)
            {
                if (_activeSpellChecker != null)
                {
                    _activeSpellChecker.Dispose();
                    _activeSpellChecker = null;
                }

                retVal = createAndSetActiveSpellChecker(type);
            }
            else
            {
                createAndSetActiveSpellChecker(typeof(NullSpellChecker));
                retVal = false;
            }

            return(retVal);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Creates the spell checker using reflection on the
        /// specified type and makes it the active one.  If it fails,
        /// it set the null spell checker as the active one.
        /// </summary>
        /// <param name="type">.NET class type of the spell checker</param>
        /// <returns>true on success</returns>
        private bool createAndSetActiveSpellChecker(Type type)
        {
            bool retVal;

            try
            {
                var spellChecker = (ISpellChecker)Activator.CreateInstance(type);
                retVal = spellChecker.Init();
                if (retVal)
                {
                    saveSettings(spellChecker);
                    _activeSpellChecker = spellChecker;
                }
            }
            catch (Exception ex)
            {
                Log.Debug("Unable to load spellChecker " + type +
                          ", assembly: " + type.Assembly.FullName +
                          ". Exception: " + ex);
                retVal = false;
            }

            if (!retVal)
            {
                _activeSpellChecker = _nullSpellChecker;
            }

            return(retVal);
        }
        private IEnumerable <IBulbAction> CreateItems()
        {
            var items = new List <IBulbAction>();

            ISpellChecker spellChecker = this._highlighting.SpellChecker;

            if (spellChecker != null)
            {
                foreach (string newWord in spellChecker.Suggest(this._highlighting.MisspelledWord, MAX_SUGGESTION_COUNT))
                {
                    string wordWithMisspelledWordDeleted =
                        this._highlighting.Word.Remove(
                            this._highlighting.MisspelledRange.StartOffset, this._highlighting.MisspelledRange.Length);

                    string newString = wordWithMisspelledWordDeleted.Insert(this._highlighting.MisspelledRange.StartOffset, newWord);

                    items.Add(new ReplaceWordWithBulbItem(this._highlighting.DocumentRange, newString));
                }

                foreach (CustomDictionary dict in spellChecker.CustomDictionaries)
                {
                    items.Add(
                        new AddToDictionaryBulbItem(
                            this._highlighting.MisspelledWord, dict.Name, this._highlighting.DocumentRange, _highlighting.SettingsStore));
                }
            }
            return(items);
        }
Exemplo n.º 13
0
        private IEnumerable <IBulbAction> CreateItems()
        {
            var items = new List <IBulbAction>();

            ISpellChecker spellChecker = _highlighting.SpellChecker;

            if (spellChecker != null)
            {
                foreach (string newWord in spellChecker.Suggest(_highlighting.LexerToken.Value, MAX_SUGGESTION_COUNT))
                {
                    if (newWord.IndexOf(" ") > 0)
                    {
                        continue;
                    }
                    string declaredName = _highlighting.Declaration.DeclaredName;
                    string nameWithMisspelledWordDeleted = declaredName.Remove(
                        _highlighting.LexerToken.Start, _highlighting.LexerToken.Length);
                    string newName = nameWithMisspelledWordDeleted.Insert(_highlighting.LexerToken.Start, newWord);

                    items.Add(new RenameBulbItem(_highlighting.Declaration, newName));
                }
            }
            items.Add(new RenameBulbItem(_highlighting.Declaration));

            if (spellChecker != null)
            {
                foreach (CustomDictionary dict in spellChecker.CustomDictionaries)
                {
                    items.Add(
                        new AddToDictionaryBulbItem(
                            _highlighting.MisspelledWord, dict.Name, _highlighting.DocumentRange, _highlighting.SettingsStore));
                }
            }
            return(items);
        }
        private IEnumerable <IBulbAction> CreateItems()
        {
            var items = new List <IBulbAction>();

            ISpellChecker spellChecker = _highlight.SpellChecker;

            if (spellChecker != null)
            {
                foreach (string suggestText in spellChecker.Suggest(_highlight.MisspelledWord, MAX_SUGGESTION_COUNT))
                {
                    string wordWithMisspelledWordDeleted = _highlight.Word.Remove(_highlight.Token.Start, _highlight.Token.Length);
                    string newWord = wordWithMisspelledWordDeleted.Insert(_highlight.Token.Start, suggestText);
                    items.Add(new ReplaceWordWithBulbItem(_highlight.DocumentRange, newWord));
                }
            }

            items.Add(new ReplaceWordWithBulbItem(_highlight.DocumentRange, String.Format("<c>{0}</c>", _highlight.Word)));
            if (spellChecker != null)
            {
                foreach (CustomDictionary customDict in spellChecker.CustomDictionaries)
                {
                    items.Add(
                        new AddToDictionaryBulbItem(
                            _highlight.Token.Value, customDict.Name, _highlight.DocumentRange, _highlight.SettingsStore));
                }
            }
            return(items);
        }
Exemplo n.º 15
0
        public void Check_That_South_Is_Not_Misspelled()
        {
            spellChecker = new DictionaryDotComSpellChecker();
            var asyncTask = spellChecker.CheckAsync("South");

            Assert.IsTrue(asyncTask.Result);
        }
Exemplo n.º 16
0
 public StringSpellCheckHighlighting(string word, DocumentRange range, string misspelledWord,
                                     TextRange misspelledRange, ISolution solution,
                                     ISpellChecker spellChecker, IContextBoundSettingsStore settingsStore)
     : base(range, misspelledWord, solution, spellChecker, settingsStore)
 {
     _word            = word;
     _misspelledRange = misspelledRange;
 }
Exemplo n.º 17
0
 protected virtual void Dispose(bool includeManagedResources)
 {
     if (_ownsCore && _core is IDisposable)
     {
         (_core as IDisposable).Dispose();
         _core = null;
     }
 }
Exemplo n.º 18
0
 /// <summary>
 /// Clean the resources being currently in use.
 /// </summary>
 /// <param name="disposing">True if managed resources should be discarded; false otherwise.</param>
 private void Dispose(bool disposing)
 {
     if (spellChecker != null)
     {
         Marshal.ReleaseComObject(spellChecker);
         spellChecker = null;
     }
 }
Exemplo n.º 19
0
 /// <summary>
 /// Releases unmanaged and - optionally - managed resources.
 /// </summary>
 /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
 protected virtual void Dispose(bool disposing)
 {
     if (this.spellChecker != null)
     {
         Marshal.ReleaseComObject(this.spellChecker);
         this.spellChecker = null;
     }
 }
Exemplo n.º 20
0
            private ISpellChecker CreateSpellCheckerPrivate(string languageTag, bool suppressCOMExceptions = true)
            {
                ISpellChecker spellChecker             = null;
                bool          lockedExecutionSucceeded =
                    _factoryLock.WithWriteLock(CreateSpellCheckerImplWithRetries, languageTag, suppressCOMExceptions, out spellChecker);

                return(lockedExecutionSucceeded ? spellChecker : null);
            }
 protected SpellCheckHighlightBase(DocumentRange range, string misspelledWord,
                                   ISolution solution, ISpellChecker spellChecker, IContextBoundSettingsStore settingsStore)
 {
     _range         = range;
     _word          = misspelledWord;
     _solution      = solution;
     _spellChecker  = spellChecker;
     _settingsStore = settingsStore;
 }
Exemplo n.º 22
0
 public SpellCheckCSharpWalker(
     ISpellChecker spellChecker,
     Action <SpellingMistake> mistakeHandler)
     : base(SyntaxWalkerDepth.StructuredTrivia)
 {
     SpellChecker   = spellChecker ?? throw new ArgumentNullException(nameof(spellChecker));
     MistakeHandler = mistakeHandler ?? throw new ArgumentNullException(nameof(mistakeHandler));
     VisitedWords   = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
 }
Exemplo n.º 23
0
 public SpellCheckController(
     IWebAgent agent,
     IRuleRepository ruleRepository,
     ISpellChecker spellChecker)
 {
     _agent          = agent;
     _ruleRepository = ruleRepository;
     _spellChecker   = spellChecker;
 }
Exemplo n.º 24
0
        /// <summary>
        /// Adds a spellchecker to the factory.
        /// </summary>
        /// <param name="language"></param>
        /// <param name="spellchecker"></param>
        public void AddSpellChecker(string language, ISpellChecker spellchecker)
        {
            if (spellchecker is null)
            {
                throw new ArgumentNullException(nameof(spellchecker));
            }

            this.languageSpellCheckerMapping.Add(language.ToLowerInvariant(), spellchecker);
        }
Exemplo n.º 25
0
 public SpellCheckerPointer(ISpellChecker core, bool performDispose)
 {
     if (null == core)
     {
         throw new ArgumentNullException("core");
     }
     _core           = core;
     _performDispose = performDispose;
 }
Exemplo n.º 26
0
 /// <summary>
 /// Wraps another spell checker to provide caching and synchronization.
 /// </summary>
 /// <param name="core">The core spell checker to be wrapped.</param>
 /// <param name="ownsCore">If true this wrapper will be responsible for disposal of the core spell checker.</param>
 public CachedSpellChecker(ISpellChecker core, bool ownsCore)
 {
     if (null == core)
     {
         throw new ArgumentNullException("core");
     }
     _core     = core;
     _ownsCore = ownsCore;
     _cache    = new Dictionary <string, CachedSpellCheckData>();
 }
Exemplo n.º 27
0
        /// <summary>
        /// Switch language to the specified one.
        /// </summary>
        /// <param name="ci">culture to switch to</param>
        /// <returns>true on success</returns>
        public bool SwitchLanguage(CultureInfo ci)
        {
            if (_activeSpellChecker != null)
            {
                _activeSpellChecker.Dispose();
                _activeSpellChecker = null;
            }

            return(SetActiveSpellChecker(ci));
        }
Exemplo n.º 28
0
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        private SpellCheckManager()
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.AssemblyResolve += currentDomain_AssemblyResolve;

            _activeSpellChecker = SpellCheckers.NullSpellChecker;

            Context.EvtCultureChanged += Context_EvtCultureChanged;
        }
        public void TestFixureSetUp()
        {
            var serviceProvider = new ServiceCollection()
                                  .AddLogging((options) => {
                options.AddConsole();
            })
                                  .AddSingleton <DictionaryDotComSpellChecker>()
                                  .BuildServiceProvider();

            spellChecker = serviceProvider.GetService <DictionaryDotComSpellChecker>();
        }
Exemplo n.º 30
0
        public void TestFixtureSetUp()
        {
            var serviceProvider = new ServiceCollection()
                                  .AddLogging((options) => {
                options.AddConsole();
            })
                                  .AddSingleton <MnemonicSpellCheckerIBeforeE>()
                                  .BuildServiceProvider();

            spellChecker = serviceProvider.GetService <MnemonicSpellCheckerIBeforeE>();
        }
Exemplo n.º 31
0
		public static IEnumerable<ISyntaxEvaluation> GetSyntaxRules(ISpellChecker spellChecker)
		{
			var types = (from type in typeof(AllRules).Assembly.GetTypes()
						 where typeof(ISyntaxEvaluation).IsAssignableFrom(type)
						 where !type.IsInterface && !type.IsAbstract
						 select type).AsArray();
			var simple =
				types.Where(x => x.GetConstructors().Any(c => c.GetParameters().Length == 0))
					.Select(Activator.CreateInstance)
					.Cast<ISyntaxEvaluation>();
			var spelling =
				types.Where(
					x =>
					x.GetConstructors()
						.Any(
							c => c.GetParameters().Length == 1 && typeof(ISpellChecker).IsAssignableFrom(c.GetParameters()[0].ParameterType)))
					.Select(x => Activator.CreateInstance(x, spellChecker))
					.Cast<ISyntaxEvaluation>();

			return simple.Concat(spelling).OrderBy(x => x.ID).AsArray();
		}
Exemplo n.º 32
0
        /// <summary>
        /// Sets the spell checker represented by id
        /// as a Guid or name.
        /// </summary>
        /// <param name="idOrName">GUID or name of the spell checker</param>
        /// <returns>true on success</returns>
        public bool SetActiveSpellChecker(String idOrName)
        {
            bool retVal;
            var guid = Guid.Empty;

            if (!Guid.TryParse(idOrName, out guid))
            {
                guid = _spellCheckers.GetByName(idOrName);
            }

            var type = Guid.Equals(idOrName, Guid.Empty) ?
                            typeof(NullSpellChecker) :
                            _spellCheckers.Lookup(guid);

            if (type != null)
            {
                if (_activeSpellChecker != null)
                {
                    _activeSpellChecker.Dispose();
                    _activeSpellChecker = null;
                }

                retVal = createAndSetActiveSpellChecker(type);
            }
            else
            {
                createAndSetActiveSpellChecker(typeof(NullSpellChecker));
                retVal = false;
            }

            return retVal;
        }
Exemplo n.º 33
0
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        private SpellCheckManager()
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;
            currentDomain.AssemblyResolve += currentDomain_AssemblyResolve;

            _nullSpellChecker = new NullSpellChecker();
            _nullSpellChecker.Init();
            _activeSpellChecker = _nullSpellChecker;

            UserManagement.ProfileManager.GetFullPath(SpellCheckersRootName);
        }
 public void TestFixtureSetUp()
 {
     SpellChecker = new MnemonicSpellCheckerIBeforeE();
 }
		public MultiLineCommentLanguageRule(ISpellChecker spellChecker)
			: base(spellChecker)
		{
		}
Exemplo n.º 36
0
 public void Dispose()
 {
     if (m_impl != null)
         m_impl.Dispose();
     m_impl = null;
 }
Exemplo n.º 37
0
 /// <summary>
 /// Saves settings for the specified wordpredictor
 /// </summary>
 /// <param name="spellChecker">Spell checker object</param>
 private void saveSettings(ISpellChecker spellChecker)
 {
     spellChecker.SaveSettings("dummy");
 }
Exemplo n.º 38
0
		public PropertyNameSpellingRule(ISpellChecker speller)
			: base(speller)
		{
		}
Exemplo n.º 39
0
		protected CommentLanguageRuleBase(ISpellChecker spellChecker)
		{
			_spellChecker = spellChecker;
		}
Exemplo n.º 40
0
		public MethodNameSpellingRule(ISpellChecker speller)
			: base(speller)
		{
		}
Exemplo n.º 41
0
 public void SetComponent(ISpellChecker spellChecker )
 {
     _spellChecker = spellChecker;
 }
Exemplo n.º 42
0
        /// <summary>
        /// Creates the spell checker using reflection on the
        /// specified type and makes it the active one.  If it fails,
        /// it set the null spell checker as the active one.
        /// </summary>
        /// <param name="type">.NET class type of the spell checker</param>
        /// <returns>true on success</returns>
        private bool createAndSetActiveSpellChecker(Type type)
        {
            bool retVal;

            try
            {
                var spellChecker = (ISpellChecker)Activator.CreateInstance(type);
                retVal = spellChecker.Init();
                if (retVal)
                {
                    saveSettings(spellChecker);
                    _activeSpellChecker = spellChecker;
                }
            }
            catch (Exception ex)
            {
                Log.Debug("Unable to load spellChecker " + type +
                        ", assembly: " + type.Assembly.FullName +
                        ". Exception: " + ex);
                retVal = false;
            }

            if (!retVal)
            {
                _activeSpellChecker = _nullSpellChecker;
            }

            return retVal;
        }
Exemplo n.º 43
0
 /// <summary>
 /// Loads default settings for the specified word predictor
 /// </summary>
 /// <param name="spellChecker">spell checker object</param>
 private void loadDefaultSettings(ISpellChecker spellChecker)
 {
     spellChecker.LoadDefaultSettings();
 }
Exemplo n.º 44
0
 public CachingSpellChecker(ISpellChecker impl)
 {
     m_impl = impl;
 }
 public void TestFixureSetUp()
 {
     SpellChecker = new DictionaryDotComSpellChecker();
 }
Exemplo n.º 46
0
 public SpellChecker(ISpellChecker[] spellCheckers)
 {
     SpellCheckers = spellCheckers;
 }
		public SingleLineCommentLanguageRule(ISpellChecker spellChecker)
			: base(spellChecker)
		{
		}
Exemplo n.º 48
0
		protected NameSpellingRuleBase(ISpellChecker speller)
		{
			_speller = speller;
		}