Exemple #1
0
        // 依存句法分析
        public static ResultSerialize DepParserDemo(string text)
        {
            client = new Nlp(API_KEY, SECRET_KEY);

            // 调用依存句法分析,可能会抛出网络等异常,请使用try/catch捕获
            JObject result = client.DepParser(text);
            //System.Diagnostics.Debug.WriteLine(result);

            ResultSerialize res = new ResultSerialize();

            res.log_id = result["log_id"].ToString();
            res.text   = result["text"].ToString();
            res.items  = (JArray)result["items"];
            for (int i = 0; i < res.items.Count; i++)
            {
                DepParserSerialize _gammar = new DepParserSerialize();
                //_gammar.id = res.items[i]["id"].ToString();
                _gammar.word   = res.items[i]["word"].ToString();
                _gammar.postag = res.items[i]["postag"].ToString();
                _gammar.head   = res.items[i]["head"].ToString();
                _gammar.deprel = res.items[i]["deprel"].ToString();
            }
            return(res);

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

            // 带参数调用依存句法分析
            result = client.DepParser(text, options);
        }
Exemple #2
0
        public static void DepParser()
        {
            var nlp     = new Nlp(AiKeySecret.ApiKey, AiKeySecret.SecretKey);
            var options = new Dictionary <string, object>()
            {
                { "mode", 1 }
            };
            var result = nlp.DepParser("今天天气不错", options);

            Console.Write(result);
        }
Exemple #3
0
 /// <summary>
 /// 依存语法
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Btn_DepParser_Click(object sender, EventArgs e)
 {
     if (CheckFormData())
     {
         var options = new Dictionary <string, object> {
             { "mode", 1 }
         };
         var results = client.DepParser(txtInPut.Text).ToObject <DepParserResult>();
         Text = $"调用日志ID为:{results.LogId}";
         dataItems.DataSource = results.Items;
     }
 }
Exemple #4
0
 /// <summary>
 /// 依存句法分析接口
 /// 依存句法分析接口可自动分析文本中的依存句法结构信息,利用句子中词与词之间的依存关系来表示词语的句法结构信息(如“主谓”、“动宾”、“定中”等结构关系),并用树状结构来表示整句的结构(如“主谓宾”、“定状补”等)。
 /// </summary>
 public static NLPDepParser DepParser(string data)
 {
     try
     {
         var options = new Dictionary <string, object>
         {
             { "mode", 1 }
         };
         var obj = nlp.DepParser(data, options);
         LogWritter.Write(LogType.Debug, obj.ToString(), "SentimentClassify");
         return(obj.ToObject <NLPDepParser>());
     }
     catch (Exception exp)
     {
     }
     return(null);
 }