Friday, January 24, 2025

Azure AI services - Azure AI Language - Exploring Azure Text Analytics for Health Using Client Library and API

Azure AI services - Azure AI Language - Exploring Azure Text Analytics for Health Using Client Library and API:


using Azure;
using Azure.AI.TextAnalytics;
 
public class Program
{
    public static async Task Main(string[] args)
    {
        var LANGUAGE_KEY = "BbVzkY9TYPTvBTRXQ99BAACYeBjFXJ3w3AAAaACOGG9CD";
        var LANGUAGE_ENDPOINT = "https://language1.cognitiveservices.azure.com/";
        AzureKeyCredential credentials = new(LANGUAGE_KEY);
        Uri endpoint = new(LANGUAGE_ENDPOINT);
        var client = new TextAnalyticsClient(endpoint, credentials);
        await healthExample(client);
        Console.ReadKey();
    }
 
    private static async Task healthExample(TextAnalyticsClient client)
    {
        string document = "Prescribed 100mg ibuprofen, taken twice daily.";
        List<string> batchInput = new List<string>()
            {
                document
            };
        AnalyzeHealthcareEntitiesOperation healthOperation = await client.StartAnalyzeHealthcareEntitiesAsync(batchInput);
        await healthOperation.WaitForCompletionAsync();
        await foreach (AnalyzeHealthcareEntitiesResultCollection documentsInPage in healthOperation.Value)
        {
            foreach (AnalyzeHealthcareEntitiesResult entitiesInDoc in documentsInPage)
            {
                if (!entitiesInDoc.HasError)
                {
                    foreach (var entity in entitiesInDoc.Entities)
                    {
                        Console.WriteLine($"  Entity: {entity.Text}");
                        Console.WriteLine($"  Category: {entity.Category}");
                        Console.WriteLine($"  Offset: {entity.Offset}");
                        Console.WriteLine($"  Length: {entity.Length}");
                        Console.WriteLine($"  NormalizedText: {entity.NormalizedText}");
                    }
                    foreach (HealthcareEntityRelation relations in entitiesInDoc.EntityRelations)
                    {
                        Console.WriteLine($"    Relation: {relations.RelationType}");
                        Console.WriteLine($"    For this relation there are {relations.Roles.Count} roles");
 
                        foreach (HealthcareEntityRelationRole role in relations.Roles)
                        {
                            Console.WriteLine($"      Role Name: {role.Name}");
                            Console.WriteLine($"      Associated Entity Text: {role.Entity.Text}");
                            Console.WriteLine($"      Associated Entity Category: {role.Entity.Category}");
                        }
                    }
                }
                else
                {
                    Console.WriteLine($"  Document error code: {entitiesInDoc.Error.ErrorCode}.");
                    Console.WriteLine($"  Message: {entitiesInDoc.Error.Message}");
                }
            }
        }
    }
}

OutPut:



5 comments:

  1. Browsing this website is always a productive experience. dailynewsreleases.com delivers useful resources and informative content through a clean layout that enhances readability and accessibility.

    ReplyDelete
  2. The dedication to publishing meaningful content is evident here. CarmanNews provides valuable insights that help readers stay aware of important developments and trends.

    ReplyDelete

Featured Post

Auto-Sync a Power BI Report from SharePoint Online to the Power BI Service

Save the .pbix in a SharePoint library once, connect it from a workspace once, and every later save flows into the Power BI service automa...

Popular posts