public static void CommentTag()
        {
            var nlp    = new Nlp("Api Key", "Secret Key");
            var result = nlp.CommentTag("个人觉得这车不错,外观漂亮年轻,动力和操控性都不错", 10);

            Console.Write(result);
        }
示例#2
0
        /// <summary>
        /// 评论观点抽取
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_CommentTag_Click(object sender, EventArgs e)
        {
            if (CheckFormData())
            {
                var options = new Dictionary <string, object> {
                    { "type", int.Parse(PartOfSpeech.商业) }
                };

                var results = client.CommentTag(txtInPut.Text, options).ToObject <CommentTagResult>();
                Text = $"调用日志ID为:{results.LogId}";
                dataItems.DataSource = results.Items;
                txtInPut2.Text       = Newtonsoft.Json.JsonConvert.SerializeObject(results);
            }
        }
示例#3
0
        // 评论观点抽取
        public static CommentTagSerialize CommentTagDemo(string text, Dictionary <string, object> options = null)
        {
            //"三星电脑电池不给力"

            client = new Nlp(API_KEY, SECRET_KEY);

            // 调用评论观点抽取,可能会抛出网络等异常,请使用try/catch捕获
            JObject result = null;

            try
            {
                //result = client.CommentTag(text); //不传option会报错
                //System.Diagnostics.Debug.WriteLine(result);

                // 如果有可选参数
                //var options = new Dictionary<string, object>{{"type", 13}};

                // 带参数调用评论观点抽取
                result = client.CommentTag(text, options);
            }
            catch
            {
                //System.Console.WriteLine("是否存在 ==>> " + (result != null));
                //System.Console.WriteLine("result子物体 ==>> " + result.Count);
            }

            CommentTagSerialize res = new CommentTagSerialize();

            res.items = (JArray)result["items"];
            //System.Console.WriteLine("res子物体");
            //System.Console.WriteLine("finally ==>> " + res.items.First.First);

            for (int i = 0; i < res.items.Count; i++)
            {
                CommentTag_Sub _item = new CommentTag_Sub();
                _item.prop      = res.items[i]["prop"].ToString();
                _item.adj       = res.items[i]["adj"].ToString();
                _item.sentiment = int.Parse(res.items[i]["sentiment"].ToString());
                _item.begin_pos = int.Parse(res.items[i]["begin_pos"].ToString());
                _item.end_pos   = int.Parse(res.items[i]["end_pos"].ToString());
                _item.abs       = res.items[i]["abstract"].ToString();
            }
            return(res);
        }