Ejemplo n.º 1
0
        private void button8_Click(object sender, EventArgs e)
        {
            //词意相似度
            // 调用词义相似度,可能会抛出网络等异常,请使用try/catch捕获
            JObject obj = client.WordSimEmbedding(textBox5.Text, textBox6.Text);

            textBox7.Text = Convert.ToString(obj["score"]);
            Console.WriteLine(obj);
        }
        protected override void Execute(CodeActivityContext context)
        {
            string word1  = Word1.Get(context);
            string word2  = Word2.Get(context);
            string apiKey = APIKey.Get(context);
            string seKey  = SecretKey.Get(context);

            try
            {
                var client = new Baidu.Aip.Nlp.Nlp(apiKey, seKey);
                //修改超时时间
                client.Timeout = 60000;
                //带参数调用词义相似度
                string result = client.WordSimEmbedding(word1, word2).ToString();
                Result.Set(context, result);
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", e.Message);
            }
        }