public int BiOptimumSegment(int nResultCount, double dSmoothingPara) { WordResult[] tmpResult; WordLinkedArray linkedArray; //Generate the biword link net ColumnFirstDynamicArray <ChainContent> aBiwordsNet = BiGraphGenerate(m_graphOptimum, dSmoothingPara, biDict, coreDict); OnGenBiOptimumSegGraph(aBiwordsNet); NShortPath.Calculate(aBiwordsNet, nResultCount); List <int[]> spResult = NShortPath.GetNPaths(Predefine.MAX_SEGMENT_NUM); m_pWordSeg = new List <WordResult[]>(); segGraph = m_graphOptimum; m_graphOptimum = new RowFirstDynamicArray <ChainContent>(); for (int i = 0; i < spResult.Count; i++) { linkedArray = BiPath2LinkedArray(spResult[i], segGraph, atomSegment); tmpResult = GenerateWord(spResult[i], linkedArray, m_graphOptimum); if (tmpResult != null) { m_pWordSeg.Add(tmpResult); } } return(m_pWordSeg.Count); }
public Segment(WordDictionary biDict, WordDictionary coreDict) { this.biDict = biDict; this.coreDict = coreDict; rawNShortPath = new NShortPath(); optNShortPath = new NShortPath(); }
public int BiSegment(string sSentence, double smoothPara, int nKind) { WordResult[] tmpResult; WordLinkedArray linkedArray; if (biDict == null || coreDict == null) { throw new Exception("biDict 或 coreDict 尚未初始化!"); } //---原子分词 atomSegment = AtomSegment(sSentence); OnAtomSegment(atomSegment); //---检索词库,加入所有可能分词方案并存入链表结构 segGraph = GenerateWordNet(atomSegment, coreDict); OnGenSegGraph(segGraph); //---检索所有可能的两两组合 biGraphResult = BiGraphGenerate(segGraph, smoothPara, biDict, coreDict); OnGenBiSegGraph(biGraphResult); //--逆向匹配优化 biGraphResult = BackwardOptimize(biGraphResult); OnBackwardOptimize(biGraphResult); //---N 最短路径计算出多个分词方案 NShortPath.Calculate(biGraphResult, nKind); List <int[]> spResult = NShortPath.GetNPaths(Predefine.MAX_SEGMENT_NUM); OnNShortPath(spResult, segGraph); m_pWordSeg = new List <WordResult[]>(); m_graphOptimum = new RowFirstDynamicArray <ChainContent>(); for (int i = 0; i < spResult.Count; i++) { linkedArray = BiPath2LinkedArray(spResult[i], segGraph, atomSegment); tmpResult = GenerateWord(spResult[i], linkedArray, m_graphOptimum); if (tmpResult != null) { m_pWordSeg.Add(tmpResult); } } OnBeforeOptimize(m_pWordSeg); return(m_pWordSeg.Count); }