Пример #1
0
        /// <summary>
        /// 情感分析
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public RES SentimentAnalysis(string input)
        {
            try
            {
                Credential cred = new Credential
                {
                    SecretId  = secretId,
                    SecretKey = secretKey
                };

                ClientProfile clientProfile = new ClientProfile();
                HttpProfile   httpProfile   = new HttpProfile();
                httpProfile.Endpoint      = ("nlp.ap-shanghai.tencentcloudapi.com");
                clientProfile.HttpProfile = httpProfile;

                NlpClient client             = new NlpClient(cred, "ap-guangzhou", clientProfile);
                SentimentAnalysisRequest req = new SentimentAnalysisRequest();
                string strParams             = JSON.ToJson(new { Text = input });
                req = SentimentAnalysisRequest.FromJsonString <SentimentAnalysisRequest>(strParams);
                SentimentAnalysisResponse resp = client.SentimentAnalysis(req).
                                                 ConfigureAwait(false).GetAwaiter().GetResult();
                return(RES.OK(resp));
            }
            catch (Exception ex)
            {
                return(RES.FAIL(ex.Message));
            }
        }
Пример #2
0
        private void search_button_Click(object sender, EventArgs e)
        //搜索功能
        {
            //更改界面状态
            file_slide.Visible     = false;
            panelResult.Visible    = true;
            map_webbrowser.Visible = false;
            treeView1.Nodes.Clear();

            //进度显示
            textBoxHint.Visible = true;
            textBoxHint.Text    = "加载中...";
            textBoxHint.Refresh();

            //nlp分析器创建
            ClientProfile clientProfile = new ClientProfile();
            HttpProfile   httpProfile   = new HttpProfile();

            httpProfile.Endpoint      = ("nlp.tencentcloudapi.com");
            clientProfile.HttpProfile = httpProfile;
            NlpClient            client = new NlpClient(cred, "ap-guangzhou", clientProfile);
            SimilarWordsRequest  req;
            SimilarWordsResponse resp;

            string[] seperator = { " ", ",", ";" };
            string[] keywords  = bunifuMaterialTextbox1.Text.Split(seperator, 15, StringSplitOptions.RemoveEmptyEntries);
            string   regexp    = "";

            for (int i = 0; i < keywords.Length; i++)
            {
                try
                {
                    textBoxHint.Text = String.Format("检索第{0}个关键词,共{1}个", i + 1, keywords.Length);
                    textBoxHint.Refresh();
                    req = new SimilarWordsRequest();
                    string strParams = "{\"Text\":\"" + keywords[i] + "\",\"WordNumber\":20}";
                    req  = SimilarWordsRequest.FromJsonString <SimilarWordsRequest>(strParams);
                    resp = client.SimilarWordsSync(req);
                    if (i > 0)
                    {
                        regexp += "|";
                    }
                    regexp += keywords[i] + "|" + string.Join("|", resp.SimilarWords);
                }
                catch (Exception error)
                {
                    MessageBox.Show(error.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            string query = "select poiid, title, public_grading from public_grading " +
                           "where poiid in " +
                           "(SELECT poiid FROM poi.pois_features where keywords regexp '" +
                           regexp +
                           "') order by public_grading desc";

            textBoxHint.Text = "加载查询中...";
            textBoxHint.Refresh();
            SelectinGeneral(query);
            textBoxHint.Text = String.Format("查询得到{0}个地点", progressBar1.Maximum);
            textBoxHint.Refresh();
        }