/// <summary>
 /// The API returns the detected language and a numeric score between 0 and 1.
 /// 
 /// Scores close to 1 indicate 100% certainty that the identified
 /// language is true.
 /// A total of 120 languages are supported.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='numberOfLanguagesToDetect'>
 /// Format - int32. (Optional) Number of languages to detect. Set to 1 by
 /// default.
 /// </param>
 /// <param name='subscriptionKey'>
 /// subscription key in url
 /// </param>
 /// <param name='ocpApimSubscriptionKey'>
 /// subscription key in header
 /// </param>
 /// <param name='batchInputV2'>
 /// </param>
 public static object DetectLanguage(this IAzureMachineLearningTextAnalytics operations, int? numberOfLanguagesToDetect = default(int?), string subscriptionKey = default(string), string ocpApimSubscriptionKey = default(string), BatchInputV2 batchInputV2 = default(BatchInputV2))
 {
     return System.Threading.Tasks.Task.Factory.StartNew(s => ((IAzureMachineLearningTextAnalytics)s).DetectLanguageAsync(numberOfLanguagesToDetect, subscriptionKey, ocpApimSubscriptionKey, batchInputV2), operations, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskCreationOptions.None, System.Threading.Tasks.TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// The API returns the detected language and a numeric score between 0 and 1.
 /// 
 /// Scores close to 1 indicate 100% certainty that the identified
 /// language is true.
 /// A total of 120 languages are supported.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='numberOfLanguagesToDetect'>
 /// Format - int32. (Optional) Number of languages to detect. Set to 1 by
 /// default.
 /// </param>
 /// <param name='subscriptionKey'>
 /// subscription key in url
 /// </param>
 /// <param name='ocpApimSubscriptionKey'>
 /// subscription key in header
 /// </param>
 /// <param name='batchInputV2'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async System.Threading.Tasks.Task<object> DetectLanguageAsync(this IAzureMachineLearningTextAnalytics operations, int? numberOfLanguagesToDetect = default(int?), string subscriptionKey = default(string), string ocpApimSubscriptionKey = default(string), BatchInputV2 batchInputV2 = default(BatchInputV2), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
 {
     using (var _result = await operations.DetectLanguageWithHttpMessagesAsync(numberOfLanguagesToDetect, subscriptionKey, ocpApimSubscriptionKey, batchInputV2, null, cancellationToken).ConfigureAwait(false))
     {
         return _result.Body;
     }
 }
 /// <summary>
 /// The API returns the detected language and a numeric score between 0
 /// and 1.
 /// Scores close to 1 indicate 100% certainty that the
 /// identified language is true.
 /// A total of 120 languages are supported.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// CustomerFinderCognitiveServices.ICustomerFinderCognitiveServicesClient.
 /// </param>
 /// <param name='numberOfLanguagesToDetect'>
 /// Optional. Format - int32. (Optional) Number of languages to detect.
 /// Set to 1 by default.
 /// </param>
 /// <param name='batchInputV2'>
 /// Optional.
 /// </param>
 public static object DetectLanguage(this ICustomerFinderCognitiveServicesClient operations, int?numberOfLanguagesToDetect = null, BatchInputV2 batchInputV2 = null)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((ICustomerFinderCognitiveServicesClient)s).DetectLanguageAsync(numberOfLanguagesToDetect, batchInputV2);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
        /// <summary>
        /// The API returns the detected language and a numeric score between 0
        /// and 1.
        /// Scores close to 1 indicate 100% certainty that the
        /// identified language is true.
        /// A total of 120 languages are supported.
        /// </summary>
        /// <param name='operations'>
        /// Reference to the
        /// CustomerFinderCognitiveServices.ICustomerFinderCognitiveServicesClient.
        /// </param>
        /// <param name='numberOfLanguagesToDetect'>
        /// Optional. Format - int32. (Optional) Number of languages to detect.
        /// Set to 1 by default.
        /// </param>
        /// <param name='batchInputV2'>
        /// Optional.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        public static async Task <object> DetectLanguageAsync(this ICustomerFinderCognitiveServicesClient operations, int?numberOfLanguagesToDetect = null, BatchInputV2 batchInputV2 = null, CancellationToken cancellationToken = default(System.Threading.CancellationToken))
        {
            Microsoft.Rest.HttpOperationResponse <object> result = await operations.DetectLanguageWithOperationResponseAsync(numberOfLanguagesToDetect, batchInputV2, cancellationToken).ConfigureAwait(false);

            return(result.Body);
        }
Exemple #5
0
        /// <summary>
        /// The API returns the detected language and a numeric score between 0
        /// and 1.
        /// Scores close to 1 indicate 100% certainty that the
        /// identified language is true.
        /// A total of 120 languages are supported.
        /// </summary>
        /// <param name='numberOfLanguagesToDetect'>
        /// Optional. Format - int32. (Optional) Number of languages to detect.
        /// Set to 1 by default.
        /// </param>
        /// <param name='batchInputV2'>
        /// Optional.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        public async Task <HttpOperationResponse <object> > DetectLanguageWithOperationResponseAsync(int?numberOfLanguagesToDetect = null, BatchInputV2 batchInputV2 = 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("numberOfLanguagesToDetect", numberOfLanguagesToDetect);
                tracingParameters.Add("batchInputV2", batchInputV2);
                ServiceClientTracing.Enter(invocationId, this, "DetectLanguageAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/languages";
            List <string> queryParameters = new List <string>();

            if (numberOfLanguagesToDetect != null)
            {
                queryParameters.Add("numberOfLanguagesToDetect=" + Uri.EscapeDataString(numberOfLanguagesToDetect.Value.ToString()));
            }
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            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     = batchInputV2.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)
            {
                LanguageBatchResultV2 resultModel = new LanguageBatchResultV2();
                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);
        }