public static List <NR> ViterbiCompute(List <TagFreqItem <NR> > tags) => Viterbi.Compute(tags, ChsPersonNameDict.transformMatrixDictionary);
Ejemplo n.º 2
0
        public override List <Term> SegSentence(char[] sentence)
        {
            var list = new List <Term>();

            if (sentence.Length == 0)
            {
                return(list);
            }

            var convertedChars = CharTable.Convert(sentence);
            var table          = new Table();

            table.v = AtomSeg2Table(convertedChars);
            _crfModel.Tag(table);
            int offset = 0;

            for (int i = 0; i < table.Size; offset += table.v[i][1].Length, i++)
            {
                var line = table.v[i];
                switch (line[2][0])
                {
                case 'B':
                    int begin = offset;
                    while (table.v[i][2][0] != 'E')             // 寻找结束标签'E'
                    {
                        offset += table.v[i][1].Length;
                        i++;
                        if (i == table.Size)
                        {
                            break;                          // 达到最后一个字符
                        }
                    }
                    // 退出while循环
                    if (i == table.Size)            // 肯定是由while loop的break退出的,offset已经包含了最后一格词的长度
                    {
                        list.Add(new Term(new string(sentence, begin, offset - begin), Nature.none));
                    }
                    else                            // 由while loop正常退出,当前词标注为'E',offset尚未包含这个词的长度
                    {
                        list.Add(new Term(new string(sentence, begin, offset - begin + table.v[i][1].Length), Nature.none));
                    }

                    break;

                default:            // 理论来说,只可能是标注为'S',所以单独成词
                    list.Add(new Term(new string(sentence, offset, table.v[i][1].Length), Nature.none));
                    break;
                }
            }

            if (config.natureTagging)
            {
                var vertices = ToVertexList(list, true);
                Viterbi.Compute(vertices, CoreDictTransfromMatrixDictionary.transformMatrixDictionary);
                for (int i = 0; i < list.Count; i++)
                {
                    var term = list[i];
                    if (term.nature == Nature.none)
                    {
                        term.nature = vertices[i + 1].GuessNature();            // vertices[i+1] -> 附加了辅助起始节点
                    }
                }
            }
            if (config.useCustomDict)
            {
                var vertices = ToVertexList(list, false);       //? 会不会覆盖上面的词性标注值
                CombineByCustomDict(vertices);
                list = ToTermList(vertices, config.offset);
            }
            return(list);
        }
Ejemplo n.º 3
0
 public static List <NS> ViterbiExCompute(List <TagFreqItem <NS> > roleTagList) =>
 Viterbi.Compute(roleTagList, PlaceDictionary.trans_tr_dict);
 /// <summary>
 /// 词性标注
 /// </summary>
 /// <param name="list"></param>
 public static void SpeechTaggint(List <Vertex> list) => Viterbi.Compute(list, CoreDictTransfromMatrixDictionary.transformMatrixDictionary);
Ejemplo n.º 5
0
 /// <summary>
 /// 维特比算法求解最优标签
 /// </summary>
 /// <param name="roleTagList"></param>
 /// <returns></returns>
 public static List <NT> ViterbiExCompute(List <TagFreqItem <NT> > roleTagList) => Viterbi.Compute(roleTagList, OrgDictionary.transformMatrixDictionary);