public CustomPaintTextBox(TextBoxBase clientTextBox, SpellChecker checker) { //Set up the CustomPaintTextBox this.clientTextBox = clientTextBox; this.mySpellChecker = checker; //Create a bitmap with the same dimensions as the textbox myBitmap = new Bitmap(clientTextBox.Width, clientTextBox.Height); //Create the graphics object from this bitmpa...this is where we will draw the lines to start with bufferGraphics = Graphics.FromImage(this.myBitmap); bufferGraphics.Clip = new Region(clientTextBox.ClientRectangle); //Get the graphics object for the textbox. We use this to draw the bufferGraphics textBoxGraphics = Graphics.FromHwnd(clientTextBox.Handle); //Assign a handle for this class and set it to the handle for the textbox this.AssignHandle(clientTextBox.Handle); //We also need to make sure we update the handle if the handle for the textbox changes //This occurs if wordWrap is turned off for a RichTextBox clientTextBox.HandleCreated += TextBoxBase_HandleCreated; //We need to add a handler to change the clip rectangle if the textBox is resized clientTextBox.ClientSizeChanged += TextBoxBase_ClientSizeChanged; //this.disposedValue = false; }
public FileHeaderInspectionTests() { var exemptPatterns = new ExemptPatterns(); exemptPatterns.Add(@"^\d\.\d\.\d{1,5}\.\d$"); exemptPatterns.Add(@"Runtime"); var spellChecker = new SpellChecker(exemptPatterns); _inspector = new NodeReviewer(new[] { new SingleLineCommentLanguageRule(spellChecker) }, Enumerable.Empty<ISymbolEvaluation>()); }
public static void ApplySpellCheckerCulture( SpellChecker spellChecker ) { if ( spellChecker != null ) { spellChecker.Culture = CultureInfo.CurrentUICulture; } }
public void SuggestionsTest() { var spell = new SpellChecker(); var examples = spell.Suggestions("manle"); Assert.IsTrue(examples.Any()); }
public static void ApplySpellCheckerCulture( SpellChecker spellChecker, string languageCode ) { if ( spellChecker != null ) { spellChecker.Culture = LanguageCodeDetection.MakeValidCulture(languageCode); } }
public void TestSuggests() { var checker = new SpellChecker(); var word = "小不列颠"; var suggests = checker.Suggests(word); foreach (var suggest in suggests) { Console.WriteLine(suggest); } }
public void TestGetEdits1() { var s = "不列"; var checker = new SpellChecker(); var edits1 = checker.GetEdits1(s); foreach (var edit in edits1) { Console.WriteLine(edit); } }
private NamingService(CultureInfo culture) { this.culture = culture; if (StyleCopCore.PlatformID == PlatformID.Win32NT) { this.spellChecker = SpellChecker.FromCulture(culture); } this.InitCustomDictionaries(); }
public void ApplyTest() { SpellChecker sc = new SpellChecker (); ReplaceWrongChars sa = new ReplaceWrongChars (sc); Dictionary<string, SpellSuggestion> suggestedWords = new Dictionary<string, SpellSuggestion> (); sa.Apply ("applicotion", suggestedWords, dic); Assert.IsTrue (suggestedWords.Count == 1 && suggestedWords.ContainsKey ("application") && suggestedWords["application"].EditDistance == 1); }
public void MultiSessionTest() { var spell1 = new SpellChecker("en-us"); var spell2 = new SpellChecker("fr-fr"); var examples1 = spell1.Suggestions("doog").ToList(); spell1.Dispose(); var examples2 = spell2.Suggestions("doog").ToList(); Assert.AreEqual(examples1.Count(), 4); Assert.AreEqual(examples2.Count(), 2); }
static void Main(string[] args) { var spellChecker = new SpellChecker(new EnglishDictionary(), new BloomFilter(), new HashCollectionFactory(new HashFactoryCollection())); Console.WriteLine("Enter a sentence to be spell checked: "); var inputSentence = Console.ReadLine(); var words_not_in_dictionary = inputSentence.Split(' ').Where(word => !spellChecker.is_word_in_dictionary(word.ToLowerInvariant())); Console.WriteLine("Here are the words you may have misspelled: "); words_not_in_dictionary.each(Console.WriteLine); Console.ReadLine(); }
public void IgnoreTest() { var spell = new SpellChecker(); var examples = spell.Check("codez"); Assert.IsTrue(examples.Any()); spell.Ignore("codez"); examples = spell.Check("codez"); Assert.AreEqual(examples.Count(), 0); }
public void ApplyTest() { SpellChecker sc = new SpellChecker (); SwapChars sa = new SwapChars (sc); Dictionary<string, SpellSuggestion> suggestedWords = new Dictionary<string, SpellSuggestion> (); sa.Apply ("buildinsg", suggestedWords, dic); Assert.IsTrue (suggestedWords.Count == 1 && suggestedWords.ContainsKey ("buildings") && suggestedWords["buildings"].EditDistance == 1); suggestedWords.Clear (); sa.Apply ("zo", suggestedWords, dic); Assert.IsTrue (suggestedWords.Count == 1 && suggestedWords.ContainsKey ("oz") && suggestedWords["oz"].EditDistance == 1); }
public void ApplyTest() { SpellChecker sc = new SpellChecker (); SplitWords sa = new SplitWords (sc); Dictionary<string, SpellSuggestion> suggestedWords = new Dictionary<string, SpellSuggestion> (); sa.Apply ("gohome", suggestedWords, dic); Assert.IsTrue (suggestedWords.Count == 1 && suggestedWords.ContainsKey ("go home") && suggestedWords["go home"].EditDistance == 1); suggestedWords.Clear (); sa.Apply ("aq", suggestedWords, dic); Assert.IsTrue (suggestedWords.Count == 1 && suggestedWords.ContainsKey ("a q") && suggestedWords["a q"].EditDistance == 1); }
public void ApplyTest() { SpellChecker sc = new SpellChecker (); InsertForgottenChar sa = new InsertForgottenChar (sc); Dictionary<string, SpellSuggestion> suggestedWords = new Dictionary<string, SpellSuggestion> (); sa.Apply ("pplication", suggestedWords, dic); Assert.IsTrue (suggestedWords.Count >= 1 && suggestedWords.ContainsKey ("application") && suggestedWords["application"].EditDistance == 1); suggestedWords.Clear (); sa.Apply ("applicatio", suggestedWords, dic); Assert.IsTrue (suggestedWords.Count == 1 && suggestedWords.ContainsKey ("application") && suggestedWords["application"].EditDistance == 1); }
public void ApplyTest() { SpellChecker sc = new SpellChecker (); ReplacePatterns sa = new ReplacePatterns (sc); Dictionary<string, SpellSuggestion> suggestedWords = new Dictionary<string, SpellSuggestion> (); sa.Apply ("thare", suggestedWords, dic); Assert.IsTrue (suggestedWords.Count == 1 && suggestedWords.ContainsKey ("their") && suggestedWords["their"].EditDistance == 3); // check infinite cycles ("i" replaces to "igh") suggestedWords.Clear (); sa.Apply ("appliceition", suggestedWords, dic); Assert.IsTrue (suggestedWords.Count == 1 && suggestedWords.ContainsKey ("application") && suggestedWords["application"].EditDistance == 2); }
public void CheckTest() { var spell = new SpellChecker("en-us"); var examples = spell.Check("foxx or recieve").ToList(); Assert.AreEqual(examples.Count(), 2); var firstError = examples[0]; Assert.AreEqual(firstError.StartIndex, 0); Assert.AreEqual(firstError.Length, 4); Assert.AreEqual(firstError.RecommendedAction, RecommendedAction.GetSuggestions); Assert.AreEqual(firstError.RecommendedReplacement, string.Empty); var secondError = examples[1]; Assert.AreEqual(secondError.StartIndex, 8); Assert.AreEqual(secondError.Length, 7); Assert.AreEqual(secondError.RecommendedAction, RecommendedAction.Replace); Assert.AreEqual(secondError.RecommendedReplacement, "receive"); }
/* public static SpellCheckerOpenOfficeDictionary[] GetAllDictionaries() { var result = new List<SpellCheckerOpenOfficeDictionary>(); var fileNames = getAllCompleteCultureFileNames(); foreach ( var fileName in fileNames ) { var normalizedFileName = fileName.Replace( @"_", @"-" ); var dictionary = new SpellCheckerOpenOfficeDictionary { Culture = CultureInfo.GetCultureInfo( normalizedFileName ), DictionaryPath = ZlpPathHelper.Combine( dictionaryBaseFolderPath.FullName, fileName + @".dic" ), GrammarPath = ZlpPathHelper.Combine( dictionaryBaseFolderPath.FullName, fileName + @".aff" ) }; result.Add( dictionary ); } return result.ToArray(); } */ public static SpellChecker CreateSpellChecker( CultureInfo culture) { string dictionaryFilePath; string grammarFilePath; if (HasDictionariesForCulture( culture, out dictionaryFilePath, out grammarFilePath)) { Trace.WriteLine( string.Format( @"Using spell checker with culture '{0}'.", culture)); // http://www.devexpress.com/Help/?document=XtraSpellChecker/CustomDocument3158.htm&levelup=true. var spellChecker = new SpellChecker { Culture = culture, SpellCheckMode = SpellCheckMode.AsYouType, }; spellChecker.CheckAsYouTypeOptions.CheckControlsInParentContainer = true; var dictionary = new SpellCheckerOpenOfficeDictionary { Culture = culture, DictionaryPath = dictionaryFilePath, GrammarPath = grammarFilePath }; spellChecker.Dictionaries.Add(dictionary); return spellChecker; } else { Trace.WriteLine( string.Format( @"No spell checker with culture '{0}' because no dictionaries available.", culture)); return null; } }
public void MoreThanOneCorrectionWithEditDistTwoAndChangedOrderInDict() { Assert.That(SpellChecker.CheckWord("Two", new string[] { "tewot", "van", "too", "three" }), Is.EqualTo("{tewot too}")); }
public RibbonUI() { InitializeComponent(); this.spellChecker = SpellChecking.InitializeSpellChecker(); OpenXmlLoadHelper.Load("MovieRentals.docx", richEdit); }
public void NoWhiteSpacesAtTextEnds() { Assert.That(SpellChecker.CheckText("one!\n two-20\t'three apples , i yesh", new string[] { "apples", "too", "tree", "ys", "yeah", "y", "I" }), Is.EqualTo("{one?}!\n too-20\t'tree apples , I {ys yeah}")); }
// IDisposable protected virtual void Dispose(bool disposing) { if (!this.disposedValue & disposing) { if (disposing) { // TODO: dispose managed state (managed objects). if (clientTextBox != null) { this.ReleaseHandle(); clientTextBox.Invalidate(); clientTextBox.HandleCreated -= TextBoxBase_HandleCreated; clientTextBox.ClientSizeChanged -= TextBoxBase_ClientSizeChanged; clientTextBox.Dispose(); clientTextBox = null; } if (myBitmap != null) { myBitmap.Dispose(); myBitmap = null; } if (textBoxGraphics != null) { textBoxGraphics.Dispose(); textBoxGraphics = null; } if (bufferGraphics != null) { bufferGraphics.Dispose(); bufferGraphics = null; } if (mySpellChecker != null) { mySpellChecker = null; } } // TODO: free unmanaged resources (unmanaged objects) and override Finalize() below. // TODO: set large fields to null. } this.disposedValue = true; }
public void UnsupportedLangTest() { var spell = new SpellChecker("zz-zz"); }
public void WordIsCorrectIfInDictionaryIgnoreCase() { Assert.That(SpellChecker.CheckWord("абвгдеж", new string[] { "абвж", "АБВГдеж" }), Is.EqualTo("АБВГдеж")); }
bool ShouldWordBeMarkedAsMisspelled(ParsedTextSpan part) => part.IsWord && !SpellChecker.Check(part.Text);
private bool EnsureWordBreakerAndSpellCheckerForCulture(CultureInfo culture, bool throwOnError = false) { if (_isDisposed || (culture == null)) { return(false); } if (!_spellCheckers.ContainsKey(culture)) { WordsSegmenter wordBreaker = null; try { // Generally, we want to use the neutral language segmenter. This will ensure that the // WordsSegmenter instance will not inadvertently de-compound words into stems. For e.g., // the dedicated segmenter for German will break down words like Hausnummer into {Haus, nummer}, // whereas the nuetral segmenter will not do so. wordBreaker = WordsSegmenter.Create(culture.Name, shouldPreferNeutralSegmenter: true); } catch when(!throwOnError) { // ArgumentException: culture name is malformed - unlikely given we use culture.Name // PlatformNotSupportedException: OS is not supported // NotSupportedException: culture name is likely well-formed, but not available currently for wordbreaking wordBreaker = null; } // Even if wordBreaker.ResolvedLanguage == WordsSegmenter.Undetermined, we will use it // as an appropriate fallback wordbreaker as long as a corresponding ISpellChecker is found. if (wordBreaker == null) { _spellCheckers[culture] = null; return(false); } SpellChecker spellChecker = null; try { using (new SpellerCOMActionTraceLogger(this, SpellerCOMActionTraceLogger.Actions.SpellCheckerCreation)) { spellChecker = new SpellChecker(culture.Name); } } catch (Exception ex) { spellChecker = null; // ArgumentException: // Either the language name is malformed (unlikely given we use culture.Name) // or this language is not supported. It might be supported if the appropriate // input language is added by the user, but it is not available at this time. if (throwOnError && ex is ArgumentException) { throw new NotSupportedException(string.Empty, ex); } } if (spellChecker == null) { _spellCheckers[culture] = null; } else { _spellCheckers[culture] = new Tuple <WordsSegmenter, SpellChecker>(wordBreaker, spellChecker); } } return(_spellCheckers[culture] == null ? false : true); }
public AutoCorrect() { InitializeComponent(); this.spellChecker = SpellChecking.InitializeSpellChecker(); OpenXmlLoadHelper.Load("AutoCorrect.docx", richEdit); }
/// <summary> /// Initialize the SpellChecker for the current View Model /// </summary> private void InitializeSpellingChecker() { this.spellChecker = new SpellChecker(); this.spellChecker.SpellCheckMode = SpellCheckMode.AsYouType; }
public static void InitDictionary(SpellChecker spellChecker) { if(LocalizationHelper.IsJapanese) spellChecker.SpellCheckMode = SpellCheckMode.OnDemand; if(spellChecker.Dictionaries.Count > 0) return; spellChecker.Dictionaries.Add(GetDefaultDictionary()); }
// Token: 0x06008615 RID: 34325 RVA: 0x0024B9A6 File Offset: 0x00249BA6 public SpellerSegment(string sourceString, WordSegment segment, SpellChecker spellChecker, WinRTSpellerInterop owner) : this(sourceString, new WinRTSpellerInterop.TextRange(segment.SourceTextSegment), spellChecker, owner) { }
public void MoreThanOneEditCorrection() { Assert.That(SpellChecker.CheckWord("Three", new string[] { "van", "Tree", "Threek", "Threk", "sthree" }), Is.EqualTo("{Tree Threek sthree}")); }
// Token: 0x06008614 RID: 34324 RVA: 0x0024B97A File Offset: 0x00249B7A public SpellerSegment(string sourceString, SpellerInteropBase.ITextRange textRange, SpellChecker spellChecker, WinRTSpellerInterop owner) { this._spellChecker = spellChecker; this._suggestions = null; this.Owner = owner; this.SourceString = sourceString; this.TextRange = textRange; }
public void DoubleDisposeTest() { var spell = new SpellChecker("en-AU"); spell.Dispose(); spell.Dispose(); // No error }
public int DetectOneOrTwoExtraLetters(string checkword, string dictword) { return(SpellChecker.CanReplace(checkword, dictword)); }
public void TextbookExample() { Assert.That(SpellChecker.SpellCheck("rain spain plain plaint pain main mainly the in on fall falls his was ===\nhte rame in pain fells mainy oon teh lain was hints pliant ==="), Is.EqualTo("the {rame?} in pain falls {main mainly} on the plain was {hints?} plaint ")); }
public void OneCorrectWordString() { Assert.That(SpellChecker.CheckText("a", new string[] { "abs", "ads", "b", "c", "a" }), Is.EqualTo("a")); }
public void SimpleSpellCheckTest() { Assert.That(SpellChecker.SpellCheck("rain spain===rain spain==="), Is.EqualTo("rain spain")); }
/// <summary> /// 检查词语是否为在典词语(仅中文) /// </summary> /// <param name="str"></param> /// <returns></returns> public static bool CheckSpell(this string str) => ((_spellChecker ?? (_spellChecker = new SpellChecker())).Suggests(str) as string[]).Length > 0;
public int DetectOneIncorrectLetter(string checkword, string dictword) { return(SpellChecker.CanReplace(checkword, dictword)); }
public void WhiteSpaceAndOtherNonAlphabetMustBeIntact() { Assert.That(SpellChecker.CheckText(" one!\n two-20\t'three apples , yesh'! ", new string[] { "apples", "too", "tree", "ys", "yeah", "y" }), Is.EqualTo(" {one?}!\n too-20\t'tree apples , {ys yeah}'! ")); }
private Symbol LookupSymbolByName(string name, TextSpan span, NamespaceSymbol? @namespace) { NamespaceSymbol?FindNamespace(string name) { this.namespaces.TryGetValue(name, out NamespaceSymbol @namespace); return(@namespace); } Symbol?foundSymbol; if (@namespace == null) { // attempt to find name in the imported namespaces var namespaceSymbol = FindNamespace(name); if (namespaceSymbol != null) { // namespace symbol found return(ValidateFunctionFlags(namespaceSymbol, span)); } // declarations must not have a namespace value, namespaces are used to fully qualify a function access. // There might be instances where a variable declaration for example uses the same name as one of the imported // functions, in this case to differentiate a variable declaration vs a function access we check the namespace value, // the former case must have an empty namespace value whereas the latter will have a namespace value. if (this.declarations.TryGetValue(name, out var localSymbol)) { // we found the symbol in the local namespace return(ValidateFunctionFlags(localSymbol, span)); } // attempt to find function in all imported namespaces var foundSymbols = this.namespaces .Select(kvp => kvp.Value.TryGetFunctionSymbol(name)) .Where(symbol => symbol != null) .ToList(); if (foundSymbols.Count() > 1) { // ambiguous symbol return(new UnassignableSymbol(DiagnosticBuilder.ForPosition(span) .AmbiguousSymbolReference(name, this.namespaces.Keys))); } foundSymbol = foundSymbols.FirstOrDefault(); if (foundSymbol == null) { var nameCandidates = this.declarations.Values .Concat(this.namespaces.SelectMany(kvp => kvp.Value.Descendants)) .Select(symbol => symbol.Name) .ToImmutableSortedSet(); var suggestedName = SpellChecker.GetSpellingSuggestion(name, nameCandidates); return(suggestedName != null ? new UnassignableSymbol(DiagnosticBuilder.ForPosition(span).SymbolicNameDoesNotExistWithSuggestion(name, suggestedName)) : new UnassignableSymbol(DiagnosticBuilder.ForPosition(span).SymbolicNameDoesNotExist(name))); } } else { foundSymbol = @namespace.TryGetFunctionSymbol(name); if (foundSymbol == null) { return(new UnassignableSymbol(DiagnosticBuilder.ForPosition(span).FunctionNotFound(name, @namespace.Name))); } } return(ValidateFunctionFlags(foundSymbol, span)); }
void Button_Click(object sender, RoutedEventArgs e) { SpellChecker.Check(richEdit); }
public void Setup() { corrector = new SpellChecker (new string[] { "fuzzy", "fully", "funny", "fast" }); }
private void codebox_TextChangedDelayed(object sender, TextChangedEventArgs e) { SpellChecker SpellChecker = new SpellChecker(Main.ActiveEditor.codebox, @"Dictionary.dic"); SpellChecker.SpellCheck(sender); }
protected void PrepareAddToDictionaryButton() { btnAddToDictionary.Enabled = SpellChecker.GetCustomDictionary() != null; }
/// <summary> /// The dispose. /// </summary> /// <param name="disposing"> /// The disposing. /// </param> protected virtual void Dispose(bool disposing) { if (disposing) { try { if (this.spellChecker != null) { this.spellChecker.Dispose(); } } finally { this.spellChecker = null; } } }
public void OneEditCorrection() { Assert.That(SpellChecker.CheckWord("Abcde", new string[] { "van", "abcdef", "abcdf" }), Is.EqualTo("abcdef")); }
public void LanguageIdTest() { var spell = new SpellChecker("en-AU"); Assert.AreEqual(spell.LanguageTag, "en-AU"); }
private void Button_Click(object sender, RoutedEventArgs e) { SpellChecker.Check(textEdit); }
private SymbolTreeInfo(VersionStamp version, IReadOnlyList <Node> orderedNodes, SpellChecker spellChecker) { _version = version; _nodes = orderedNodes; _spellChecker = spellChecker; }
public void IsPlatformSupportedTest() { Assert.IsTrue(SpellChecker.IsPlatformSupported()); }
/// <summary> /// Evaluate spelling /// </summary> /// <returns> /// The result of the evaluation. /// </returns> protected override ValidatorResult Evaluate() { string controlValidationValue = this.ControlValidationValue; if (string.IsNullOrEmpty(controlValidationValue)) { return ValidatorResult.Valid; } ItemUri itemUri = this.ItemUri; if (itemUri == null) { return ValidatorResult.Valid; } CultureInfo cultureInfo = itemUri.Language.CultureInfo; if (cultureInfo.IsNeutralCulture) { cultureInfo = Language.CreateSpecificCulture(cultureInfo.Name); } var checker = new SpellChecker(FileUtil.MapPath(FileUtilMapPath)) { Text = controlValidationValue, DictionaryLanguage = cultureInfo.Name }; if (checker.CheckText().Count <= 2) { return ValidatorResult.Valid; } this.Text = string.Format("The field \"{0}\" contains more than two spelling errors.", this.GetFieldDisplayName()); return this.GetFailedResult(ValidatorResult.Error); }
public void NoCorrections() { Assert.That(SpellChecker.CheckWord("abcdefg", new string[] { "van", "abcdr" }), Is.EqualTo("{abcdefg?}")); }
public void IsLanguageSupportedTest() { Assert.IsTrue(SpellChecker.IsLanguageSupported("en-us")); Assert.IsFalse(SpellChecker.IsLanguageSupported("zz-zz")); }
public void WordIsCorrectIfInDictionary() { Assert.That(SpellChecker.CanReplace("абвгдеж", "абвгдеж"), Is.EqualTo(0)); }