Exemplo n.º 1
0
        private void btnRemark_Click(object sender, EventArgs e)
        {
            if (subtitle == null || subtitle.Bodies.Count == 0)
            {
                MessageBox.Show("请先点击“载入字幕”按钮打开字幕文件");
                return;
            }

            Splash.Show("解析字幕中...");

            sentenceParse = new SentenceParse();
            var subtitleWords = PickNewWords(subtitle.Bodies.Values);

            if (subtitleWords.Count > 0)
            {
                NewWordConfirmForm form = new NewWordConfirmForm();
                form.DataSource       = subtitleWords.Values.ToList();
                form.SubtitleFileName = Path.GetFileName(txbSubtitleFilePath.Text);
                form.OnClickOkButton += RemarkSubtitle;
                form.Show();
                form.Activate();
                //if (form.ShowDialog() == DialogResult.OK)
                //{

                //  form.SelectedNewWords
                //}
            }
            Splash.Close();
        }
Exemplo n.º 2
0
        private string ReplaceSubtitleLineByVocabulary(string line, IDictionary <string, SubtitleWord> words)
        {
            StringBuilder sb = new StringBuilder();

            foreach (string s in SentenceParse.SplitSentence(line))
            {
                if (s.Length == 1)
                {
                    sb.Append(s);
                }
                else
                {
                    var    word = s.ToLower();
                    string mean = "";
                    if (words.ContainsKey(s))//这个词需要注释
                    {
                        mean = words[s].SelectMean;
                    }
                    else if (words.ContainsKey(word))
                    {
                        mean = words[word].SelectMean;
                    }

                    if (mean != "")
                    {
                        if (Global.ShortMean)
                        {
                            var meanarray = mean.Split(new char[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries);
                            mean = meanarray[0];
                            mean = mean.Substring(mean.IndexOf(' ') + 1);
                        }
                        sb.Append(string.Format("{0}({1})", s, mean.Trim()));
                    }
                    else
                    {
                        sb.Append(s);
                    }
                }
            }
            return(sb.ToString());

            //var array = SentenceParse.SplitSentence2Words(line);
            //foreach (string oword in array)
            //{
            //    var word = oword.ToLower();

            //    //var w = englishWordService.GetOriginalWord(word);
            //    //var mean = words.ContainsKey(w) ? words[w].SelectMean : "";
            //    //if (!string.IsNullOrEmpty(mean))
            //    //{
            //    //    if(shortMean)
            //    //    {
            //    //        var meanarray = mean.Split(new char[]{';',','},StringSplitOptions.RemoveEmptyEntries);
            //    //        mean = meanarray[0];
            //    //    }
            //    //    line = ReplaceNewWord(line, word, mean);
            //    //}
            //}
            //return line;
        }
Exemplo n.º 3
0
        public void Test1Word2Properties(string sentence, string word, string property)
        {
            //DictionaryService service = new ViconDictionaryService();
            //var dic = service.GetChineseMeanInDict(word);
            var r = new SentenceParse().RemarkWord(sentence, word, word);

            Assert.AreEqual(r.DefaultMean.Property, property);
        }
        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();
        }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
        public void TestVerbIng(string sentence, string word, string originalWord, string decideWord, string property)
        {
            //DictionaryService service=new ViconDictionaryService();
            //var dic = service.GetChineseMeanInDict(word);
            //var dic2 = service.GetChineseMeanInDict(originalWord);

            var r = new SentenceParse().RemarkWord(sentence, word, originalWord);

            Assert.AreEqual(r.DefaultMean.Property, property);
            Assert.AreEqual(r.Word, decideWord);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 将一个句子中的生词进行注释
        /// </summary>
        /// <param name="line"></param>
        /// <param name="words"></param>
        /// <returns></returns>
        private string ReplaceSubtitleLineByVocabulary(string line, IDictionary <string, SubtitleWord> words)
        {
            StringBuilder sb = new StringBuilder();

            foreach (string s in SentenceParse.SplitSentence(line))
            {
                if (s.Length == 1)
                {
                    sb.Append(s);
                }
                else
                {
                    var          word         = s.ToLower();
                    string       mean         = "";
                    SubtitleWord wordWithMean = null;
                    if (words.ContainsKey(s))//这个词需要注释
                    {
                        wordWithMean = words[s];
                    }
                    else if (words.ContainsKey(word))
                    {
                        wordWithMean = words[word];
                    }
                    mean = wordWithMean?.SelectMean;
                    if (!String.IsNullOrEmpty(mean))
                    {
                        if (Global.ShortMean)
                        {
                            var meanarray = mean.Split(new char[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries);
                            mean = meanarray[0];
                            mean = mean.Substring(mean.IndexOf(' ') + 1);
                        }
                        var formatted = string.Format("{0}({1})", s, mean.Trim());
                        if (wordWithMean.IsStar)
                        {
                            //标星的单词,需要突出显示
                            formatted = String.Format("<font color='{0}'>{1}</font>", ColorTranslator.ToHtml(meanColor), formatted);
                        }
                        sb.Append(formatted);
                    }
                    else
                    {
                        sb.Append(s);
                    }
                }
            }
            return(sb.ToString());

            //var array = SentenceParse.SplitSentence2Words(line);
            //foreach (string oword in array)
            //{
            //    var word = oword.ToLower();

            //    //var w = englishWordService.GetOriginalWord(word);
            //    //var mean = words.ContainsKey(w) ? words[w].SelectMean : "";
            //    //if (!string.IsNullOrEmpty(mean))
            //    //{
            //    //    if(shortMean)
            //    //    {
            //    //        var meanarray = mean.Split(new char[]{';',','},StringSplitOptions.RemoveEmptyEntries);
            //    //        mean = meanarray[0];
            //    //    }
            //    //    line = ReplaceNewWord(line, word, mean);
            //    //}
            //}
            //return line;
        }
Exemplo n.º 8
0
        private void btnRemark_Click(object sender, EventArgs e)
        {
            if (subtitle == null || subtitle.Bodies.Count == 0)
            {
                MessageBox.Show("请先点击“载入字幕”按钮打开字幕文件");
                return;
            }

            Splash.Show("解析字幕中...");

            sentenceParse = new SentenceParse();
            var subtitleWords = PickNewWords(subtitle.Bodies.Values);
            if (subtitleWords.Count > 0)
            {
                NewWordConfirmForm form = new NewWordConfirmForm();
                form.DataSource = subtitleWords.Values.ToList();
                form.SubtitleFileName = Path.GetFileName(txbSubtitleFilePath.Text);
                form.OnClickOkButton += RemarkSubtitle;
                form.Show();
                form.Activate();
                //if (form.ShowDialog() == DialogResult.OK)
                //{

                //  form.SelectedNewWords
                //}
            }
            Splash.Close();
        }