public void Calc() { //var @string = "支持和Razor视图引擎捆绑反编译器,增强导航,重新设计的设置管理,不同语言的新的代码检查功能"; var @string = "陈琛爱洪根祥"; var jiebaSegmenter = new JiebaSegmenter(); var tokens = jiebaSegmenter.Calc(@string, jiebaSegmenter.CreateDAG(@string)); }
public void TestCalc() { var s = "语言学家参加学术会议"; var seg = new JiebaSegmenter(); var dag = seg.GetDag(s); var route = seg.Calc(s, dag); foreach (var key in route.Keys.ToList().OrderBy(k => k)) { Console.Write("{0}: ", key); var pair = route[key]; Console.WriteLine("({0}, {1})", pair.Freq, pair.Key); } }
internal IEnumerable <Pair> CutDag(string sentence) { var dag = _segmenter.GetDag(sentence); var route = _segmenter.Calc(sentence, dag); var tokens = new List <Pair>(); var x = 0; var n = sentence.Length; var buf = string.Empty; while (x < n) { var y = route[x].Key + 1; var w = sentence.Substring(x, y - x); if (y - x == 1) { buf += w; } else { if (buf.Length > 0) { AddBufferToWordList(tokens, buf); buf = string.Empty; } //tokens.Add(new Pair(w, _wordTagTab.GetDefault(w, "x"))); tokens.Add(new Pair(w, _wordTagTab.SelectValueOrDefault(w, "x"))); } x = y; } if (buf.Length > 0) { AddBufferToWordList(tokens, buf); } return(tokens); }