Beispiel #1
0
        private void translateText_ButtonClick(object sender, EventArgs e)
        {
            /*Translator trans = new Translator();
            *  string tr = trans.GetOxfordDefinition("dangle");
            *  File.WriteAllText(@"C:\gg.txt", tr);*/

            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;
            }

            if (excelApp == null)
            {
                excelApp = new ExcelManager();
                excelApp.Open(DM.PathToExcel);
            }
            Translator trans = new Translator();

            List <string> existedWords = excelApp.GetColumn(DM.Columns.word);

            for (int j = 23000; j < 23890; j++)//existedWords.Count
            {
                //1000000000
                for (double i = 0; i < 1000000000; i++)
                {
                    var x = 0;
                    var y = 2;
                    var h = x * y / 2;
                }

                Text = j.ToString();
                try
                {
                    string word = existedWords[j];
                    string tr   = trans.GetOxfordDefinition(word);
                    excelApp.SetValue(DM.Columns.definition, j + 2, tr);
                }
                catch (Exception ee)
                {
                    File.AppendAllText(@"C:\111.txt", j.ToString() + "  " + ee.Message + "\n");
                }
            }
            excelApp.makeVisible();
        }
Beispiel #2
0
        private void button3Kana_Click(object sender, EventArgs e)
        {
            string textToAnalyze = FileSaver.ReadTextToAnalize();

            if (textToAnalyze == "")
            {
                MessageBox.Show("Файл " + DM.fileToAnalizePath + " не найден");
                return;
            }

            List <Word> dict1 = new List <Word>();
            List <Word> ready = new List <Word>();

            foreach (var item in textToAnalyze)
            {
                if (item != ' ' && item != '.' && !kana.Contains(item) && item != '\r' && item != '\n' && item != '!' && item != '?')
                {
                    dict1.Add(new Word(item.ToString()));
                }
            }

            foreach (var word in dict1)
            {
                if (cont(word.word, ready))
                {
                    int i = ind(word.word, ready);
                    if (i > -1)
                    {
                        ready[i].freq += 1;
                    }
                }
                else
                {
                    ready.Add(word);
                }
            }

            string str = "";

            foreach (var item in ready)
            {
                str += item.word + "\t" + item.freq + "\r";
            }
            File.WriteAllText(@"C:\3\jpn.txt", str);

            string text = File.ReadAllText(@"C:\3\1.txt");

            text = text.Replace("\r", "<br>");

            foreach (var item in used)
            {
                text = text.Replace(item.ToString(), "<strong style='color:red;'>" + item.ToString() + "</strong>");
            }
            File.WriteAllText(@"C:\3\ready.html", text);
        }
Beispiel #3
0
        private void beautifyButton_Click(object sender, EventArgs e)
        {
            InitDictionaryManagerPaths();
            if (excelApp == null)
            {
                string pathToExcel = FileSaver.OpenExcelFile();
                if (pathToExcel == "")
                {
                    MessageBox.Show("Файл " + DM.PathToExcel + " не найден");
                    return;
                }
                excelApp = new ExcelManager();
                excelApp.Open(DM.PathToExcel);
            }

            string textToAnalyze = FileSaver.ReadTextToAnalize();

            if (textToAnalyze == "")
            {
                MessageBox.Show("Файл " + DM.fileToAnalizePath + " не найден");
                return;
            }

            WordsFormer allWords = new WordsFormer();

            allWords.analyzeAll(textToAnalyze);

            List <string> lWords      = excelApp.GetColumn(DM.Columns.word);
            List <string> lfreq       = excelApp.GetColumn(DM.Columns.freq);
            List <string> lLvl        = excelApp.GetColumn(DM.Columns.level);
            List <string> lSrs        = excelApp.GetColumn(DM.Columns.src);
            List <string> ltrans1     = excelApp.GetColumn(DM.Columns.trans1);
            List <string> ltrans2     = excelApp.GetColumn(DM.Columns.trans2);
            List <string> ltrans3     = excelApp.GetColumn(DM.Columns.trans3);
            List <string> ldefinition = excelApp.GetColumn(DM.Columns.definition);


            string addFreq;
            string miniDict = "";

            for (int i = 0; i < allWords.dict.Count; i++)
            {
                string word = allWords.dict[i].word;

                this.Text = i.ToString();

                int ind = lWords.IndexOf(word);
                if (ind < 0)
                {
                    continue;
                }

                addFreq = lfreq[ind];

                Stylizer styleze = new Stylizer();

                //string translation = ltrans1[ind] + ',' + ltrans2[ind] + ',' + ltrans3[ind];
                string translation = ltrans1[ind] + ',' + ltrans2[ind] + ',' + ltrans3[ind] + "\n------\n";
                translation += ldefinition[ind].Replace("\"", "").Replace("'", "");


                if (lSrs[ind] == sourceTextBox.Text) //that source
                {
                    if (lLvl[ind] == "0")            //dont know, new
                    {
                        styleze.StylizeWord(word, ref textToAnalyze, addFreq, DM.Styles.bold, translation);
                    }

                    if (lLvl[ind] == "1")//maybe know, new
                    {
                        styleze.StylizeWord(word, ref textToAnalyze, addFreq, DM.Styles.brown, translation);
                    }

                    bool writeFullMiniDIct = true;
                    if (writeFullMiniDIct && (lLvl[ind] == "0" || lLvl[ind] == "1"))
                    {
                        miniDict = miniDict + word + '\t' + ltrans1[ind] + '\t' + ltrans2[ind] + '\t' + ltrans3[ind] + '\r';
                    }
                }
                else
                {
                    if (lLvl[ind] == "0" || lLvl[ind] == "1")//maybe know and don't know, another source
                    {
                        styleze.StylizeWord(word, ref textToAnalyze, addFreq, DM.Styles.italic, translation);
                        miniDict = miniDict + word + '\t' + ltrans1[ind] + '\t' + ltrans2[ind] + '\t' + ltrans3[ind] + '\r';
                    }
                    if (lLvl[ind] == "2")//maybe know and don't know, another source
                    {
                        styleze.StylizeWord(word, ref textToAnalyze, addFreq, DM.Styles.blue, translation);
                        miniDict = miniDict + word + '\t' + ltrans1[ind] + '\t' + ltrans2[ind] + '\t' + ltrans3[ind] + '\r';
                    }
                }
            }
            textToAnalyze = textToAnalyze.Replace("\r", "<br>");

            string name = commonSourceTextBox.Text + " " + sourceTextBox.Text;

            FileSaver.WriteFiles(name, miniDict, textToAnalyze);

            excelApp.Quit();
            Application.Exit();
        }
Beispiel #4
0
        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();
        }