示例#1
0
        //使用模型初始化tag,必须先使用该函数初始化才能使用add和parse
        //正常返回为0, 错误返回<0
        public int init_by_model(ModelReader model_p)
        {
            featureIndex = model_p;
            ysize_       = (short)model_p.ysize();

            if (nbest_ > 1)
            {
                //Only allocate heap when nbest is more than 1
                heap_queue = BaseUtils.heap_init((int)(crf_max_word_num * ysize_ * ysize_));
            }

            //Initialize feature set cache according unigram and bigram templates
            InitializeFeatureCache();

            node_   = new Node[crf_max_word_num, ysize_];
            result_ = new short[crf_max_word_num];

            //Create node and path cache
            for (short cur = 0; cur < crf_max_word_num; cur++)
            {
                for (short i = 0; i < ysize_; i++)
                {
                    var n = new Node();
                    node_[cur, i] = n;

                    n.lpathList = new List <Path>();
                    n.rpathList = new List <Path>();
                    n.x         = cur;
                    n.y         = i;
                }
            }

            for (var cur = 1; cur < crf_max_word_num; cur++)
            {
                for (var j = 0; j < ysize_; ++j)
                {
                    for (var i = 0; i < ysize_; ++i)
                    {
                        var p = new Path();
                        p.add(node_[cur - 1, j], node_[cur, i]);
                    }
                }
            }

            return(BaseUtils.RETURN_SUCCESS);
        }