Exemple #1
0
        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);
        }
Exemple #2
0
 public Segment(WordDictionary biDict, WordDictionary coreDict)
 {
     this.biDict   = biDict;
     this.coreDict = coreDict;
     rawNShortPath = new NShortPath();
     optNShortPath = new NShortPath();
 }
 public Segment(WordDictionary biDict, WordDictionary coreDict)
 {
    this.biDict = biDict;
    this.coreDict = coreDict;
    rawNShortPath = new NShortPath();
    optNShortPath = new NShortPath();
 }
Exemple #4
0
        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);
        }