public static SentimentResponse GetSentimentResponse(List <NewsResult> newsResults)
        {
            var sentimentResponse = new SentimentResponse();
            var sentimentRequest  = new SentimentRequest();

            sentimentRequest.Documents = new List <Document>();
            foreach (var result in newsResults)
            {
                sentimentRequest.Documents.Add(new Document {
                    Id = result.Headline, Text = result.Summary
                });
            }

            var webClient = new WebClient();

            webClient.Headers.Add("Ocp-Apim-Subscription-Key", "a26df349753c400882fa9e068d0d74dd");
            webClient.Headers.Add(HttpRequestHeader.Accept, "application/json");
            webClient.Headers.Add(HttpRequestHeader.ContentType, "application/json");
            string requestJson = JsonConvert.SerializeObject(sentimentRequest);

            byte[] requestBytes = Encoding.UTF8.GetBytes(requestJson);
            byte[] response     = webClient.UploadData("https://eastus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment", requestBytes);
            string sentiments   = Encoding.UTF8.GetString(response);

            sentimentResponse = JsonConvert.DeserializeObject <SentimentResponse>(sentiments);
            return(sentimentResponse);
        }
Beispiel #2
0
        public static SentimentResponse GetSentimentResponse(List <NewsResult> newsResults)
        {
            var sentimentResponse = new SentimentResponse();
            var sentimentRequest  = new SentimentRequest();

            sentimentRequest.Documents = new List <Document>();

            foreach (var result in newsResults)
            {
                sentimentRequest.Documents.Add(new Document {
                    Id = result.Headline, Text = result.Summary
                });
            }

            var webClient = new WebClient();

            //webClient.Headers.Add("Ocp-Apim-Subscription-Key", "value");
            //webClient.Headers.Add("Ocp-Apim-Subscription-Key", "b8e29bbd1df24254a8595a8a2d4b7632");
            webClient.Headers.Add(HttpRequestHeader.Accept, "application/json");
            webClient.Headers.Add(HttpRequestHeader.ContentType, "application/json");

            string requestJson = JsonConvert.SerializeObject(sentimentRequest);

            byte[] requestBytes = Encoding.UTF8.GetBytes(requestJson);

            byte[] response = webClient.UploadData("https://westcentralus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment", requestBytes);
            //byte[] response = webClient.UploadData(string.Format("https://westcentralus.api.cognitive.microsoft.com/text/analytics/v2.0", requestBytes));
            string sentiments = Encoding.UTF8.GetString(response);

            sentimentResponse = JsonConvert.DeserializeObject <SentimentResponse>(sentiments);

            return(sentimentResponse);
        }
Beispiel #3
0
        public static SentimentResponse GetSentimentResponse(List <NewsResult> newsResults)
        {
            var sentimentResponse = new SentimentResponse();
            var sentimentRequest  = new SentimentRequest();

            sentimentRequest.Documents = new List <Document>();
            foreach (var result in newsResults)
            {
                sentimentRequest.Documents.Add(new Document {
                    Id = result.Headline, Text = result.Summary
                });
            }

            using (var webClient = new WebClient())
            {
                //string queryString = null;
                var uri = "https://australiaeast.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment";
                webClient.Headers.Add("Ocp-Apim-Subscription-Key", Constants.TextAnalyticAccessKey);
                webClient.Headers.Add(HttpRequestHeader.Accept, "application/json");
                webClient.Headers.Add(HttpRequestHeader.ContentType, "application/json");
                string requestJson = JsonConvert.SerializeObject(sentimentRequest);
                byte[] requestByte = Encoding.UTF8.GetBytes(requestJson);
                byte[] response    = webClient.UploadData(uri, requestByte);

                string sentiments = Encoding.UTF8.GetString(response);
                sentimentResponse = JsonConvert.DeserializeObject <SentimentResponse>(sentiments);
            }
            return(sentimentResponse);
        }
Beispiel #4
0
        public static SentimentResponse GetSentimentResponse(List <NewsResult> newsResults)
        {
            var sentimentResponse = new SentimentResponse();
            var sentimentRequest  = new SentimentRequest();

            sentimentRequest.Documents = new List <Document>();
            foreach (var result in newsResults)
            {
                sentimentRequest.Documents.Add(new Document {
                    IDisposable = result.Headline, TextReader = result.Summary
                })
            }

            string url       = "google.com";
            var    webClient = new WebClient();

            webClient.Headers.Add(uHttpRequestHeader.HttpRequestHeader.Accept, "application/json");
            byte[] searchResults = webClient.UploadData(string.Format(url, playerName));
        }
Beispiel #5
0
        public static SentimentResponse GetSentimentResponse(List <NewsResult> newsResults)
        {
            var sentimentResponse = new SentimentResponse();
            var sentimentRequest  = new SentimentRequest();

            sentimentRequest.Documents = new List <Document>();
            foreach (var result in newsResults)
            {
                sentimentRequest.Documents.Add(new Document {
                    Id = result.SentimentId, Text = result.Summary
                });
            }
            var webClient = new WebClient();

            webClient.Headers.Add("Ocp-Apim-Subscription-Key", "364c7692b83247139c69060b3e40d396");
            webClient.Headers.Add(HttpRequestHeader.ContentType, "application/json");
            string requestJson = JsonConvert.SerializeObject(sentimentRequest);

            byte[] requestBytes = Encoding.UTF8.GetBytes(requestJson);
            string endpoint     = "cyadehn-th-textanalytics.cognitiveservices.azure.com";

            byte[] response;
            try
            {
                response = webClient.UploadData(string.Format("https://{0}/text/analytics/v3.0/sentiment", endpoint), requestBytes);
                ITraceWriter traceWriter = new MemoryTraceWriter();
                string       sentiments  = Encoding.UTF8.GetString(response);
                sentimentResponse = JsonConvert.DeserializeObject <SentimentResponse>(sentiments, new JsonSerializerSettings {
                    TraceWriter = traceWriter
                });
                Console.Write(traceWriter);
            }
            catch (WebException ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(sentimentResponse);
        }