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"); } } }
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(); } }
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); }
public void TestFixtureSetUp() { //spellChecker = new MnemonicSpellCheckerIBeforeE(); spellChecker = new ServiceCollection() .AddScoped <ISpellChecker, MnemonicSpellCheckerIBeforeE>() .BuildServiceProvider().GetService <ISpellChecker>(); }
public IdentifierSpellCheckHighlighting(IDeclaration declaration, LexerToken token, ISolution solution, ISpellChecker spellChecker, IContextBoundSettingsStore settingsStore) : base(GetRange(declaration), token.Value, solution, spellChecker, settingsStore) { _lexerToken = token; _declaration = declaration; }
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>(); }
public void TestFixureSetUp() { //spellChecker = new DictionaryDotComSpellChecker(); spellChecker = new ServiceCollection() .AddScoped <ISpellChecker, DictionaryDotComSpellChecker>() .BuildServiceProvider().GetService <ISpellChecker>(); }
/// <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); }
/// <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); }
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); }
public void Check_That_South_Is_Not_Misspelled() { spellChecker = new DictionaryDotComSpellChecker(); var asyncTask = spellChecker.CheckAsync("South"); Assert.IsTrue(asyncTask.Result); }
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; }
protected virtual void Dispose(bool includeManagedResources) { if (_ownsCore && _core is IDisposable) { (_core as IDisposable).Dispose(); _core = null; } }
/// <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; } }
/// <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; } }
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; }
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); }
public SpellCheckController( IWebAgent agent, IRuleRepository ruleRepository, ISpellChecker spellChecker) { _agent = agent; _ruleRepository = ruleRepository; _spellChecker = spellChecker; }
/// <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); }
public SpellCheckerPointer(ISpellChecker core, bool performDispose) { if (null == core) { throw new ArgumentNullException("core"); } _core = core; _performDispose = performDispose; }
/// <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>(); }
/// <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)); }
/// <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>(); }
public void TestFixtureSetUp() { var serviceProvider = new ServiceCollection() .AddLogging((options) => { options.AddConsole(); }) .AddSingleton <MnemonicSpellCheckerIBeforeE>() .BuildServiceProvider(); spellChecker = serviceProvider.GetService <MnemonicSpellCheckerIBeforeE>(); }
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(); }
/// <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; }
/// <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) { }
public void Dispose() { if (m_impl != null) m_impl.Dispose(); m_impl = null; }
/// <summary> /// Saves settings for the specified wordpredictor /// </summary> /// <param name="spellChecker">Spell checker object</param> private void saveSettings(ISpellChecker spellChecker) { spellChecker.SaveSettings("dummy"); }
public PropertyNameSpellingRule(ISpellChecker speller) : base(speller) { }
protected CommentLanguageRuleBase(ISpellChecker spellChecker) { _spellChecker = spellChecker; }
public MethodNameSpellingRule(ISpellChecker speller) : base(speller) { }
public void SetComponent(ISpellChecker spellChecker ) { _spellChecker = spellChecker; }
/// <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; }
/// <summary> /// Loads default settings for the specified word predictor /// </summary> /// <param name="spellChecker">spell checker object</param> private void loadDefaultSettings(ISpellChecker spellChecker) { spellChecker.LoadDefaultSettings(); }
public CachingSpellChecker(ISpellChecker impl) { m_impl = impl; }
public void TestFixureSetUp() { SpellChecker = new DictionaryDotComSpellChecker(); }
public SpellChecker(ISpellChecker[] spellCheckers) { SpellCheckers = spellCheckers; }
public SingleLineCommentLanguageRule(ISpellChecker spellChecker) : base(spellChecker) { }
protected NameSpellingRuleBase(ISpellChecker speller) { _speller = speller; }