Example #1
0
        private TextDocumentBatchStatistics GetMockStatistics()
        {
            int  documentCount = 2, validDocumentCount = 2, invalidDocumentCount = 0;
            long transactionCount = 5;

            return(TextAnalyticsModelFactory.TextDocumentBatchStatistics(documentCount, validDocumentCount, invalidDocumentCount, transactionCount));
        }
Example #2
0
 private List <AnalyzeSentimentResult> GetMockSentimentResults()
 {
     return(new List <AnalyzeSentimentResult>
     {
         TextAnalyticsModelFactory.AnalyzeSentimentResult("0", new TextDocumentStatistics(), TextAnalyticsModelFactory.DocumentSentiment(TextSentiment.Positive, 0.9, 0.8, 0.7, new List <SentenceSentiment>(), null)),
         TextAnalyticsModelFactory.AnalyzeSentimentResult("1", new TextDocumentStatistics(), TextAnalyticsModelFactory.DocumentSentiment(TextSentiment.Positive, 0.9, 0.8, 0.7, new List <SentenceSentiment>(), null))
     });
 }
        public async Task RecognizeEntitiesResultsSorted_WithErrors()
        {
            var mockResults = new List <RecognizeEntitiesResult>()
            {
                TextAnalyticsModelFactory.RecognizeEntitiesResult("2", new TextDocumentStatistics(),
                                                                  new CategorizedEntityCollection
                                                                  (
                                                                      new List <CategorizedEntity>
                {
                    new CategorizedEntity("EntityText0", "EntityCategory0", "EntitySubCategory0", 0.5),
                    new CategorizedEntity("EntityText1", "EntityCategory1", "EntitySubCategory1", 0.5),
                },
                                                                      new List <TextAnalyticsWarning>()
                                                                  )),
                TextAnalyticsModelFactory.RecognizeEntitiesResult("3", new TextDocumentStatistics(),
                                                                  new CategorizedEntityCollection
                                                                  (
                                                                      new List <CategorizedEntity>
                {
                    new CategorizedEntity("EntityText0", "EntityCategory0", "EntitySubCategory0", 0.5),
                    new CategorizedEntity("EntityText1", "EntityCategory1", "EntitySubCategory1", 0.5),
                },
                                                                      new List <TextAnalyticsWarning>()
                                                                  )),
                new RecognizeEntitiesResult("4", new TextAnalyticsError("InvalidDocument", "Document is invalid.")),
                new RecognizeEntitiesResult("5", new TextAnalyticsError("InvalidDocument", "Document is invalid.")),
            };
            var mockResultCollection = new RecognizeEntitiesResultCollection(mockResults,
                                                                             new TextDocumentBatchStatistics(2, 2, 2, 2),
                                                                             "modelVersion");

            var mockResponse = new MockResponse(200);

            mockResponse.SetContent(SerializationHelpers.Serialize(mockResultCollection, SerializeRecognizeEntitiesResultCollection));

            var mockTransport          = new MockTransport(mockResponse);
            TextAnalyticsClient client = CreateTestClient(mockTransport);

            var documents = new List <TextDocumentInput>()
            {
                new TextDocumentInput("4", "TextDocument1"),
                new TextDocumentInput("5", "TextDocument2"),
                new TextDocumentInput("2", "TextDocument3"),
                new TextDocumentInput("3", "TextDocument4"),
            };

            var response = await client.RecognizeEntitiesBatchAsync(documents, new TextAnalyticsRequestOptions());

            var resultCollection = response.Value;

            Assert.AreEqual("4", resultCollection[0].Id);
            Assert.AreEqual("5", resultCollection[1].Id);
            Assert.AreEqual("2", resultCollection[2].Id);
            Assert.AreEqual("3", resultCollection[3].Id);
        }
        public async Task DetectLanguageBatchAsync()
        {
            var mockResponse = new Mock <Response>();
            var mockClient   = new Mock <TextAnalyticsClient>();
            var documents    = new List <string>
            {
                "Hello world",
                "Bonjour tout le monde",
            };

            var languages = new List <DetectLanguageResult>
            {
                TextAnalyticsModelFactory.DetectLanguageResult("0", default, TextAnalyticsModelFactory.DetectedLanguage("English", "en", 1.00)),
Example #5
0
        public void ExtractSummaryResultWithError()
        {
            var id    = "id";
            var error = TextAnalyticsModelFactory.TextAnalyticsError("code", "message", "target");

            var extractSummaryResult = TextAnalyticsModelFactory.ExtractSummaryResult(id, error);

            Assert.AreEqual(id, extractSummaryResult.Id);
            Assert.AreEqual(default(TextDocumentStatistics), extractSummaryResult.Statistics);
            Assert.Throws <InvalidOperationException>(() => _ = extractSummaryResult.Sentences);

            Assert.IsTrue(extractSummaryResult.HasError);
            Assert.AreEqual(error, extractSummaryResult.Error);
        }
Example #6
0
        public void ExtractSummaryResultWithoutError()
        {
            var id                 = "id";
            var statistics         = TextAnalyticsModelFactory.TextDocumentStatistics(10, 20);
            var sentenceCollection = TextAnalyticsModelFactory.SummarySentenceCollection(new List <SummarySentence>());

            var extractSummaryResult = TextAnalyticsModelFactory.ExtractSummaryResult(id, statistics, sentenceCollection);

            Assert.AreEqual(id, extractSummaryResult.Id);
            Assert.AreEqual(statistics, extractSummaryResult.Statistics);
            Assert.AreEqual(sentenceCollection, extractSummaryResult.Sentences);

            Assert.IsFalse(extractSummaryResult.HasError);
            Assert.AreEqual(default(TextAnalyticsError), extractSummaryResult.Error);
        }
Example #7
0
        public async Task DetectLanguageAsync()
        {
            #region Snippet:CreateMocks
            var mockResponse = new Mock <Response>();
            var mockClient   = new Mock <TextAnalyticsClient>();
            #endregion

            #region Snippet:SetupMocks
            Response <DetectedLanguage> response = Response.FromValue(TextAnalyticsModelFactory.DetectedLanguage("Spanish", "es", 1.00), mockResponse.Object);

            mockClient.Setup(c => c.DetectLanguageAsync("Este documento está en español.", It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(response));
            #endregion

            #region Snippet:UseMocks
            TextAnalyticsClient client = mockClient.Object;
            bool result = await IsSpanishAsync("Este documento está en español.", client, default);

            Assert.IsTrue(result);
            #endregion
        }
Example #8
0
 private AnalyzeSentimentResultCollection GetMockAnalyzeSentimentResultCollection()
 {
     return(TextAnalyticsModelFactory.AnalyzeSentimentResultCollection(GetMockSentimentResults(), GetMockStatistics(), "1"));
 }