/// <summary> /// 找到字幕中的生词,先进行分词,然后取每个单词的原型,然后看每个单词是否认识,认识则跳过,不认识则注释。 /// </summary> /// <param name="subtitles"></param> /// <returns></returns> private IDictionary <string, SubtitleWord> PickNewWords(ICollection <SubtitleLine> subtitles) { Dictionary <string, SubtitleWord> result = new Dictionary <string, SubtitleWord>(); var texts = subtitles.Select(s => s.EnglishText).ToList(); foreach (var line in texts) { var lineResult = sentenceParse.Pickup(line); foreach (KeyValuePair <string, string> keyValuePair in lineResult) { if (result.ContainsKey(keyValuePair.Key)) { continue; } string original = keyValuePair.Key; string word = keyValuePair.Value; var mean = sentenceParse.RemarkWord(line, word, original); if (mean != null) { var wd = new SubtitleWord() { Word = mean.Word, WordInSubitle = word, Means = mean.Means, SubtitleSentence = line, SelectMean = mean.DefaultMean == null ? mean.Means[0].ToString() : mean.DefaultMean.ToString() }; result.Add(original, wd); } } } return(result); }
/// <summary> /// 找到字幕中的生词,先进行分词,然后取每个单词的原型,然后看每个单词是否认识,认识则跳过,不认识则注释。 /// </summary> /// <param name="subtitles"></param> /// <returns></returns> private IDictionary <string, SubtitleWord> PickNewWords(ICollection <SubtitleLine> subtitles) { Dictionary <string, SubtitleWord> result = new Dictionary <string, SubtitleWord>(); var unknownWords = DbOperator.Instance.GetAllUserUnKnownVocabulary().ToDictionary(s => s.Word, s => s.IsStar); var texts = subtitles.Select(s => s.EnglishText).ToList(); foreach (var line in texts) { var lineResult = sentenceParse.Pickup(line); foreach (KeyValuePair <string, string> keyValuePair in lineResult) { string original = keyValuePair.Key; //if (knownWords.Contains(original)) continue; string word = keyValuePair.Value; //if(knownWords.Contains(word)) continue; if (result.ContainsKey(original)) { result[original].ShowCount++; if (!result[original].WordInSubtitle.Contains(word)) { result[original].WordInSubtitle.Add(word); } continue; } var mean = sentenceParse.RemarkWord(line, word, original); if (mean != null) { var wd = new SubtitleWord() { Word = mean.Word, ShowCount = 1, WordInSubtitle = new List <string>() { word }, Means = mean.Means, SubtitleSentence = line, SelectMean = mean.DefaultMean == null ? mean.Means[0].ToString() : mean.DefaultMean.ToString() }; if (unknownWords.ContainsKey(mean.Word)) { wd.IsStar = unknownWords[mean.Word]; } result.Add(original, wd); } } } return(result); }
/// <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; }
/// <summary> /// 找到字幕中的生词,先进行分词,然后取每个单词的原型,然后看每个单词是否认识,认识则跳过,不认识则注释。 /// </summary> /// <param name="subtitles"></param> /// <returns></returns> private IDictionary<string, SubtitleWord> PickNewWords(ICollection<SubtitleLine> subtitles) { Dictionary<string, SubtitleWord> result = new Dictionary<string, SubtitleWord>(); var unknownWords = DbOperator.Instance.GetAllUserUnKnownVocabulary().ToDictionary(s=>s.Word,s=>s.IsStar); var texts = subtitles.Select(s => s.EnglishText).ToList(); foreach (var line in texts) { var lineResult = sentenceParse.Pickup(line); foreach (KeyValuePair<string, string> keyValuePair in lineResult) { string original = keyValuePair.Key; //if (knownWords.Contains(original)) continue; string word = keyValuePair.Value; //if(knownWords.Contains(word)) continue; if (result.ContainsKey(original)) { result[original].ShowCount++; if (!result[original].WordInSubtitle.Contains(word)) { result[original].WordInSubtitle.Add(word); } continue; } var mean = sentenceParse.RemarkWord(line, word, original); if (mean != null) { var wd = new SubtitleWord() { Word = mean.Word, ShowCount = 1, WordInSubtitle = new List<string>() {word}, Means = mean.Means, SubtitleSentence = line, SelectMean = mean.DefaultMean == null ? mean.Means[0].ToString() : mean.DefaultMean.ToString() }; if (unknownWords.ContainsKey(mean.Word)) { wd.IsStar = unknownWords[mean.Word]; } result.Add(original, wd); } } } return result; }