Exemplo n.º 1
0
        public async Task RecognizeCustomEntitiesTest()
        {
            TextAnalyticsClient client = GetClient();

            TextAnalyticsActions batchActions = new TextAnalyticsActions()
            {
                RecognizeCustomEntitiesActions = new List <RecognizeCustomEntitiesAction>()
                {
                    new RecognizeCustomEntitiesAction(TestEnvironment.RecognizeCustomEntitiesProjectName, TestEnvironment.RecognizeCustomEntitiesDeploymentName)
                }
            };

            var operation = await client.StartAnalyzeActionsAsync(new List <string> {
                EnglishDocument1
            }, batchActions);

            await PollUntilTimeout(operation);

            Assert.IsTrue(operation.HasCompleted);

            RecognizeCustomEntitiesResultCollection results = ExtractDocumentsResultsFromResponse(operation);
            RecognizeEntitiesResult     firstResult         = results.First();
            CategorizedEntityCollection entites             = firstResult.Entities;

            ValidateInDocumentResult(entites, e_document1ExpectedOutput);
        }
Exemplo n.º 2
0
        public async Task RecognizeEntitiesTypesSubTypes()
        {
            TextAnalyticsClient client = GetClient();
            const string        input  = "Bill Gates | Microsoft | New Mexico | 800-102-1100 | [email protected] | April 4, 1975 12:34 | April 4, 1975 | 12:34 | five seconds | 9 | third | 120% | €30 | 11m | 22 °C";

            RecognizeEntitiesResult result = await client.RecognizeEntitiesAsync(input);

            List <NamedEntity> entities = result.NamedEntities.ToList();

            Assert.AreEqual(15, entities.Count);

            Assert.AreEqual(NamedEntityType.Person, entities[0].Type);
            Assert.AreEqual(NamedEntitySubType.None, entities[0].SubType);

            Assert.AreEqual(NamedEntityType.Organization, entities[1].Type);
            Assert.AreEqual(NamedEntitySubType.None, entities[1].SubType);

            Assert.AreEqual(NamedEntityType.Location, entities[2].Type);
            Assert.AreEqual(NamedEntitySubType.None, entities[2].SubType);

            Assert.AreEqual(NamedEntityType.PhoneNumber, entities[3].Type);
            Assert.AreEqual(NamedEntitySubType.None, entities[3].SubType);

            Assert.AreEqual(NamedEntityType.Email, entities[4].Type);
            Assert.AreEqual(NamedEntitySubType.None, entities[4].SubType);

            Assert.AreEqual(NamedEntityType.DateTime, entities[5].Type);
            Assert.AreEqual(NamedEntitySubType.None, entities[5].SubType);

            Assert.AreEqual(NamedEntityType.DateTime, entities[6].Type);
            Assert.AreEqual(NamedEntitySubType.Date, entities[6].SubType);

            Assert.AreEqual(NamedEntityType.DateTime, entities[7].Type);
            Assert.AreEqual(NamedEntitySubType.Time, entities[7].SubType);

            Assert.AreEqual(NamedEntityType.DateTime, entities[8].Type);
            Assert.AreEqual(NamedEntitySubType.Duration, entities[8].SubType);

            Assert.AreEqual(NamedEntityType.Quantity, entities[9].Type);
            Assert.AreEqual(NamedEntitySubType.Number, entities[9].SubType);

            Assert.AreEqual(NamedEntityType.Quantity, entities[10].Type);
            Assert.AreEqual(NamedEntitySubType.Ordinal, entities[10].SubType);

            Assert.AreEqual(NamedEntityType.Quantity, entities[11].Type);
            Assert.AreEqual(NamedEntitySubType.Percentage, entities[11].SubType);

            Assert.AreEqual(NamedEntityType.Quantity, entities[12].Type);
            Assert.AreEqual(NamedEntitySubType.Currency, entities[12].SubType);

            Assert.AreEqual(NamedEntityType.Quantity, entities[13].Type);
            Assert.AreEqual(NamedEntitySubType.Dimension, entities[13].SubType);

            Assert.AreEqual(NamedEntityType.Quantity, entities[14].Type);
            Assert.AreEqual(NamedEntitySubType.Temperature, entities[14].SubType);
        }
Exemplo n.º 3
0
        public async Task RecognizeEntitiesWithLanguageTest()
        {
            TextAnalyticsClient client = GetClient();
            string input = "Microsoft fue fundado por Bill Gates y Paul Allen.";

            RecognizeEntitiesResult result = await client.RecognizeEntitiesAsync(input, "es");

            IReadOnlyCollection <NamedEntity> entities = result.NamedEntities;

            Assert.AreEqual(3, entities.Count);
        }
        private Dictionary <string, List <string> > GetEntities(RecognizeEntitiesResult document)
        {
            var entitiesResult = new Dictionary <string, List <string> >();

            document.Entities
            .GroupBy(entities => (string)entities.Category)
            .ToList()
            .ForEach(group =>
            {
                var category = group.Key;
                var entities = group.Select(entity => entity.Text).ToList();
                entitiesResult.Add(category, entities);
            });
            return(entitiesResult);
        }
