Exemple #1
0
        /// <summary>
        /// Check the sentiment
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnSentiment_Click(object sender, EventArgs e)
        {
            if (!PerformValidation())
            {
                return;
            }

            // Prepare json payload of the documents
            RequestDocument doc = new RequestDocument();

            doc.language = "en";
            doc.id       = "1001";
            // read the text from the file we specified
            doc.text = System.IO.File.ReadAllText(FileName);

            List <RequestDocument> lstDocs = new List <RequestDocument>();

            lstDocs.Add(doc);
            RequestRootObject ro = new RequestRootObject();

            ro.documents = lstDocs;

            // text to be analysed
            StringContent strPayload = new StringContent(JsonConvert.SerializeObject(ro), Encoding.UTF8, "application/json");


            // Detect sentiment:
            var uri      = "text/analytics/v2.0/sentiment";
            var response = await CallEndpoint(httpClientObj, uri, await strPayload.ReadAsByteArrayAsync());

            ResponseRootObject responseAsJson = JsonConvert.DeserializeObject <ResponseRootObject>(response);

            rtbOutput.Text = string.Empty;
            rtbOutput.AppendText("Detected sentiment in 0-1 range,where 0 is negative and 1 is positive is:" + responseAsJson.documents[0].score);
        }
Exemple #2
0
        private async void btnLanguageDetection_Click(object sender, EventArgs e)
        {
            if (!PerformValidation())
            {
                return;
            }

            // Prepare json payload of the documents
            RequestDocument doc = new RequestDocument();

            doc.language = "en";
            doc.id       = "1001";
            // read the text from the file we specified
            doc.text = System.IO.File.ReadAllText(FileName);

            List <RequestDocument> lstDocs = new List <RequestDocument>();

            lstDocs.Add(doc);
            RequestRootObject ro = new RequestRootObject();

            ro.documents = lstDocs;

            // text to be analysed
            StringContent strPayload = new StringContent(JsonConvert.SerializeObject(ro), Encoding.UTF8, "application/json");

            // Detect language:
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            queryString["numberOfLanguagesToDetect"] = NumLanguages.ToString(CultureInfo.InvariantCulture);
            var uri      = "text/analytics/v2.0/languages?" + queryString;
            var response = await CallEndpoint(httpClientObj, uri, await strPayload.ReadAsByteArrayAsync());

            ResponseRootObject responseAsJson = JsonConvert.DeserializeObject <ResponseRootObject>(response);

            rtbOutput.Text = string.Empty;

            rtbOutput.AppendText("Key phrases of the document are:\n" + String.Join("\n", responseAsJson.documents[0].keyPhrases.Select(p => p.ToString()).ToArray()));
        }