示例#1
0
        public void calcCost(CRFSharp.Path p)
        {
            double c = 0;

            long[] f = feature_cache_[p.fid];
            for (int i = 0; i < f.Length && f[i] != -1; i++)
            {
                c += featureIndex.GetAlpha((int)(f[i] + p.lnode.y * ysize_ + p.rnode.y));
            }
            p.cost = featureIndex.cost_factor_ * c;
        }
示例#2
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 = Utils.heap_init((int)(crf_max_word_num * ysize_ * ysize_));
            }

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

            node_   = new Node[Utils.DEFAULT_CRF_MAX_WORD_NUM, ysize_];
            result_ = new short[Utils.DEFAULT_CRF_MAX_WORD_NUM];

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

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

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

            return(Utils.ERROR_SUCCESS);
        }
示例#3
0
        public void calcCost(CRFSharp.Path p)
        {
            double c = 0;

            long[] f = feature_cache_[p.fid];
            for (int i = 0; i < f.Length; ++i)
            {
                int fCurrent = (int)f[i];
                if (fCurrent == -1)
                {
                    break;
                }
                c += featureIndex.GetAlpha((fCurrent + p.lnode.y * ysize_ + p.rnode.y));
            }

            p.cost = featureIndex.cost_factor_ * c;
        }
示例#4
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 = Utils.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 CRFSharp.Path();
                        p.add(node_[cur - 1, j], node_[cur, i]);
                    }
                }
            }

            return Utils.ERROR_SUCCESS;
        }