/// <summary>
 /// The API returns a list of strings denoting the key talking points in the
 /// input text.
 /// We employ techniques from Microsoft Office's sophisticated
 /// Natural Language Processing toolkit.
 /// Currently, the following languages are supported: English,
 /// German, Spanish and Japanese.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='subscriptionKey'>
 /// subscription key in url
 /// </param>
 /// <param name='ocpApimSubscriptionKey'>
 /// subscription key in header
 /// </param>
 /// <param name='multiLanguageBatchInputV2'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async System.Threading.Tasks.Task<object> KeyPhrasesAsync(this IAzureMachineLearningTextAnalytics operations, string subscriptionKey = default(string), string ocpApimSubscriptionKey = default(string), MultiLanguageBatchInputV2 multiLanguageBatchInputV2 = default(MultiLanguageBatchInputV2), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
 {
     using (var _result = await operations.KeyPhrasesWithHttpMessagesAsync(subscriptionKey, ocpApimSubscriptionKey, multiLanguageBatchInputV2, null, cancellationToken).ConfigureAwait(false))
     {
         return _result.Body;
     }
 }
 /// <summary>
 /// The API returns a list of strings denoting the key talking points in the
 /// input text.
 /// We employ techniques from Microsoft Office's sophisticated
 /// Natural Language Processing toolkit.
 /// Currently, the following languages are supported: English,
 /// German, Spanish and Japanese.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='subscriptionKey'>
 /// subscription key in url
 /// </param>
 /// <param name='ocpApimSubscriptionKey'>
 /// subscription key in header
 /// </param>
 /// <param name='multiLanguageBatchInputV2'>
 /// </param>
 public static object KeyPhrases(this IAzureMachineLearningTextAnalytics operations, string subscriptionKey = default(string), string ocpApimSubscriptionKey = default(string), MultiLanguageBatchInputV2 multiLanguageBatchInputV2 = default(MultiLanguageBatchInputV2))
 {
     return System.Threading.Tasks.Task.Factory.StartNew(s => ((IAzureMachineLearningTextAnalytics)s).KeyPhrasesAsync(subscriptionKey, ocpApimSubscriptionKey, multiLanguageBatchInputV2), operations, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskCreationOptions.None, System.Threading.Tasks.TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// The API returns a numeric score between 0 and 1.
 /// Scores close to 1 indicate positive sentiment, while
 /// scores close to 0 indicate negative sentiment.
 /// Sentiment score is generated using classification
 /// techniques.
 /// The input features to the classifier include n-grams,
 /// features generated from part-of-speech tags, and word embeddings.
 /// Currently, the following languages are supported:
 /// English, Spanish, French, Portuguese.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// CustomerFinderCognitiveServices.ICustomerFinderCognitiveServicesClient.
 /// </param>
 /// <param name='multiLanguageBatchInputV2'>
 /// Optional.
 /// </param>
 public static object Sentiment(this ICustomerFinderCognitiveServicesClient operations, MultiLanguageBatchInputV2 multiLanguageBatchInputV2 = null)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((ICustomerFinderCognitiveServicesClient)s).SentimentAsync(multiLanguageBatchInputV2);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
        /// <summary>
        /// The API returns a numeric score between 0 and 1.
        /// Scores close to 1 indicate positive sentiment, while
        /// scores close to 0 indicate negative sentiment.
        /// Sentiment score is generated using classification
        /// techniques.
        /// The input features to the classifier include n-grams,
        /// features generated from part-of-speech tags, and word embeddings.
        /// Currently, the following languages are supported:
        /// English, Spanish, French, Portuguese.
        /// </summary>
        /// <param name='operations'>
        /// Reference to the
        /// CustomerFinderCognitiveServices.ICustomerFinderCognitiveServicesClient.
        /// </param>
        /// <param name='multiLanguageBatchInputV2'>
        /// Optional.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        public static async Task <object> SentimentAsync(this ICustomerFinderCognitiveServicesClient operations, MultiLanguageBatchInputV2 multiLanguageBatchInputV2 = null, CancellationToken cancellationToken = default(System.Threading.CancellationToken))
        {
            Microsoft.Rest.HttpOperationResponse <object> result = await operations.SentimentWithOperationResponseAsync(multiLanguageBatchInputV2, cancellationToken).ConfigureAwait(false);

            return(result.Body);
        }
Exemple #5
0
        /// <summary>
        /// The API returns a numeric score between 0 and 1.
        /// Scores close to 1 indicate positive sentiment, while
        /// scores close to 0 indicate negative sentiment.
        /// Sentiment score is generated using classification
        /// techniques.
        /// The input features to the classifier include n-grams,
        /// features generated from part-of-speech tags, and word embeddings.
        /// Currently, the following languages are supported:
        /// English, Spanish, French, Portuguese.
        /// </summary>
        /// <param name='multiLanguageBatchInputV2'>
        /// Optional.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        public async Task <HttpOperationResponse <object> > SentimentWithOperationResponseAsync(MultiLanguageBatchInputV2 multiLanguageBatchInputV2 = null, CancellationToken cancellationToken = default(System.Threading.CancellationToken))
        {
            // Tracing
            bool   shouldTrace  = ServiceClientTracing.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("multiLanguageBatchInputV2", multiLanguageBatchInputV2);
                ServiceClientTracing.Enter(invocationId, this, "SentimentAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/sentiment";
            string baseUrl = this.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = new HttpRequestMessage();

            httpRequest.Method     = HttpMethod.Post;
            httpRequest.RequestUri = new Uri(url);

            // Set Headers

            // Set Credentials
            if (this.Credentials != null)
            {
                cancellationToken.ThrowIfCancellationRequested();
                await this.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
            }

            // Serialize Request
            string requestContent = null;
            JToken requestDoc     = multiLanguageBatchInputV2.SerializeJson(null);

            requestContent      = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
            httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
            httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

            // Send Request
            if (shouldTrace)
            {
                ServiceClientTracing.SendRequest(invocationId, httpRequest);
            }
            cancellationToken.ThrowIfCancellationRequested();
            HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

            if (shouldTrace)
            {
                ServiceClientTracing.ReceiveResponse(invocationId, httpResponse);
            }
            HttpStatusCode statusCode = httpResponse.StatusCode;

            cancellationToken.ThrowIfCancellationRequested();
            string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.BadRequest)
            {
                HttpOperationException <object> ex = new HttpOperationException <object>();
                ex.Request  = httpRequest;
                ex.Response = httpResponse;
                ex.Body     = null;
                if (shouldTrace)
                {
                    ServiceClientTracing.Error(invocationId, ex);
                }
                throw ex;
            }

            // Create Result
            HttpOperationResponse <object> result = new HttpOperationResponse <object>();

            result.Request  = httpRequest;
            result.Response = httpResponse;

            // Deserialize Response
            if (statusCode == HttpStatusCode.OK)
            {
                SentimentBatchResultV2 resultModel = new SentimentBatchResultV2();
                JToken responseDoc = null;
                if (string.IsNullOrEmpty(responseContent) == false)
                {
                    responseDoc = JToken.Parse(responseContent);
                }
                if (responseDoc != null)
                {
                    resultModel.DeserializeJson(responseDoc);
                }
                result.Body = resultModel;
            }
            if (statusCode == HttpStatusCode.BadRequest)
            {
                ErrorResponse resultModel = new ErrorResponse();
                JToken        responseDoc = null;
                if (string.IsNullOrEmpty(responseContent) == false)
                {
                    responseDoc = JToken.Parse(responseContent);
                }
                if (responseDoc != null)
                {
                    resultModel.DeserializeJson(responseDoc);
                }
                result.Body = resultModel;
            }

            if (shouldTrace)
            {
                ServiceClientTracing.Exit(invocationId, result);
            }
            return(result);
        }