/// <summary> /// Counts the words in the text files we have for the currently selected language. /// </summary> public void CountWords() { var inputDirectory = new DirectoryInfo(CommonFiles.DocsPath(_languageId)); var inputFiles = inputDirectory.GetFiles("*.txt", SearchOption.TopDirectoryOnly); string outputFilePath = Path.Combine(CommonFiles.AllWordsSorted(_languageId)); var wordCounter = new WordCounter(); wordCounter.CountWords(inputFiles, outputFilePath, _ignoreCase); // Reload words here? //InitializeLanguage(); }
/// <summary> /// Counts n-grams in the text files for the selected language. /// </summary> private void CountNGrams() { try { string lang = _languageId; var indexer = new NGramIndexer(CommonFiles.Words(lang), CommonFiles.WordCounts(lang), CommonFiles.NGrams(lang), CommonFiles.NGramCounts(lang), CommonFiles.NGramsByWord(lang), CommonFiles.WordsByNGram(lang)) { Order = NGramOrder }; var counter = new WordCounter(); var inputDirectory = new DirectoryInfo(CommonFiles.DocsPath(lang)); var inputFiles = inputDirectory.GetFiles("*.txt", SearchOption.TopDirectoryOnly).Take(NGramMaxFiles).ToList(); var knownWords = new HashSet<string>(_translator.GetKnownWords()); counter.CountNGrams(indexer, inputFiles, knownWords, _ignoreCase); } catch (IOException ex) { Debug.WriteLine(ex.Message + ex.StackTrace); return; } }