public async stt::Task AnalyzeSentimentRequestObjectAsync()
        {
            moq::Mock <LanguageService.LanguageServiceClient> mockGrpcClient = new moq::Mock <LanguageService.LanguageServiceClient>(moq::MockBehavior.Strict);
            AnalyzeSentimentRequest request = new AnalyzeSentimentRequest
            {
                Document     = new Document(),
                EncodingType = EncodingType.None,
            };
            AnalyzeSentimentResponse expectedResponse = new AnalyzeSentimentResponse
            {
                DocumentSentiment = new Sentiment(),
                Language          = "language7dae1285",
                Sentences         = { new Sentence(), },
            };

            mockGrpcClient.Setup(x => x.AnalyzeSentimentAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <AnalyzeSentimentResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            LanguageServiceClient    client = new LanguageServiceClientImpl(mockGrpcClient.Object, null);
            AnalyzeSentimentResponse responseCallSettings = await client.AnalyzeSentimentAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            AnalyzeSentimentResponse responseCancellationToken = await client.AnalyzeSentimentAsync(request, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
Пример #2
0
 /// <summary>
 /// Analyzes the sentiment of the provided text.
 /// </summary>
 /// <param name="request">
 /// The request object containing all of the parameters for the API call.
 /// </param>
 /// <param name="callSettings">
 /// If not null, applies overrides to this RPC call.
 /// </param>
 /// <returns>
 /// The RPC response.
 /// </returns>
 public override AnalyzeSentimentResponse AnalyzeSentiment(
     AnalyzeSentimentRequest request,
     CallSettings callSettings = null)
 {
     Modify_AnalyzeSentimentRequest(ref request, ref callSettings);
     return(_callAnalyzeSentiment.Sync(request, callSettings));
 }
Пример #3
0
        private static AnalyzeSentimentRequest GetSentimentAnalysisRequest(DocumentBatch documentBatch)
        {
            var document = Google.Cloud.Language.V1.Document.FromPlainText(documentBatch.ToAnnotatedPlainText());
            var analyzeSentimentRequest = new AnalyzeSentimentRequest
            {
                Document     = document,
                EncodingType = EncodingType.Utf16 // Default in C#
            };

            return(analyzeSentimentRequest);
        }
Пример #4
0
        /// <summary>
        /// Analyzes the sentiment of the provided text.
        /// </summary>
        /// <param name="document">
        /// Input document. Currently, `analyzeSentiment` only supports English text
        /// ([Document.language][google.cloud.language.v1.Document.language]="EN").
        /// </param>
        /// <param name="callSettings">
        /// If not null, applies overrides to this RPC call.
        /// </param>
        /// <returns>
        /// The RPC response.
        /// </returns>
        public override AnalyzeSentimentResponse AnalyzeSentiment(
            Document document,
            CallSettings callSettings = null)
        {
            AnalyzeSentimentRequest request = new AnalyzeSentimentRequest
            {
                Document = document,
            };

            Modify_AnalyzeSentimentRequest(ref request, ref callSettings);
            return(_callAnalyzeSentiment.Sync(request, callSettings));
        }
 public void AnalyzeSentiment_RequestObject()
 {
     // Snippet: AnalyzeSentiment(AnalyzeSentimentRequest,CallSettings)
     // Create client
     LanguageServiceClient languageServiceClient = LanguageServiceClient.Create();
     // Initialize request argument(s)
     AnalyzeSentimentRequest request = new AnalyzeSentimentRequest
     {
         Document = new Document(),
     };
     // Make the request
     AnalyzeSentimentResponse response = languageServiceClient.AnalyzeSentiment(request);
     // End snippet
 }
Пример #6
0
 // [START analyze_text_sentiment_core]
 /// <summary>
 /// This sample demonstrates analyzing the sentiment of text
 /// </summary>
 public static void SampleAnalyzeSentiment()
 {
     LanguageServiceClient   languageServiceClient = LanguageServiceClient.Create();
     AnalyzeSentimentRequest request = new AnalyzeSentimentRequest
     {
         Document = new Document
         {
             Type    = Document.Types.Type.PlainText,
             Content = "I am so happy",
         },
     };
     AnalyzeSentimentResponse response = languageServiceClient.AnalyzeSentiment(request);
     // FIXME: inspect the results
 }
Пример #7
0
 // [START language_sentiment_gcs_core]
 /// <summary>
 /// Analyze sentiment of text stored in GCS
 /// </summary>
 public static void SampleAnalyzeSentiment(string gcsUri)
 {
     LanguageServiceClient languageServiceClient = LanguageServiceClient.Create();
     // string gcsUri = "gs://cloud-samples-data/language/sentiment-positive.txt"
     AnalyzeSentimentRequest request = new AnalyzeSentimentRequest
     {
         Document = new Document
         {
             Type = Document.Types.Type.PlainText,
             GcsContentUri = "gs://cloud-samples-data/language/sentiment-positive.txt",
         },
     };
     AnalyzeSentimentResponse response = languageServiceClient.AnalyzeSentiment(request);
     // FIXME: inspect the results
 }
        public async Task AnalyzeSentimentAsync_RequestObject()
        {
            // Snippet: AnalyzeSentimentAsync(AnalyzeSentimentRequest,CallSettings)
            // Create client
            LanguageServiceClient languageServiceClient = await LanguageServiceClient.CreateAsync();

            // Initialize request argument(s)
            AnalyzeSentimentRequest request = new AnalyzeSentimentRequest
            {
                Document = new Document(),
            };
            // Make the request
            AnalyzeSentimentResponse response = await languageServiceClient.AnalyzeSentimentAsync(request);

            // End snippet
        }
        /// <summary>Snippet for AnalyzeSentimentAsync</summary>
        public async Task AnalyzeSentimentRequestObjectAsync()
        {
            // Snippet: AnalyzeSentimentAsync(AnalyzeSentimentRequest, CallSettings)
            // Additional: AnalyzeSentimentAsync(AnalyzeSentimentRequest, CancellationToken)
            // Create client
            LanguageServiceClient languageServiceClient = await LanguageServiceClient.CreateAsync();

            // Initialize request argument(s)
            AnalyzeSentimentRequest request = new AnalyzeSentimentRequest
            {
                Document     = new Document(),
                EncodingType = EncodingType.None,
            };
            // Make the request
            AnalyzeSentimentResponse response = await languageServiceClient.AnalyzeSentimentAsync(request);

            // End snippet
        }
        public void AnalyzeSentiment2()
        {
            Mock <LanguageService.LanguageServiceClient> mockGrpcClient = new Mock <LanguageService.LanguageServiceClient>(MockBehavior.Strict);
            AnalyzeSentimentRequest request = new AnalyzeSentimentRequest
            {
                Document = new Document(),
            };
            AnalyzeSentimentResponse expectedResponse = new AnalyzeSentimentResponse
            {
                Language = "language-1613589672",
            };

            mockGrpcClient.Setup(x => x.AnalyzeSentiment(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            LanguageServiceClient    client   = new LanguageServiceClientImpl(mockGrpcClient.Object, null);
            AnalyzeSentimentResponse response = client.AnalyzeSentiment(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        public async Task AnalyzeSentimentAsync2()
        {
            Mock <LanguageService.LanguageServiceClient> mockGrpcClient = new Mock <LanguageService.LanguageServiceClient>(MockBehavior.Strict);
            AnalyzeSentimentRequest request = new AnalyzeSentimentRequest
            {
                Document = new Document(),
            };
            AnalyzeSentimentResponse expectedResponse = new AnalyzeSentimentResponse
            {
                Language = "language-1613589672",
            };

            mockGrpcClient.Setup(x => x.AnalyzeSentimentAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <AnalyzeSentimentResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            LanguageServiceClient    client   = new LanguageServiceClientImpl(mockGrpcClient.Object, null);
            AnalyzeSentimentResponse response = await client.AnalyzeSentimentAsync(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        public void AnalyzeSentiment2()
        {
            moq::Mock <LanguageService.LanguageServiceClient> mockGrpcClient = new moq::Mock <LanguageService.LanguageServiceClient>(moq::MockBehavior.Strict);
            AnalyzeSentimentRequest request = new AnalyzeSentimentRequest
            {
                Document = new Document(),
            };
            AnalyzeSentimentResponse expectedResponse = new AnalyzeSentimentResponse
            {
                DocumentSentiment = new Sentiment(),
                Language          = "language7dae1285",
                Sentences         = { new Sentence(), },
            };

            mockGrpcClient.Setup(x => x.AnalyzeSentiment(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            LanguageServiceClient    client   = new LanguageServiceClientImpl(mockGrpcClient.Object, null);
            AnalyzeSentimentResponse response = client.AnalyzeSentiment(request.Document);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Пример #13
0
 // Partial modifier methods contain '_' to ensure no name conflicts with RPC methods.
 partial void Modify_AnalyzeSentimentRequest(ref AnalyzeSentimentRequest request, ref CallSettings settings);
Пример #14
0
 /// <summary>
 /// Analyzes the sentiment of the provided text.
 /// </summary>
 /// <param name="request">
 /// The request object containing all of the parameters for the API call.
 /// </param>
 /// <param name="callSettings">
 /// If not null, applies overrides to this RPC call.
 /// </param>
 /// <returns>
 /// The RPC response.
 /// </returns>
 public virtual AnalyzeSentimentResponse AnalyzeSentiment(
     AnalyzeSentimentRequest request,
     CallSettings callSettings = null)
 {
     throw new NotImplementedException();
 }
Пример #15
0
        /// <summary>
        /// Analyzes the sentiment of the provided text.
        /// Documentation https://developers.google.com/cloudnaturallanguage/v1/reference/documents/analyzeSentiment
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated CloudNaturalLanguage service.</param>
        /// <param name="body">A valid CloudNaturalLanguage v1 body.</param>
        /// <returns>AnalyzeSentimentResponseResponse</returns>
        public static AnalyzeSentimentResponse AnalyzeSentiment(CloudNaturalLanguageService service, AnalyzeSentimentRequest body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }

                // Make the request.
                return(service.Documents.AnalyzeSentiment(body).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Documents.AnalyzeSentiment failed.", ex);
            }
        }