Example #1
0
        private void beautifySubs_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);
            }
            var    pathSubs = @"C:\3\subs.srt";
            string text     = File.ReadAllText(pathSubs, Encoding.UTF8);

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

            WordsFormer allWords = new WordsFormer();

            allWords.analyzeAll(text);

            List <string> lWords = excelApp.GetColumn(DM.Columns.word);
            List <string> lLvl   = excelApp.GetColumn(DM.Columns.level);
            List <string> lSrs   = excelApp.GetColumn(DM.Columns.src);



            for (int i = 0; i < allWords.dict.Count; i++)
            {
                string   word = allWords.dict[i].word;
                Stylizer st   = new Stylizer();
                this.Text = i.ToString();

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


                if (lLvl[ind] == "0")
                {
                    if (lSrs[ind] == sourceTextBox.Text)
                    {
                        sign = " * ";
                    }
                    else
                    {
                        sign = " + ";
                    }

                    int tIndex = text.IndexOf(word, StringComparison.CurrentCultureIgnoreCase);
                    if (tIndex < 0)
                    {
                        continue;
                    }
                    do
                    {
                        if (st.IsComplete(word, text, tIndex))
                        {
                            text = text.Insert(tIndex, sign);
                            text = text.Insert(tIndex + sign.Length + word.Length, sign);
                        }
                        tIndex = text.IndexOf(word, tIndex + sign.Length + word.Length + 2, StringComparison.CurrentCultureIgnoreCase);
                    } while (tIndex > 0);
                }
            }

            File.WriteAllText(@"C:\3\subs2.srt", text);


            bool isOnlyNewWords = true;

            if (isOnlyNewWords)
            {
                var           lines    = File.ReadAllLines(@"C:\3\subs2.srt", Encoding.UTF8).ToList();
                List <string> resLines = new List <string>();


                for (int i = 0; i < lines.Count; i++)
                {
                    bool containsNewWords = lines[i].Contains("*") || lines[i].Contains("+");

                    if (containsNewWords)
                    {
                        int st  = findStart(lines, i);
                        int end = findEnd(lines, i);
                        for (int k = st; k <= end; k++)
                        {
                            resLines.Add(lines[k]);
                        }
                        i = end;
                    }
                }
                File.WriteAllLines(@"C:\3\subs23.srt", resLines);
            }

            beautifyButton_Click(null, null);

            /*
             * excelApp.Quit();
             * Application.Exit();*/
        }
Example #2
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();
        }
Example #3
0
        private void countWordsButton_Click(object sender, EventArgs e)
        {
            StringBuilder st  = new StringBuilder();
            var           dir = new DirectoryInfo(@"C:\3\many\").GetFiles();

            foreach (var file in dir)
            {
                st.AppendLine(File.ReadAllText(file.FullName, Encoding.UTF8));
            }

            string pathToExcel = FileSaver.OpenExcelFile();

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

            int news            = 0;
            int olds            = 0;
            int oldUnder        = 0;
            int oldUnderFreqSum = 0;

            WordsFormer.Counting = true;

            WordsFormer allWords = new WordsFormer();

            allWords.analyzeAll(st.ToString());

            WordsFormer.Counting = false;

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

            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
                {
                    news++;
                    newsCnt.Add(allWords.dict[j].freq);
                }
                else
                {
                    olds++;
                    if (oldUnderList.IndexOf(word) > -1)
                    {
                        oldUnder++;
                        oldUnderFreqSum += allWords.dict[j].freq;
                        oldUnderCntList.Add(allWords.dict[j].freq);
                    }
                }
            }

            Text  = $"Новые {news}, среднее кол-во {newsCnt.FindAll(x => x < 15).Average()}, знаю {olds}, всего {allWords.dict.Count}. Сложность {(news * 100 / allWords.dict.Count)}%";
            Text += $". Редкие старые {oldUnder}, в среднем {oldUnderCntList.Average()}";
            excelApp.makeVisible();
            excelApp.Quit();
        }
Example #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();
        }