public void DetectLanguage() { Mock <TranslationService.TranslationServiceClient> mockGrpcClient = new Mock <TranslationService.TranslationServiceClient>(MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()) .Returns(new Mock <Operations.OperationsClient>().Object); DetectLanguageRequest expectedRequest = new DetectLanguageRequest { ParentAsLocationName = new LocationName("[PROJECT]", "[LOCATION]"), Model = "model104069929", MimeType = "mimeType-196041627", Labels = { }, }; DetectLanguageResponse expectedResponse = new DetectLanguageResponse(); mockGrpcClient.Setup(x => x.DetectLanguage(expectedRequest, It.IsAny <CallOptions>())) .Returns(expectedResponse); TranslationServiceClient client = new TranslationServiceClientImpl(mockGrpcClient.Object, null); LocationName parent = new LocationName("[PROJECT]", "[LOCATION]"); string model = "model104069929"; string mimeType = "mimeType-196041627"; IDictionary <string, string> labels = new Dictionary <string, string>(); DetectLanguageResponse response = client.DetectLanguage(parent, model, mimeType, labels); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async Task DetectLanguageAsync() { Mock <TranslationService.TranslationServiceClient> mockGrpcClient = new Mock <TranslationService.TranslationServiceClient>(MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()) .Returns(new Mock <Operations.OperationsClient>().Object); DetectLanguageRequest expectedRequest = new DetectLanguageRequest { Parent = new LocationName("[PROJECT]", "[LOCATION]").ToString(), Model = "model104069929", MimeType = "mimeType-196041627", Labels = { }, }; DetectLanguageResponse expectedResponse = new DetectLanguageResponse(); mockGrpcClient.Setup(x => x.DetectLanguageAsync(expectedRequest, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <DetectLanguageResponse>(Task.FromResult(expectedResponse), null, null, null, null)); TranslationServiceClient client = new TranslationServiceClientImpl(mockGrpcClient.Object, null); string formattedParent = new LocationName("[PROJECT]", "[LOCATION]").ToString(); string model = "model104069929"; string mimeType = "mimeType-196041627"; IDictionary <string, string> labels = new Dictionary <string, string>(); DetectLanguageResponse response = await client.DetectLanguageAsync(formattedParent, model, mimeType, labels); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
/// <summary>Snippet for DetectLanguage</summary> public void DetectLanguage() { // Snippet: DetectLanguage(LocationName,string,string,IDictionary<string, string>,CallSettings) // Create client TranslationServiceClient translationServiceClient = TranslationServiceClient.Create(); // Initialize request argument(s) LocationName parent = new LocationName("[PROJECT]", "[LOCATION]"); string model = ""; string mimeType = ""; IDictionary <string, string> labels = new Dictionary <string, string>(); // Make the request DetectLanguageResponse response = translationServiceClient.DetectLanguage(parent, model, mimeType, labels); // End snippet }
/// <summary>Snippet for DetectLanguage</summary> public void DetectLanguage_RequestObject() { // Snippet: DetectLanguage(DetectLanguageRequest,CallSettings) // Create client TranslationServiceClient translationServiceClient = TranslationServiceClient.Create(); // Initialize request argument(s) DetectLanguageRequest request = new DetectLanguageRequest { ParentAsLocationName = new LocationName("[PROJECT]", "[LOCATION]"), }; // Make the request DetectLanguageResponse response = translationServiceClient.DetectLanguage(request); // End snippet }
private void DetectLanguageSuccessEventHandler(DetectLanguageResponse value) { ResetState(true); foreach (var detection in value.data.detections) { foreach (var item in detection) { _textNetworkResultInputField.text += "language: " + item.language + "\n" + "isReliable: " + item.isReliable + "\n" + "confidence: " + item.confidence + "\n---------\n"; } } }
/// <summary>Snippet for DetectLanguageAsync</summary> public async Task DetectLanguageAsync_RequestObject() { // Snippet: DetectLanguageAsync(DetectLanguageRequest,CallSettings) // Additional: DetectLanguageAsync(DetectLanguageRequest,CancellationToken) // Create client TranslationServiceClient translationServiceClient = await TranslationServiceClient.CreateAsync(); // Initialize request argument(s) DetectLanguageRequest request = new DetectLanguageRequest { ParentAsLocationName = new LocationName("[PROJECT]", "[LOCATION]"), }; // Make the request DetectLanguageResponse response = await translationServiceClient.DetectLanguageAsync(request); // End snippet }
/// <summary>Snippet for DetectLanguageAsync</summary> public async Task DetectLanguageAsync() { // Snippet: DetectLanguageAsync(string,string,string,IDictionary<string, string>,CallSettings) // Additional: DetectLanguageAsync(string,string,string,IDictionary<string, string>,CancellationToken) // Create client TranslationServiceClient translationServiceClient = await TranslationServiceClient.CreateAsync(); // Initialize request argument(s) string formattedParent = new LocationName("[PROJECT]", "[LOCATION]").ToString(); string model = ""; string mimeType = ""; IDictionary <string, string> labels = new Dictionary <string, string>(); // Make the request DetectLanguageResponse response = await translationServiceClient.DetectLanguageAsync(formattedParent, model, mimeType, labels); // End snippet }
public async Task DetectLanguageAsync2() { Mock <TranslationService.TranslationServiceClient> mockGrpcClient = new Mock <TranslationService.TranslationServiceClient>(MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()) .Returns(new Mock <Operations.OperationsClient>().Object); DetectLanguageRequest request = new DetectLanguageRequest { ParentAsLocationName = new LocationName("[PROJECT]", "[LOCATION]"), }; DetectLanguageResponse expectedResponse = new DetectLanguageResponse(); mockGrpcClient.Setup(x => x.DetectLanguageAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <DetectLanguageResponse>(Task.FromResult(expectedResponse), null, null, null, null)); TranslationServiceClient client = new TranslationServiceClientImpl(mockGrpcClient.Object, null); DetectLanguageResponse response = await client.DetectLanguageAsync(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public void DetectLanguage2() { Mock <TranslationService.TranslationServiceClient> mockGrpcClient = new Mock <TranslationService.TranslationServiceClient>(MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()) .Returns(new Mock <Operations.OperationsClient>().Object); DetectLanguageRequest request = new DetectLanguageRequest { ParentAsLocationName = new LocationName("[PROJECT]", "[LOCATION]"), }; DetectLanguageResponse expectedResponse = new DetectLanguageResponse(); mockGrpcClient.Setup(x => x.DetectLanguage(request, It.IsAny <CallOptions>())) .Returns(expectedResponse); TranslationServiceClient client = new TranslationServiceClientImpl(mockGrpcClient.Object, null); DetectLanguageResponse response = client.DetectLanguage(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public void DetectLanguageTest() { DetectLanguageResponse r = new DetectLanguageResponse { data = new DetectionData { detections = new Detection[] { new Detection { language = "zu", isReliable = true, confidence = 9 } } } }; OutLine(r.ToJson()); DetectLanguageLanguageDetector detector = new DetectLanguageLanguageDetector(); Language lang = detector.DetectLanguage("Ich mag Affen"); Expect.AreEqual("de", lang.ISO6391); }
/// <summary> /// Detects the language of a given text. /// </summary> /// <param name="text">The text string for performing language detection</param> /// <param name="projectId">Your Google Cloud Project ID.</param> public static void DetectLanguageSample(string text = "[TEXT_STRING_FOR_DETECTION]", string projectId = "[Google Cloud Project ID]") { TranslationServiceClient translationServiceClient = TranslationServiceClient.Create(); DetectLanguageRequest request = new DetectLanguageRequest { ParentAsLocationName = new LocationName(projectId, "global"), Content = text, MimeType = "text/plain", }; DetectLanguageResponse response = translationServiceClient.DetectLanguage(request); // Display list of detected languages sorted by detection confidence. // The most probable language is first. foreach (DetectedLanguage language in response.Languages) { // The language detected Console.WriteLine($"Language code: {language.LanguageCode}"); // Confidence of detection result for this language Console.WriteLine($"Confidence: {language.Confidence}"); } }