protected static void GenerateWord(List <Vertex> vertices, WordNet wordNet)
        {
            FixResultByRule(vertices);

            wordNet.AddAll(vertices);
        }
예제 #2
0
        /// <summary>
        /// 将给定句子分词
        /// </summary>
        /// <param name="sentence"></param>
        /// <returns></returns>
        public override List <Term> SegSentence(char[] sentence)
        {
            var wordNetAll = new WordNet(sentence);

            //-------------------- 生成一元词网 --------------------------
            GenerateWordNet(wordNetAll);

            // 使用Viterbi分词
            var list = Viterbi(wordNetAll);

            if (config.useCustomDict)   // 需要使用自定义词典
            {
                if (config.indexMode)   // 开启索引模式
                {
                    CombineByCustomDict(list, wordNetAll);
                }
                else
                {
                    CombineByCustomDict(list);
                }
            }

            if (config.numQuantRecognize)               // 数量词识别
            {
                CombineNumQuant(list, wordNetAll, config);
            }

            if (config.nameEntityRecognize)                       // 命名实体识别
            {
                var wordNetOptimum = new WordNet(sentence, list); //
                var preSize        = wordNetOptimum.Size;

                if (config.chsNameRecognize)         // 中文人名识别
                {
                    ChsNameRecognition.Recognition(list, wordNetOptimum, wordNetAll);
                }

                if (config.translatedNameRecognize)
                {
                    TranslatedPersonRecognition.Recognition(list, wordNetOptimum, wordNetAll);
                }

                if (config.jpNameRecognize)
                {
                }
                if (config.placeRecognize)
                {
                }

                if (config.orgRecognize)
                {
                    list = Viterbi(wordNetOptimum);
                    wordNetOptimum.Clear();
                    wordNetOptimum.AddAll(list);
                    preSize = wordNetOptimum.Size;
                    OrgRecognition.Recognition(list, wordNetOptimum, wordNetAll);
                }
                if (wordNetOptimum.Size != preSize)
                {
                    list = Viterbi(wordNetOptimum);
                }
            }

            return(Convert(list, config.offset));
        }