/// <summary>
 /// The API returns the top detected topics for a list of submitted text
 /// documents.
 /// A topic is identified with a key phrase, which can be one or
 /// more related words.
 /// Use the URL parameters and stop word list to control which
 /// words or documents are filtered out.
 /// You can also supply a list of topics to exclude from the
 /// response.
 /// At least 100 text documents must be submitted, however it is
 /// designed to detect topics across hundreds to thousands of documents.
 /// Note that one transaction is charged per text document
 /// submitted.
 /// For best performance, limit each document to a short, human
 /// written text paragraph such as review, conversation or user feedback.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='minDocumentsPerWord'>
 /// Format - int32. (optional) Words that occur in less than this many
 /// documents are ignored.
 /// Use this parameter to help exclude rare document topics.
 /// Omit to let the service choose appropriate value.
 /// </param>
 /// <param name='maxDocumentsPerWord'>
 /// Format - int32. (optional) Words that occur in more than this many
 /// documents are ignored.
 /// Use this parameter to help exclude ubiquitous document topics.
 /// Omit to let the service choose appropriate value.
 /// </param>
 /// <param name='subscriptionKey'>
 /// subscription key in url
 /// </param>
 /// <param name='ocpApimSubscriptionKey'>
 /// subscription key in header
 /// </param>
 /// <param name='topicDetectionInputV2'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async System.Threading.Tasks.Task<ErrorResponse> DetectTopicsAsync(this IAzureMachineLearningTextAnalytics operations, int? minDocumentsPerWord = default(int?), int? maxDocumentsPerWord = default(int?), string subscriptionKey = default(string), string ocpApimSubscriptionKey = default(string), TopicDetectionInputV2 topicDetectionInputV2 = default(TopicDetectionInputV2), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
 {
     using (var _result = await operations.DetectTopicsWithHttpMessagesAsync(minDocumentsPerWord, maxDocumentsPerWord, subscriptionKey, ocpApimSubscriptionKey, topicDetectionInputV2, null, cancellationToken).ConfigureAwait(false))
     {
         return _result.Body;
     }
 }
 /// <summary>
 /// The API returns the top detected topics for a list of submitted text
 /// documents.
 /// A topic is identified with a key phrase, which can be one or
 /// more related words.
 /// Use the URL parameters and stop word list to control which
 /// words or documents are filtered out.
 /// You can also supply a list of topics to exclude from the
 /// response.
 /// At least 100 text documents must be submitted, however it is
 /// designed to detect topics across hundreds to thousands of documents.
 /// Note that one transaction is charged per text document
 /// submitted.
 /// For best performance, limit each document to a short, human
 /// written text paragraph such as review, conversation or user feedback.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='minDocumentsPerWord'>
 /// Format - int32. (optional) Words that occur in less than this many
 /// documents are ignored.
 /// Use this parameter to help exclude rare document topics.
 /// Omit to let the service choose appropriate value.
 /// </param>
 /// <param name='maxDocumentsPerWord'>
 /// Format - int32. (optional) Words that occur in more than this many
 /// documents are ignored.
 /// Use this parameter to help exclude ubiquitous document topics.
 /// Omit to let the service choose appropriate value.
 /// </param>
 /// <param name='subscriptionKey'>
 /// subscription key in url
 /// </param>
 /// <param name='ocpApimSubscriptionKey'>
 /// subscription key in header
 /// </param>
 /// <param name='topicDetectionInputV2'>
 /// </param>
 public static ErrorResponse DetectTopics(this IAzureMachineLearningTextAnalytics operations, int? minDocumentsPerWord = default(int?), int? maxDocumentsPerWord = default(int?), string subscriptionKey = default(string), string ocpApimSubscriptionKey = default(string), TopicDetectionInputV2 topicDetectionInputV2 = default(TopicDetectionInputV2))
 {
     return System.Threading.Tasks.Task.Factory.StartNew(s => ((IAzureMachineLearningTextAnalytics)s).DetectTopicsAsync(minDocumentsPerWord, maxDocumentsPerWord, subscriptionKey, ocpApimSubscriptionKey, topicDetectionInputV2), operations, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskCreationOptions.None, System.Threading.Tasks.TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// The API returns the top detected topics for a list of submitted
 /// text documents.
 /// A topic is identified with a key phrase, which can be
 /// one or more related words.
 /// Use the URL parameters and stop word list to control
 /// which words or documents are filtered out.
 /// You can also supply a list of topics to exclude from
 /// the response.
 /// At least 100 text documents must be submitted, however
 /// it is designed to detect topics across hundreds to thousands of
 /// documents.
 /// Note that one transaction is charged per text document
 /// submitted.
 /// For best performance, limit each document to a short,
 /// human written text paragraph such as review, conversation or user
 /// feedback.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// CustomerFinderCognitiveServices.ICustomerFinderCognitiveServicesClient.
 /// </param>
 /// <param name='minDocumentsPerWord'>
 /// Optional. Format - int32. (optional) Words that occur in less than
 /// this many documents are ignored.
 /// Use this parameter to help exclude rare document
 /// topics.
 /// Omit to let the service choose appropriate value.
 /// </param>
 /// <param name='maxDocumentsPerWord'>
 /// Optional. Format - int32. (optional) Words that occur in more than
 /// this many documents are ignored.
 /// Use this parameter to help exclude ubiquitous document
 /// topics.
 /// Omit to let the service choose appropriate value.
 /// </param>
 /// <param name='topicDetectionInputV2'>
 /// Optional.
 /// </param>
 public static ErrorResponse DetectTopics(this ICustomerFinderCognitiveServicesClient operations, int?minDocumentsPerWord = null, int?maxDocumentsPerWord = null, TopicDetectionInputV2 topicDetectionInputV2 = null)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((ICustomerFinderCognitiveServicesClient)s).DetectTopicsAsync(minDocumentsPerWord, maxDocumentsPerWord, topicDetectionInputV2);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
        /// <summary>
        /// The API returns the top detected topics for a list of submitted
        /// text documents.
        /// A topic is identified with a key phrase, which can be
        /// one or more related words.
        /// Use the URL parameters and stop word list to control
        /// which words or documents are filtered out.
        /// You can also supply a list of topics to exclude from
        /// the response.
        /// At least 100 text documents must be submitted, however
        /// it is designed to detect topics across hundreds to thousands of
        /// documents.
        /// Note that one transaction is charged per text document
        /// submitted.
        /// For best performance, limit each document to a short,
        /// human written text paragraph such as review, conversation or user
        /// feedback.
        /// </summary>
        /// <param name='operations'>
        /// Reference to the
        /// CustomerFinderCognitiveServices.ICustomerFinderCognitiveServicesClient.
        /// </param>
        /// <param name='minDocumentsPerWord'>
        /// Optional. Format - int32. (optional) Words that occur in less than
        /// this many documents are ignored.
        /// Use this parameter to help exclude rare document
        /// topics.
        /// Omit to let the service choose appropriate value.
        /// </param>
        /// <param name='maxDocumentsPerWord'>
        /// Optional. Format - int32. (optional) Words that occur in more than
        /// this many documents are ignored.
        /// Use this parameter to help exclude ubiquitous document
        /// topics.
        /// Omit to let the service choose appropriate value.
        /// </param>
        /// <param name='topicDetectionInputV2'>
        /// Optional.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        public static async Task <ErrorResponse> DetectTopicsAsync(this ICustomerFinderCognitiveServicesClient operations, int?minDocumentsPerWord = null, int?maxDocumentsPerWord = null, TopicDetectionInputV2 topicDetectionInputV2 = null, CancellationToken cancellationToken = default(System.Threading.CancellationToken))
        {
            Microsoft.Rest.HttpOperationResponse <CustomerFinderCognitiveServices.Models.ErrorResponse> result = await operations.DetectTopicsWithOperationResponseAsync(minDocumentsPerWord, maxDocumentsPerWord, topicDetectionInputV2, cancellationToken).ConfigureAwait(false);

            return(result.Body);
        }
Example #5
0
        /// <summary>
        /// The API returns the top detected topics for a list of submitted
        /// text documents.
        /// A topic is identified with a key phrase, which can be
        /// one or more related words.
        /// Use the URL parameters and stop word list to control
        /// which words or documents are filtered out.
        /// You can also supply a list of topics to exclude from
        /// the response.
        /// At least 100 text documents must be submitted, however
        /// it is designed to detect topics across hundreds to thousands of
        /// documents.
        /// Note that one transaction is charged per text document
        /// submitted.
        /// For best performance, limit each document to a short,
        /// human written text paragraph such as review, conversation or user
        /// feedback.
        /// </summary>
        /// <param name='minDocumentsPerWord'>
        /// Optional. Format - int32. (optional) Words that occur in less than
        /// this many documents are ignored.
        /// Use this parameter to help exclude rare document
        /// topics.
        /// Omit to let the service choose appropriate value.
        /// </param>
        /// <param name='maxDocumentsPerWord'>
        /// Optional. Format - int32. (optional) Words that occur in more than
        /// this many documents are ignored.
        /// Use this parameter to help exclude ubiquitous document
        /// topics.
        /// Omit to let the service choose appropriate value.
        /// </param>
        /// <param name='topicDetectionInputV2'>
        /// Optional.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        public async Task <HttpOperationResponse <ErrorResponse> > DetectTopicsWithOperationResponseAsync(int?minDocumentsPerWord = null, int?maxDocumentsPerWord = null, TopicDetectionInputV2 topicDetectionInputV2 = 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("minDocumentsPerWord", minDocumentsPerWord);
                tracingParameters.Add("maxDocumentsPerWord", maxDocumentsPerWord);
                tracingParameters.Add("topicDetectionInputV2", topicDetectionInputV2);
                ServiceClientTracing.Enter(invocationId, this, "DetectTopicsAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

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

            if (minDocumentsPerWord != null)
            {
                queryParameters.Add("minDocumentsPerWord=" + Uri.EscapeDataString(minDocumentsPerWord.Value.ToString()));
            }
            if (maxDocumentsPerWord != null)
            {
                queryParameters.Add("maxDocumentsPerWord=" + Uri.EscapeDataString(maxDocumentsPerWord.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     = topicDetectionInputV2.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.Accepted && 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 <ErrorResponse> result = new HttpOperationResponse <ErrorResponse>();

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

            // Deserialize Response
            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);
        }