private void button6_Click(object sender, EventArgs e) { FileInfo fileInfo = new System.IO.FileInfo(textBox3.Text); String FileName = fileInfo.Name.Replace(fileInfo.Extension, "").Replace(".", "_") + "Dictionery.xml"; DictioneryDataset Dic = new DictioneryDataset(); wordlist.Where(w => !string.IsNullOrEmpty(w.Meaning)).ToList().ForEach(f => Dic.DicTable.AddDicTableRow(f.Text, f.Meaning)); Dic.WriteXml(System.IO.Path.Combine(fileInfo.DirectoryName, FileName)); }
private void button2_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(textBox3.Text)) { textBox3_DoubleClick(sender, e); } // -------------- load dictionery FileInfo fileInfo = new System.IO.FileInfo(textBox3.Text); List <DicEntity> allDic = Business.Dictionery.instance.GetAll(); foreach (DicEntity dicEntity in allDic) { if (!MyDic.ContainsKey(dicEntity.Word)) { MyDic.Add(dicEntity.Word, dicEntity.Meaning); } } //------------------------------------ List <string> RemoveWorsd = new List <string>(); string readAllText = System.IO.File.ReadAllText(textBox3.Text.Trim()); string[] StopWords = System.IO.File.ReadAllLines(System.IO.Path.Combine(Application.StartupPath, "StopWord.txt")); RemoveWorsd.AddRange(StopWords.ToList()); //************************** remove Ignore and IKnow ******************** String IgnoreWordsFileName = fileInfo.Name.Replace(fileInfo.Extension, "").Replace(".", "_") + "IgnoreWords.xml"; String IKnowWordsFileName = fileInfo.Name.Replace(fileInfo.Extension, "").Replace(".", "_") + "IKnowWords.xml"; DictioneryDataset RemoveWordDataset = new DictioneryDataset(); if (System.IO.File.Exists(System.IO.Path.Combine(fileInfo.DirectoryName, IgnoreWordsFileName))) { RemoveWordDataset.ReadXml(System.IO.Path.Combine(fileInfo.DirectoryName, IgnoreWordsFileName)); for (int i = 0; i < RemoveWordDataset.DicTable.Rows.Count; i++) { RemoveWorsd.Add(RemoveWordDataset.DicTable[i].Word); AddToIgnore(RemoveWordDataset.DicTable[i].Word); } } if (System.IO.File.Exists(System.IO.Path.Combine(fileInfo.DirectoryName, IKnowWordsFileName))) { RemoveWordDataset = new DictioneryDataset(); RemoveWordDataset.ReadXml(System.IO.Path.Combine(fileInfo.DirectoryName, IKnowWordsFileName)); for (int i = 0; i < RemoveWordDataset.DicTable.Rows.Count; i++) { RemoveWorsd.Add(RemoveWordDataset.DicTable[i].Word); AddToIKnow(RemoveWordDataset.DicTable[i].Word); } } //************************** remove Ignore and IKnow ******************** string[] Signs = System.IO.File.ReadAllLines(System.IO.Path.Combine(Application.StartupPath, "Signs.txt")); Signs.ToList().ForEach(f => readAllText = readAllText.Replace(f, " ")); List <Word> words = readAllText.Replace("—", " ").Split(' ').Select(s => new Word() { Text = s.ToLower().Trim() }).Where(w => !RemoveWorsd.Any(a => a.ToLower().Trim() == w.Text.Trim()) && w.TextLength > 3).ToList(); // List<Word> words = readAllText.Replace("—", " ").Split(Environment.NewLine.ToCharArray()).Select(s => new Word() { Text = s.ToLower().Trim() }).Where(w => w.TextLength < 33).OrderBy(o => o.Text).ToList(); wordlist = words.GroupBy(g => g.Text).Select(group => new Word() { Text = group.Key, Count = group.Count(), Meaning = MyDic.ContainsKey(group.Key) ? MyDic[group.Key] : Business.Dictionery.instance.getByWord(group.Key).Meaning }).OrderByDescending(o => o.Count).ToList(); dataGridView1.DataSource = wordlist; label1.Text = "Records = " + dataGridView1.RowCount; label2.Text = "Empty Meaning = " + wordlist.Where(w => String.IsNullOrEmpty(w.Meaning)).Count().ToString(); }