Exemplo n.º 5
0
        public async Task RecognizeEntitiesWithSubtypeTest()
        {
            TextAnalyticsClient client = GetClient();
            string input = "I had a wonderful trip to Seattle last week.";

            RecognizeEntitiesResult result = await client.RecognizeEntitiesAsync(input);

            IReadOnlyCollection <NamedEntity> entities = result.NamedEntities;

            Assert.AreEqual(2, entities.Count);

            foreach (NamedEntity entity in entities)
            {
                if (entity.Text == "last week")
                {
                    Assert.IsTrue(entity.SubType != NamedEntitySubType.None);
                }
            }
        }
Exemplo n.º 6
0
        public void RecognizePiiEntities()
        {
            string endpoint        = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_ENDPOINT");
            string subscriptionKey = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_SUBSCRIPTION_KEY");

            // Instantiate a client that will be used to call the service.
            var client = new TextAnalyticsClient(new Uri(endpoint), subscriptionKey);

            string input = "A developer with SSN 859-98-0987 whose phone number is 206-867-5309 is building tools with our APIs.";

            Debug.WriteLine($"Recognizing PII entities for input: \"{input}\"");
            RecognizeEntitiesResult           result   = client.RecognizePiiEntities(input);
            IReadOnlyCollection <NamedEntity> entities = result.NamedEntities;

            Debug.WriteLine($"Recognized {entities.Count()} PII entit{(entities.Count() > 1 ? "ies" : "y")}:");
            foreach (NamedEntity entity in entities)
            {
                Debug.WriteLine($"Text: {entity.Text}, Type: {entity.Type}, SubType: {entity.SubType ?? "N/A"}, Score: {entity.Score}, Offset: {entity.Offset}, Length: {entity.Length}");
            }
        }
Exemplo n.º 7
0
        public void RecognizeEntities()
        {
            string endpoint        = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_ENDPOINT");
            string subscriptionKey = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_SUBSCRIPTION_KEY");

            // Instantiate a client that will be used to call the service.
            var client = new TextAnalyticsClient(new Uri(endpoint), subscriptionKey);

            string input = "Microsoft was founded by Bill Gates and Paul Allen.";

            Debug.WriteLine($"Recognizing entities for input: \"{input}\"");
            RecognizeEntitiesResult           result   = client.RecognizeEntities(input);
            IReadOnlyCollection <NamedEntity> entities = result.NamedEntities;

            Debug.WriteLine($"Recognized {entities.Count()} entities:");
            foreach (NamedEntity entity in entities)
            {
                Debug.WriteLine($"Text: {entity.Text}, Type: {entity.Type}, SubType: {entity.SubType ?? "N/A"}, Score: {entity.Score}, Offset: {entity.Offset}, Length: {entity.Length}");
            }
        }
        public async Task RecognizeEntitiesAsync()
        {
            string endpoint        = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_ENDPOINT");
            string subscriptionKey = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_SUBSCRIPTION_KEY");

            var client = new TextAnalyticsClient(new Uri(endpoint), subscriptionKey);

            #region Snippet:RecognizeEntitiesAsync
            string input = "Microsoft was founded by Bill Gates and Paul Allen.";

            RecognizeEntitiesResult result = await client.RecognizeEntitiesAsync(input);

            IReadOnlyCollection <NamedEntity> entities = result.NamedEntities;

            Console.WriteLine($"Recognized {entities.Count()} entities:");
            foreach (NamedEntity entity in entities)
            {
                Console.WriteLine($"Text: {entity.Text}, Type: {entity.Type}, SubType: {entity.SubType ?? "N/A"}, Score: {entity.Score}, Offset: {entity.Offset}, Length: {entity.Length}");
            }
            #endregion
        }
Exemplo n.º 9
0
        public async Task RecognizeEntitiesTest()
        {
            TextAnalyticsClient client = GetClient();
            string input = "Microsoft was founded by Bill Gates and Paul Allen.";

            RecognizeEntitiesResult result = await client.RecognizeEntitiesAsync(input);

            IReadOnlyCollection <NamedEntity> entities = result.NamedEntities;

            Assert.AreEqual(3, entities.Count);

            var entitiesList = new List <string> {
                "Bill Gates", "Microsoft", "Paul Allen"
            };

            foreach (NamedEntity entity in entities)
            {
                Assert.IsTrue(entitiesList.Contains(entity.Text));
                Assert.IsNotNull(entity.Score);
                Assert.IsNotNull(entity.Offset);
                Assert.IsNotNull(entity.Length);
                Assert.Greater(entity.Length, 0);
            }
        }