internal WordAnalyResult SentenceAnaly() { if (ConfigBase.Default.IsTraceStack) { LogService.AnyLog("Stack", new StackTrace().GetFrame(0).GetMethod().ToString()); } WordAnalyResult result = new WordAnalyResult(); stops.Clear(); stops.Add(0);//开始值 //计算停止处 for (var fi = 0; fi < Raw.Length; fi++) { //句断符号停止 if (SentenceStopChars.Contains(Raw[fi])) { if (Raw[fi] != '.' || Raw[fi] == '.' && (fi == Raw.Length - 1 || Raw[fi++] == ' ')) { stops.Add(fi); } } } stops.Add(Raw.Length);//结束值 //截句 for (var fi = 1; fi < stops.Count; fi++) { var spi = stops[fi - 1]; if (spi > 0) { var splitword = Raw[spi]; //words.Add(splitword.ToString()); spi++; } var epi = stops[fi]; var sch = '\x0'; if (epi < Raw.Length) { sch = Raw[epi]; //epi++;//包含符号//注释后不包含符号 } var slen = epi - spi; if (slen < 1) { break; } var span = Raw.Slice(spi, slen); //$"P>{span.ToString()}".WriteInfoLine(); var words = new LinyeeNLWordAnalyzer(span, Enc, WordStopChars).WordAnaly(); var res = new Sentence(words, sch); sentences.Add(res);; } // return(result.SetData(sentences).SetOk()); }
internal WordAnalyResult ParagraphAnaly() { if (ConfigBase.Default.IsTraceStack) { LogService.AnyLog("Stack", new StackTrace().GetFrame(0).GetMethod().ToString()); } WordAnalyResult result = new WordAnalyResult(); stops.Clear(); stops.Add(0);//开始值 //计算停止处 for (var fi = 0; fi < Raw.Length; fi++) { //段落符号停止 if (ParagraphStopChars.Contains(Raw[fi])) { stops.Add(fi); } } stops.Add(Raw.Length);//结束值 //截段 for (var fi = 1; fi < stops.Count; fi++) { var spi = stops[fi - 1]; if (spi > 0) { var splitword = Raw[spi]; //words.Add(splitword.ToString()); spi++; } var epi = stops[fi]; //if (epi >= Raw.Length && paragraphs.Count > 0) //{ // break;//退出 //} //else if(epi< Raw.Length) //{ // epi++; //} var slen = epi - spi; if (slen < 1) { break; } var span = Raw.Slice(spi, slen); paragraphs.Add(new Paragraph(new LinyeeNLSentenceAnalyzer(span, Enc, SentenceStopChars, WordStopChars).SentenceAnaly())); } // return(result.SetData(paragraphs).SetOk()); }
internal WordAnalyResult <List <WordInfoOnce> > WordAnaly() { if (ConfigBase.Default.IsTraceStack) { LogService.AnyLog("Stack", new StackTrace().GetFrame(0).GetMethod().ToString()); } WordAnalyResult <List <WordInfoOnce> > result = new WordAnalyResult <List <WordInfoOnce> >(); var winfos = WordDict.WordAnaly(Raw, 0); words.AddRange(winfos); // return(result.SetData(words).SetOk()); }
public WordAnalyResult AddNew(string key, WordInfoOnce value) { WordAnalyResult result = new WordAnalyResult(); if (ContainsKey(key)) { return(result.SetFail("已经存在"));//已有 } else { base.Add(key, value); savetimes++; return(result.SetOk()); } }
internal WordAnalyResult <List <string> > WordAnaly() { if (ConfigBase.Default.IsTraceStack) { LogService.AnyLog("Stack", new StackTrace().GetFrame(0).GetMethod().ToString()); } WordAnalyResult <List <string> > result = new WordAnalyResult <List <string> >(); #region 标点分词 stops.Clear(); stops.Add(0);//开始值 //计算停止处 for (var fi = 0; fi < Raw.Length; fi++) { //标点符号停止 if (StopChars.Contains(Raw[fi])) { stops.Add(fi); } } stops.Add(Raw.Length);//结束值 //截词 for (var fi = 1; fi < stops.Count; fi++) { var spi = stops[fi - 1]; if (spi > 0) { var splitword = Raw[spi]; words.Add(splitword.ToString()); spi++; } var epi = stops[fi]; //if (epi >= Raw.Length && words.Count>0) //{ // break;//退出 //} var wlen = epi - spi; if (wlen < 1) { break; } var word = Raw.Slice(spi, wlen); var wordstr = word.ToString(); //词中是否含有中文 if (wordstr.ContainChinese()) { try { var winfos = new LinyeeNLZHWordAnalyzer(word, Enc, LinyeeWrodDict.Default).WordAnaly(); if (winfos.IsOK) { words.AddRange(winfos.Data.Select(p => p.w)); } } catch (Exception ex) { ex.ToString().WriteErrorLine(); } } else { words.Add(wordstr); var info = new WordInfoOnce(wordstr); } } #endregion // return(result.SetData(words).SetOk()); }