public static bool VerificaPalavra(string palavra) { var dictionary = WordList.CreateFromFiles(@"Files\\pt_BR.dic"); //bool notOk = dictionary.Check("teh"); //var suggestions = dictionary.Suggest("teh"); bool ok = dictionary.Check(palavra); return(ok); //TXTextControl.Proofing.TXSpell spell = new TXTextControl.Proofing.TXSpell(); //using (Hunspell hunspell = new Hunspell("Files\\pt_br.aff", "Files\\pt_br.dic")) //{ // return hunspell.Spell(palavra); // Console.WriteLine("Hunspell - Spell Checking Functions"); // Console.WriteLine("¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯"); // Console.WriteLine("Check if the word 'Recommendation' is spelled correct"); // bool correct = hunspell.Spell("Recommendation"); // Console.WriteLine("Recommendation is spelled " + // (correct ? "correct" : "not correct")); // Console.WriteLine(""); // Console.WriteLine("Make suggestions for the word 'Recommendatio'"); // List<string> suggestions = hunspell.Suggest("Recommendatio"); // Console.WriteLine("There are " + // suggestions.Count.ToString() + " suggestions"); // foreach (string suggestion in suggestions) // { // Console.WriteLine("Suggestion is: " + suggestion); // } //} }
private void Bodymethod(string dicMode, string affMode, int length, List <string> candidat) { var dictionary = WordList.CreateFromFiles(dicMode, affMode); if (length == -1) { foreach (var c in candidat) { var suggestions = dictionary.Suggest(c); Keys.AddRange(suggestions); } } else { foreach (var c in candidat) { if (c.Length < length) { continue; } else if (c.Length > length) { break; } else { var suggestions = dictionary.Suggest(c); Keys.AddRange(suggestions); } } } }
public MainWindow() { InitializeComponent(); blinkStopwatch.Start(); Loaded += MainWindow_Loaded; Dictionary <char, Button> keyboardGrid = new Dictionary <char, Button>(); Dispatcher.BeginInvoke(new Action(() => { foreach (System.Windows.Controls.Button button in allLetters.Children) { keyboardGrid.Add(button.Name[6], new Button { X1 = button.Margin.Left, X2 = button.Margin.Left + button.Width, Y1 = button.Margin.Top, Y2 = button.Margin.Top + button.Height }); } }), DispatcherPriority.ContextIdle, null); inputAnalyzer = new InputAnalyze(keyboardGrid, WordList.CreateFromFiles(@"./English (British).dic")); }
private async Task MainAsync() { var credentials = JsonConvert.DeserializeObject <Credentials>(File.ReadAllText("Keys/Credentials.json")); if (credentials.BotToken == null) { throw new NullReferenceException("Invalid Credentials file"); } var factory = new RankedLanguageIdentifierFactory(); _identifier = factory.Load("Keys/Core14.profile.xml"); foreach (var file in Directory.GetFiles("Dictionaries")) { FileInfo fi = new FileInfo(file); if (fi.Name.Split('.')[1] == "dic") { _dictionaries.Add(fi.Name.Split('.')[0], WordList.CreateFromFiles(file)); } } await _commands.AddModuleAsync <Communication>(null); Client.MessageReceived += HandleCommandAsync; StartTime = DateTime.Now; await Client.LoginAsync(TokenType.Bot, credentials.BotToken); await Client.StartAsync(); await Task.Delay(-1); }
public async Task SpellCheck(CommandContext ctx, [Description("Sentence to spell check")] params string[] message) { ctx.Client.GetInteractivity(); int errorCount = 0; int correctCount = 0; StringBuilder sb = new StringBuilder(); foreach (string word in message) { var dictionary = WordList.CreateFromFiles(@"Resources/en_au.dic"); bool notOk = dictionary.Check(word); if (notOk == false) { errorCount += 1; var suggestion = dictionary.Suggest(word).First().ToString(); sb.Append($" `{suggestion}`"); } else { correctCount += 1; sb.Append($" {word}"); } } await ctx.Channel.SendMessageAsync($"correct: {correctCount}\nIncorrect: {errorCount}\nSuggested spelling: {sb.ToString()}").ConfigureAwait(false); }
/// <summary> /// /// </summary> /// <param name="dicPath"></param> /// <param name="affPath"></param> public Speller(string dicPath, string affPath) { Dictionary = WordList.CreateFromFiles(dicPath, affPath); CustomDictionary = WordList.CreateFromWords(new List <string> { "RFI" }); }
/// <summary> /// /// </summary> /// <param name="dicPath"></param> /// <param name="affPath"></param> /// <param name="additions"></param> public Speller(string dicPath, string affPath, IReadOnlyCollection <string> additions = null) { Dictionary = WordList.CreateFromFiles(dicPath, affPath); if (additions != null && additions.Any()) { CustomDictionary = WordList.CreateFromWords(additions); } }
public void Benchmark(BenchmarkContext context) { foreach (var filePair in TestFiles) { var checker = WordList.CreateFromFiles(filePair.DictionaryFilePath, filePair.AffixFilePath); checker.Check(TestWord); FilePairsLoaded.Increment(); } }
public void Setup() { WordList = WordList.CreateFromFiles(Path.Combine(DataFilePaths.TestFilesFolderPath, "English (American).dic")); WordData = CategorizedWordData.Create( CategorizedWordData.GetAssortedEnUsWords(), isCorrect: WordList.Check, isRoot: WordList.ContainsEntriesForRootWord); }
private WordList GetWordList() { if (wordList == null) { var directory = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent; var file = directory.GetFiles("en_US.dic").First(); wordList = WordList.CreateFromFiles(file.FullName); } return(wordList); }
public override void Setup(BenchmarkContext context) { base.Setup(context); var testAssemblyPath = Path.GetFullPath(GetType().Assembly.Location); var filesDirectory = Path.Combine(Path.GetDirectoryName(testAssemblyPath), "files/"); Checker = WordList.CreateFromFiles(Path.Combine(filesDirectory, "English (American).dic")); WordsChecked = context.GetCounter(nameof(WordsChecked)); }
static void DictionaryLoads() { var testAssemblyPath = Path.GetFullPath(typeof(Program).Assembly.Location); var filesDirectory = Path.Combine(Path.GetDirectoryName(testAssemblyPath), "files/"); var dictionaryFilePaths = Directory.GetFiles(filesDirectory, "*.dic").OrderBy(p => p); foreach (var dictionaryFilePath in dictionaryFilePaths) { WordList.CreateFromFiles(dictionaryFilePath); } }
static void Suggestions() { var hunspell = WordList.CreateFromFiles("files/English (American).dic"); var words = ReadWords() .Take(500) .ToList(); foreach (var word in words) { var isFound = hunspell.Check(word); var suggestions = hunspell.Suggest(word); } }
static void Checks() { var hunspell = WordList.CreateFromFiles("files/English (American).dic"); var words = ReadWords().ToList(); for (var i = 0; i < 1000; i++) { foreach (var word in words) { hunspell.Check(word); } } }
public static string AutoCorrect(string word, string dicFilePath, string affFilePath) { var dictionary = WordList.CreateFromFiles(dicFilePath, affFilePath); var suggestions = dictionary.Suggest(word).ToArray <string>(); foreach (var suggestion in suggestions) { if (suggestion.Length > word.Length) { return(suggestion); } } return(word); }
private static Result <WordList> GetDictionary(string path) { if (!File.Exists(path + "ru_RU.dic") || !File.Exists(path + "ru_RU.aff")) { return(Result.Fail <WordList>("Not found dictionaries (ru_RU.dic/ru_RU.aff) by path " + path)); } try { return(WordList.CreateFromFiles(path + "ru_RU.dic", path + "ru_RU.aff")); } catch (Exception e) { return(Result.Fail <WordList>("Unhandled exception: " + e)); } }
public static bool IsIndDic(this string word) { var dictionary = WordList.CreateFromFiles("en_GB.dic"); if (!dictionary.Check(word)) { return(false); } return(true); }
static void Main(string[] args) { List <Vertex> vertices = GetData(); int currentTeam = 1; //Console.WriteLine(string.Format("There are {0} vertices", vertices.Count)); //foreach(Vertex vtx in vertices) //{ // Console.WriteLine(vtx.Diag()); //} // loop from 0 to the end // if the vertex is discovered goto next one // print the team, currentTeam++, goto next one string result = ""; for (int i = 0; i < vertices.Count; i++) { if (vertices[i].Discovered) { continue; } result += GetLetter(i, vertices, currentTeam); currentTeam++; } printAnagram("", result); var dictionary = WordList.CreateFromFiles(@"en_GB.dic"); Console.WriteLine(dictionary.Check("home") ? "PASS" : "FAIL"); foreach (string item in results) { if (dictionary.Check(item)) { Console.WriteLine(item); break; } } #if LOCAL Console.ReadLine(); #endif } // Main
/// <summary> /// /// </summary> public Speller() { var dllPath = Assembly.GetExecutingAssembly().Location; var binPath = Path.GetDirectoryName(dllPath); if (binPath == null) { return; } var packagePath = Path.Combine(binPath, @"..\"); var extraPath = Path.Combine(packagePath, "extra"); var dicPath = Path.Combine(extraPath, "en_US.dic"); var affPath = Path.Combine(extraPath, "en_US.aff"); Dictionary = WordList.CreateFromFiles(dicPath, affPath); CustomDictionary = WordList.CreateFromWords(new List <string> { "RFI" }); }
static List <string> Bodymethod(string dicMode, string affMode, int length, List <string> candidat) { List <string> Keys = new List <string>(); var dictionary = WordList.CreateFromFiles(dicMode, affMode); if (length == -1) { foreach (var c in candidat) { var suggestions = dictionary.Suggest(c); foreach (var s in suggestions) { Keys.Add(s); } } } else { foreach (var c in candidat) { if (c.Length < length) { continue; } else if (c.Length > length) { break; } else { var suggestions = dictionary.Suggest(c); foreach (var s in suggestions) { Keys.Add(s); } } } } return(Keys); }
public virtual void Setup(BenchmarkContext context) { var testAssemblyPath = Path.GetFullPath(GetType().Assembly.Location); var filesDirectory = Path.Combine(Path.GetDirectoryName(testAssemblyPath), "files/"); Task.WhenAll( Task.Run((Action)LoadChecker), Task.Run((Action)LoadWords)) .GetAwaiter().GetResult(); void LoadChecker() { Checker = WordList.CreateFromFiles(Path.Combine(filesDirectory, "English (American).dic")); } void LoadWords() { Words = new List <string>(); using (var stram = new FileStream(Path.Combine(filesDirectory, "List_of_common_misspellings.txt"), FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true)) using (var reader = new StreamReader(stram, Encoding.UTF8, true)) { string line; while ((line = reader.ReadLine()) != null) { line = line.Trim(); if (line.Length == 0 || line.StartsWith("#") || line.StartsWith("[")) { continue; } Words.AddRange(line.Split(new char[] { ' ', '\t', ',' }, StringSplitOptions.RemoveEmptyEntries)); } } } }
private static WordList GetDictionary(string path) { return(WordList.CreateFromFiles(path + "ru_RU.dic", path + "ru_RU.aff")); }
public async Task WiggimsBotSpell(CommandContext ctx) { bool isCommand = ctx.Message.Content.ToLower().Contains("w!") || ctx.Message.Content.ToLower().Contains("w@"); bool isBot = ctx.Message.Author.IsBot; bool isCodeBlock = ctx.Message.Content.Contains("```"); string[] message = ctx.Message.Content.Split(); int errorCount = 0; int correctCount = 0; int boganCount = 0; List <string> sb = new List <string> { }; GuildPreferences guildPreferences = await _guildPreferences.GetOrCreateGuildPreferences(ctx.Guild.Id); if (!isCommand && !isBot && !isCodeBlock) { foreach (string word in message) { if ( string.IsNullOrWhiteSpace(word) || word.Contains("https://") || word.Length > 18 || word.Contains(":") || word.Contains("😢") || word.Contains("👍") || word.Contains("👎") || word.Contains("😀") || word.Contains("😃") || word.Contains("😄") || word.Contains("😁") || word.Contains("😆") || word.Contains("😅") || word.Contains("😂") || word.StartsWith("!") || word.StartsWith("d!") || word.StartsWith(">") || !guildPreferences.SpellingEnabled ) { return; } var dictionary = WordList.CreateFromFiles(@"Resources/en_au.dic"); var boganDictionary = WordList.CreateFromFiles(@"Resources/badwords.dic"); string cleanedWord = Regex.Replace(word.ToLower(), @"[^\w\s]", ""); bool notOk = dictionary.Check(cleanedWord); bool Bogan = boganDictionary.Check(cleanedWord); if (notOk == false) { errorCount += 1; Console.WriteLine(cleanedWord); sb.Add(cleanedWord); await File.AppendAllTextAsync(@"Resources/missspelledwordsall.txt", $"\n{cleanedWord} - {word}"); var wrongDictionary = WordList.CreateFromFiles(@"Resources/missspelledwords.dic"); bool alreadyPresent = wrongDictionary.Check(cleanedWord); if (alreadyPresent == false) { string dicFilePath = @"Resources/missspelledwords.dic"; await File.AppendAllTextAsync(dicFilePath, $"\n{cleanedWord}"); } if (Bogan == true) { boganCount += 1; } } else { correctCount += 1; if (Bogan == true) { boganCount += 1; } } } Console.WriteLine($"{ctx.Message.Author.Username} sent a message in the {ctx.Guild.Name} guild. spelling stats:\nCorrect: {correctCount}\tIncorrect: {errorCount}\tBogan words: {boganCount}"); Profile profile = await _profileService.GetOrCreateProfileAsync(ctx.Member.Id, ctx.Guild.Id); TextProcessorViewModel viewModel = await _textProcessorService.ProcessTextAsync(ctx.Member.Id, ctx.Guild.Id, $"{ctx.Member.Username}#{ctx.Member.Discriminator}", correctCount, errorCount, boganCount, 1, guildPreferences.ErrorListLength, sb).ConfigureAwait(false); if (!viewModel.LevelledUp) { return; } var json = string.Empty; using (var fs = File.OpenRead("config.json")) using (var sr = new StreamReader(fs, new UTF8Encoding(false))) json = sr.ReadToEnd(); var configJson = JsonConvert.DeserializeObject <ConfigJson>(json); int goldperlevelup = configJson.goldperlevelup; await _goldService.TransferGold(ctx.Client.CurrentUser.Id, ctx.Member.Id, ctx.Guild.Id, goldperlevelup, true); if (profile.QuietMode == true) { return; } var levelUpEmbed = new DiscordEmbedBuilder { Title = $"{ctx.Member.DisplayName} Is Now Level {viewModel.Profile.Level}", Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail { Url = ctx.Member.AvatarUrl }, Color = ctx.Member.Color }; if (goldperlevelup > 0) { levelUpEmbed.WithDescription($"+ {goldperlevelup} :moneybag:"); } levelUpEmbed.WithFooter("`w!profile togglenotifications` to hide In future."); await ctx.Channel.SendMessageAsync(embed : levelUpEmbed).ConfigureAwait(false); } }
public static HashSet <string> ReadDic(string dicPath, string affPath) { var wordList = WordList.CreateFromFiles(dicPath, affPath); return(wordList.RootWords.Where(IsNoun).ToHashSet()); }
public static bool CheckIfTermInDictionary(string term, string dicFilePath, string affFilePath) { var dictionary = WordList.CreateFromFiles(dicFilePath, affFilePath); return(dictionary.Check(term)); }
public SpellCheckModel(IWebHostEnvironment appEnvironment) { _appEnvironment = appEnvironment; _dictionaryRu = WordList.CreateFromFiles(_appEnvironment.WebRootPath + "/ru_RU.dic"); _dictionaryEn = WordList.CreateFromFiles(_appEnvironment.WebRootPath + "/en_GB.dic"); }
static SpellCheck() { Stopwatch timer = new Stopwatch(); timer.Start(); try { string dictionaryDir = Path.Combine(Directory.GetCurrentDirectory(), "Resources", "SpellCheck"); if (!Directory.Exists(dictionaryDir)) { m_dictionary = new Dictionary <string, WordList>(); return; } // parse file paths to get Dictionary <string, string[]> filePair = new Dictionary <string, string[]>(); foreach (string path in Directory.EnumerateFiles(dictionaryDir)) { string type = Path.GetFileNameWithoutExtension(path)?.ToLower(); string end = Path.GetExtension(path)?.ToLower(); if (string.IsNullOrEmpty(type) || string.IsNullOrEmpty(end)) { continue; } if (!s_acceptedFormats.Contains(end)) { continue; } if (!filePair.ContainsKey(type)) { filePair[type] = new string[2]; } if (end == ".dic") { filePair[type][0] = path; } if (end == ".aff") { filePair[type][1] = path; } } Logging.Logger.Log(LogLevel.Info, $"Found {filePair.Count} dictionaries, starting import"); ConcurrentDictionary <string, WordList> saveDictionary = new ConcurrentDictionary <string, WordList>(); Parallel.ForEach(filePair, (pair, state) => { if (pair.Value[0] == null) { return; } try { WordList dictionary = WordList.CreateFromFiles(pair.Value[0], pair.Value[1]); saveDictionary.TryAdd(pair.Key, dictionary); Logging.Logger.Log(LogLevel.Info, $"Imported '{pair.Key}' language dictionary"); } catch (Exception ex) { Logging.Logger.Log(LogLevel.Error, ex, $"Unable to initialize spell check directory ('{pair.Key}')"); } }); m_dictionary = new Dictionary <string, WordList>(saveDictionary); } finally { timer.Stop(); Logging.Logger.Log(LogLevel.Info, $"{m_dictionary.Count} Spelling dictionaries imported, took {timer.Elapsed.TotalSeconds} seconds"); } }
public async Task AddToDictionary(CommandContext ctx, [Description("Word to be added.")] string word, [Description("retype word to be added.")] string confirmWord) { Profile profile = await _profileService.GetOrCreateProfileAsync(ctx.Member.Id, ctx.Guild.Id); if (profile.SpellAcc < 90) { await ctx.Channel.SendMessageAsync($"Your spelling must be above 90% to add to the dictionary, at the moment you are currently at {profile.SpellAcc}%."); return; } if (confirmWord != word) { await ctx.Channel.SendMessageAsync($"'{word}' and '{confirmWord}' are not the same.").ConfigureAwait(false); return; } string newWord = Regex.Replace(word, @"[^\w\s]", "").ToLower(); var dictionary = WordList.CreateFromFiles(@"Resources/en_au.dic"); bool notOk = dictionary.Check(newWord); if (notOk == true) { await ctx.Channel.SendMessageAsync($"{newWord} is already in the dictionary.").ConfigureAwait(false); return; } string dicFilePath = @"Resources/en_au.dic"; await File.AppendAllTextAsync(dicFilePath, $"\n{newWord}"); // string spellMistakesDic = "Resources/missspelledwords.dic"; string[] Lines = File.ReadAllLines(spellMistakesDic); File.Delete(spellMistakesDic); using (StreamWriter sw = File.AppendText(spellMistakesDic)) { foreach (string line in Lines) { if (line.StartsWith(newWord)) { continue; } else { sw.WriteLine(line); } } } string logFilePath = "Logs/dictionary.log"; await File.AppendAllTextAsync(logFilePath, $"\n{DateTime.Now}: {ctx.Member} added a new word to the dictionary '{newWord}'."); await ctx.Channel.SendMessageAsync($"{newWord} was added to the dictionary.").ConfigureAwait(false); await _textProcessorService.RemoveDictionaryWordFromLists(newWord); }