public static void IncreaseFrequency(ExcelManager excelApp, int indexOfWordInDictionary, int freq) { string oldFrequnecy = excelApp.GetValue(Columns.freq, indexOfWordInDictionary); int newFrequency = Convert.ToInt32(excelApp.GetValue(Columns.freq, indexOfWordInDictionary)) + freq; excelApp.SetValue(Columns.freq, indexOfWordInDictionary, newFrequency.ToString()); }
void Tag(string tag) { if (memo.study.Count == 0) { return; } excelApp.SetValue(DM.Columns.level, memo.GetCurrentWord().index + 2, tag); excelApp.Save(); FileSaver.TagLog(memo.GetCurrentWord().word, tag); skipButton_Click(null, null); WordsCounter(); richTextBox1.Focus(); }
public static void AddExamples(ExcelManager excelApp, List <string> examples, int indexOfWordInDictionary) { foreach (var example in examples) { for (int col = 0; col < WordsFormer.maxExamples; col++) { string celVal = excelApp.GetValue(col + WordsFormer.whereExamplesStart, indexOfWordInDictionary); if (celVal == example) { break; } if (celVal == null || celVal == "") { excelApp.SetValue(col + WordsFormer.whereExamplesStart, indexOfWordInDictionary, example); break; } } } }
private void addWordsFromTextButton_Click(object sender, EventArgs e) { InitDictionaryManagerPaths(); if (commonSourceTextBox.Text == "" || sourceTextBox.Text == "") { MessageBox.Show("Не заполнены поля источники"); return; } string textToAnalyze = FileSaver.ReadTextToAnalize(); if (textToAnalyze == "") { MessageBox.Show("Файл " + DM.fileToAnalizePath + " не найден"); return; } string pathToExcel = FileSaver.OpenExcelFile(); if (DM.PathToExcel == "") { MessageBox.Show("Файл " + DM.PathToExcel + " не найден"); return; } int news = 0; int olds = 0; string log = ""; WordsFormer allWords = new WordsFormer(); allWords.analyzeAll(textToAnalyze); if (excelApp == null) { excelApp = new ExcelManager(); excelApp.Open(DM.PathToExcel); } List <string> existedWords = excelApp.GetColumn(DM.Columns.word); List <string> lfreq = excelApp.GetColumn(DM.Columns.freq); List <string> lLvl = excelApp.GetColumn(DM.Columns.level); int oldUnder = 0; List <string> oldUnderList = new List <string>(); List <int> oldUnderCntList = new List <int>(); List <int> newsCnt = new List <int>(); for (int i = 0; i < existedWords.Count; i++) { var f = Convert.ToInt32(lfreq[i]); if (lLvl[i] == "0" && Convert.ToInt32(lfreq[i]) <= DictionaryManager.NumberOfRare) { oldUnderList.Add(existedWords[i]); } } for (int j = 0; j < allWords.dict.Count; j++) { string word = allWords.dict[j].word; int indexOfWordInDictionary = existedWords.IndexOf(word); Text = j.ToString() + "/" + allWords.dict.Count.ToString(); if (indexOfWordInDictionary < 0)//add new { Translator tranlate = new Translator(); Translator.WordTranslation translatedWord; translatedWord = tranlate.makeTranslations(word); int lastRow = excelApp.lastRow; excelApp.SetValue(DM.Columns.word, lastRow, translatedWord.word); excelApp.SetValue(DM.Columns.freq, lastRow, allWords.dict[j].freq.ToString()); excelApp.SetValue(DM.Columns.level, lastRow, "0"); excelApp.SetValue(DM.Columns.date, lastRow, DateTime.Today.ToShortDateString()); excelApp.SetValue(DM.Columns.definition, lastRow, translatedWord.definition); excelApp.SetValue(DM.Columns.init, lastRow, translatedWord.initial); excelApp.SetValue(DM.Columns.trans1, lastRow, translatedWord.translation.Split('\t')[0]); excelApp.SetValue(DM.Columns.trans2, lastRow, translatedWord.translation.Split('\t')[1]); excelApp.SetValue(DM.Columns.trans3, lastRow, translatedWord.translation.Split('\t')[2]); excelApp.SetValue(DM.Columns.src, lastRow, sourceTextBox.Text); excelApp.SetValue(DM.Columns.comSrc, lastRow, commonSourceTextBox.Text); DM.AddExamples(excelApp, allWords.dict[j].examples, lastRow); news++; } else { indexOfWordInDictionary = indexOfWordInDictionary + 2;//first two rows isnot count. can refacotr DM.IncreaseFrequency(excelApp, indexOfWordInDictionary, allWords.dict[j].freq); DM.AddExamples(excelApp, allWords.dict[j].examples, indexOfWordInDictionary); olds++; if (oldUnderList.IndexOf(word) > -1) { oldUnder++; } log = log + word + "\taddFreq " + allWords.dict[j].freq.ToString() + "\tfrom " + allWords.dict[j].word + "\r"; } } Text = $"Новые {news}, знаю {olds}, всего {allWords.dict.Count}. Сложность {(news * 100 / allWords.dict.Count)}%. Редкие {oldUnder}"; FileSaver.Log(log); FileSaver.Duplicate(sourceTextBox.Text); excelApp.makeVisible(); }