private void btnPreview_Click(object sender, EventArgs e) { var filePaths = txbFilePath.Text.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (filePaths.Length == 0) { MessageBox.Show("未选择字幕文件"); return; } SubtitleFiles.Clear(); stOperator = SubtitleHelper.GetOperatorByFileName(filePaths[0]); foreach (var filePath in filePaths) { var content = FileOperationHelper.ReadFile(filePath); var srts = stOperator.Parse(content); SubtitleFiles.Add(filePath, srts); } richTextBox1.Clear(); foreach (var subtitleFile in SubtitleFiles) { richTextBox1.AppendText("----" + subtitleFile.Key + "----\r\n"); richTextBox1.AppendText(stOperator.Subtitle2String(subtitleFile.Value)); } }
private void btnPickupNewWords_Click(object sender, EventArgs e) { if (folderBrowserDialog1.ShowDialog() != DialogResult.OK) { return; } SentenceParse sentenceParse = new SentenceParse(); DirectoryInfo directoryInfo = new DirectoryInfo(folderBrowserDialog1.SelectedPath); List <string> sentences = new List <string>(); foreach (FileInfo fileInfo in directoryInfo.GetFiles()) { string filePath = fileInfo.FullName; var txt = FileOperationHelper.ReadFile(filePath); var stOperator = SubtitleHelper.GetOperatorByFileName(filePath); var srts = stOperator.Parse(txt); srts = stOperator.RemoveChinese(srts); sentences.AddRange(srts.Bodies.Values.Select(l => l.EnglishText)); } Splash.Show(); Splash.Status = "解析字幕中..."; IDictionary <string, VPreviewWord> previewWords = new Dictionary <string, VPreviewWord>(); foreach (var sentence in sentences) { var newWords = sentenceParse.Pickup(sentence); foreach (KeyValuePair <string, string> keyValuePair in newWords) { string original = keyValuePair.Key; string word = keyValuePair.Value; if (previewWords.ContainsKey(original)) { previewWords[original].Rank++; } else { var mean = sentenceParse.RemarkWord(sentence, word, original); if (mean != null) { var wd = new VPreviewWord() { Word = mean.Word, Rank = 1, Sentence = sentence, Mean = mean.DefaultMean == null ? mean.Means[0].ToString() : mean.DefaultMean.ToString() }; previewWords.Add(original, wd); } } } } DisplayPreviewWords(previewWords.Values); Splash.Close(); }
private void ReadAndShowSubtitle() { var txt = FileOperationHelper.ReadFile(txbSubtitleFilePath.Text); stOperator = SubtitleHelper.GetOperatorByFileName(txbSubtitleFilePath.Text); var srts = stOperator.Parse(txt); srts = stOperator.RemoveChinese(srts); srts = stOperator.RemoveFormat(srts); ShowSubtitleText(srts.Bodies.Values); subtitle = srts; }
private void btnParse_Click(object sender, EventArgs e) { var txt = FileOperationHelper.ReadFile(txbSubtitleFilePath.Text); stOperator = SubtitleHelper.GetOperatorByFileName(txbSubtitleFilePath.Text); var srts = stOperator.Parse(txt); srts = stOperator.RemoveChinese(srts); ShowSubtitleText(srts.Bodies); subtitle = srts; }