Esempio n. 1
0
        public SegDecoderTagger CreateTagger(int nbest, int this_crf_max_word_num = Utils.DEFAULT_CRF_MAX_WORD_NUM)
        {
            if (modelReader == null)
            {
                return null;
            }
            var tagger = new SegDecoderTagger(nbest, this_crf_max_word_num);
            tagger.init_by_model(modelReader);

            return tagger;
        }
Esempio n. 2
0
        public SegDecoderTagger CreateTagger(int nbest)
        {
            if (modelReader == null)
            {
                return(null);
            }
            SegDecoderTagger tagger = new SegDecoderTagger(nbest);

            tagger.init_by_model(modelReader);

            return(tagger);
        }
Esempio n. 3
0
        public SegDecoderTagger CreateTagger(int nbest, int this_crf_max_word_num = Utils.DEFAULT_CRF_MAX_WORD_NUM)
        {
            if (modelReader == null)
            {
                return(null);
            }
            SegDecoderTagger tagger = new SegDecoderTagger(nbest, this_crf_max_word_num);

            tagger.init_by_model(modelReader);

            return(tagger);
        }
Esempio n. 4
0
        //Segment given text
        public int Segment(crf_seg_out[] pout,         //segment result
                           SegDecoderTagger tagger,    //Tagger per thread
                           List <List <string> > inbuf //feature set for segment
                           )
        {
            int ret = 0;

            if (inbuf.Count == 0)
            {
                //Empty input string
                return(Utils.ERROR_SUCCESS);
            }

            ret = tagger.reset();
            if (ret < 0)
            {
                return(ret);
            }

            ret = tagger.add(inbuf);
            if (ret < 0)
            {
                return(ret);
            }

            //parse
            ret = tagger.parse();
            if (ret < 0)
            {
                return(ret);
            }

            //wrap result
            ret = tagger.output(pout);
            if (ret < 0)
            {
                return(ret);
            }

            return(Utils.ERROR_SUCCESS);
        }
Esempio n. 5
0
        //Segment given text
        public int Segment(crf_seg_out[] pout, //segment result
            SegDecoderTagger tagger, //Tagger per thread
            List<List<string>> inbuf //feature set for segment
            )
        {
            var ret = 0;
            if (inbuf.Count == 0)
            {
                //Empty input string
                return Utils.ERROR_SUCCESS;
            }

            ret = tagger.reset();
            if (ret < 0)
            {
                return ret;
            }

            ret = tagger.add(inbuf);
            if (ret < 0)
            {
                return ret;
            }

            //parse
            ret = tagger.parse();
            if (ret < 0)
            {
                return ret;
            }

            //wrap result
            ret = tagger.output(pout);
            if (ret < 0)
            {
                return ret;
            }

            return Utils.ERROR_SUCCESS;
        }
Esempio n. 6
0
        //Output raw result with probability
        private void OutputRawResultToFile(List<List<string>> inbuf, crf_term_out[] crf_out, SegDecoderTagger tagger, StreamWriter sw)
        {
            for (var k = 0; k < crf_out.Length; k++)
            {
                if (crf_out[k] == null)
                {
                    //No more result
                    break;
                }

                var sb = new StringBuilder();

                var crf_seg_out = crf_out[k];
                //Show the entire sequence probability
                //For each token
                for (var i = 0; i < inbuf.Count; i++)
                {
                    //Show all features
                    for (var j = 0; j < inbuf[i].Count; j++)
                    {
                        sb.Append(inbuf[i][j]);
                        sb.Append("\t");
                    }

                    //Show the best result and its probability
                    sb.Append(crf_seg_out.result_[i]);

                    if (tagger.vlevel_ > 1)
                    {
                        sb.Append("\t");
                        sb.Append(crf_seg_out.weight_[i]);

                        //Show the probability of all tags
                        sb.Append("\t");
                        for (var j = 0; j < tagger.ysize_; j++)
                        {
                            sb.Append(tagger.yname(j));
                            sb.Append("/");
                            sb.Append(tagger.prob(i, j));

                            if (j < tagger.ysize_ - 1)
                            {
                                sb.Append("\t");
                            }
                        }
                    }
                    sb.AppendLine();
                }
                if (tagger.vlevel_ > 0)
                {
                    sw.WriteLine("#{0}", crf_seg_out.prob);
                }
                sw.WriteLine(sb.ToString().Trim());
                sw.WriteLine();
            }
        }
Esempio n. 7
0
        //Output raw result with probability
        private void OutputRawResultToFile(List <List <string> > inbuf, crf_term_out[] crf_out, SegDecoderTagger tagger, StreamWriter sw)
        {
            foreach (crf_term_out crf_seg_out in crf_out)
            {
                if (crf_seg_out == null)
                {
                    //No more result
                    break;
                }

                var sb = new StringBuilder();

                //Show the entire sequence probability
                //For each token
                for (var i = 0; i < inbuf.Count; i++)
                {
                    //Show all features
                    for (var j = 0; j < inbuf[i].Count; j++)
                    {
                        sb.Append(inbuf[i][j]);
                        sb.Append("\t");
                    }

                    //Show the best result and its probability
                    sb.Append(crf_seg_out.result_[i]);

                    if (tagger.vlevel_ > 1)
                    {
                        sb.Append("\t");
                        sb.Append(crf_seg_out.weight_[i]);

                        //Show the probability of all tags
                        sb.Append("\t");
                        for (var j = 0; j < tagger.ysize_; j++)
                        {
                            sb.Append(tagger.yname(j));
                            sb.Append("/");
                            sb.Append(tagger.prob(i, j));

                            if (j < tagger.ysize_ - 1)
                            {
                                sb.Append("\t");
                            }
                        }
                    }
                    sb.AppendLine();
                }
                if (tagger.vlevel_ > 0)
                {
                    sw.WriteLine("#{0}", crf_seg_out.prob);
                }
                sw.WriteLine(sb.ToString().Trim());
                sw.WriteLine();
            }
        }