public static List <string> ReduceWithReplacment(string src) { Thesaurus t = getThesaurusInstance(); List <WordResult[]> result = Split(src); List <string> ls = new List <string>(); WordResult[] twr; string s; int k; bool IsNFound; for (int i = 0; i < result.Count; i++) { IsNFound = false; for (int j = 1; j < result[i].Length - 1; j++) { s = Utility.GetPOSString(result[i][j].nPOS, nPosLevel.LevelOne); if (s == "n") { IsNFound = true; continue; } if (IsNFound) { if (s == "a") { twr = result[i]; //去掉句首的连词 if (Utility.GetPOSString(twr[1].nPOS, nPosLevel.LevelOne) == "c") { twr[1].sWord = ""; } ls.Add(t.ReplaceByProbility(PrintResultStringOnly(twr))); break; } else if (s == "d" || s == "n") { continue; } else { IsNFound = false; continue; } } } } return(ls); }
private static Thesaurus getThesaurusInstance() { if (ms_thesaurus == null) { try { ms_thesaurus = new Thesaurus(System.IO.Path.Combine(Environment.CurrentDirectory, "SegmentDict") + System.IO.Path.DirectorySeparatorChar + "tyc.mdb"); } catch { System.Windows.Forms.MessageBox.Show("同义词库初始化失败!", "错误", System.Windows.Forms.MessageBoxButtons.OK); log.Debug("同义词库初始化失败!"); } } return(ms_thesaurus); }
private static Thesaurus getThesaurusInstance() { if (ms_thesaurus == null) { try { ms_thesaurus = new Thesaurus(System.IO.Path.Combine(Environment.CurrentDirectory, "SegmentDict") + System.IO.Path.DirectorySeparatorChar + "tyc.mdb"); } catch { System.Windows.Forms.MessageBox.Show("同义词库初始化失败!","错误", System.Windows.Forms.MessageBoxButtons.OK); log.Debug("同义词库初始化失败!"); } } return ms_thesaurus; }
private void 同义词替换测试ToolStripMenuItem_Click(object sender, EventArgs e) { Thesaurus ts = new Thesaurus(System.IO.Path.Combine(Environment.CurrentDirectory, "SegmentDict") + System.IO.Path.DirectorySeparatorChar + "tyc.mdb"); string s = @"味道很不错,很好吃,很开心,一点也不贵,很便宜,人很多,很挤,空间很狭窄"; string d = ts.Replace(s); MessageBox.Show(s + Environment.NewLine + d); }