Esempio n. 1
0
 /// <summary>
 /// DNN语言模型
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btn_DnnlmCn_Click(object sender, EventArgs e)
 {
     if (CheckFormData())
     {
         var results = client.DnnlmCn(txtInPut.Text).ToObject <DnnlmCnResult>();
         Text = $"调用日志ID为:{results.LogId}";
         dataItems.DataSource = results.Items;
         MessageBox.Show(results.Ppl.ToString());
     }
 }
Esempio n. 2
0
        // DNN语言模型
        public static DnnlmCnSerialize DnnlmCnDemo(string text)
        {
            //床前明月光;
            client = new Nlp(API_KEY, SECRET_KEY);

            // 调用DNN语言模型,可能会抛出网络等异常,请使用try/catch捕获
            JObject result = client.DnnlmCn(text);
            //System.Diagnostics.Debug.WriteLine(result);

            DnnlmCnSerialize res = new DnnlmCnSerialize();

            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++)
            {
                DnnlmCn_Sub _item = new DnnlmCn_Sub();
                _item.word = res.items[i]["word"].ToString();
                _item.prob = double.Parse(res.items[i]["prob"].ToString());
            }
            res.ppl = double.Parse(result["ppl"].ToString());
            return(res);
        }