Module azure.textanalytics

ballerinax/azure.textanalytics Ballerina library

1.5.1

Overview

This is a generated connector for Azure Text Analytics API v1 OpenAPI specification. The Text Analytics API is a suite of natural language processing (NLP) services built with best-in-class Microsoft machine learning algorithms. The API can be used to analyze unstructured text for tasks such as sentiment analysis, key phrase extraction and language detection. Functionality for analysis of text specific to the healthcare domain and personal information are also available in the API. Further documentation can be found here

This module supports Azure Text Analytics API v1.

Prerequisites

Before using this connector in your Ballerina application, complete the following:

Quickstart

To use the Azure Text Analytics connector in your Ballerina application, update the .bal file as follows:

Step 1: Import connector

Import the ballerinax/azure.textanalytics module into the Ballerina project.

Copy
import ballerinax/azure.textanalytics;

Step 2: Create a new connector instance

You can now make the connection configuration using Ocp-Apim-Subscription-Key.

You can do this step in two ways. You can use any one of this.

  • Option 1 : Configure API Keys in ballerina file directly.

    Copy
    nalytics:ApiKeysConfig apiKeyConfig = {
    cpApimSubscriptionKey:"<AZURE_API_KEY>"
    ubscriptionKey: "<Subscription Key>"
    
    
    nalytics:Client myClient = check new Client(apiKeyConfig, serviceUrl = "https://<REGION>.api.cognitive.microsoft.com/text/analytics/v3.1");
  • Option 2 : Configure API Keys in Config.toml file and configure it in ballerina file, using configurables.

    1. Set up API Keys in Config.toml as shown below.
    [apiKeyConfig]
    ocpApimSubscriptionKey = "<AZURE_API_KEY>"
    subscriptionKey = "<Subscription Key>"
    
    1. Configure the client in ballerina file as shown below.
    Copy
    configurable ApiKeysConfig & readonly apiKeyConfig = ?;
    
    textanalytics:Client myClient = check new Client(apiKeyConfig, serviceUrl = "https://<REGION>.api.cognitive.microsoft.com/text/analytics/v3.1");

Step 3: Invoke connector operation

  1. Now you can use the operations available within the connector. Note that they are in the form of remote operations.

    Following is an example on how to use sentiment prediction. The API returns a sentiment prediction, as well as sentiment scores for each sentiment class (Positive, Negative, and Neutral) for the document and each sentence within it.

    Sentiment Prediction

    Copy
    public function main() returns error? {
    
        textanalytics:MultiLanguageBatchInput payload = {
            "documents": [
                {
                "id": "string",
                "text": "string",
                "language": "string"
            }
        ]};
    
        textanalytics:SentimentResponse res = check baseClient->sentiment(payload);
    
    }
  2. Use bal run command to compile and run the Ballerina program.

Import

import ballerinax/azure.textanalytics;Copy

Metadata

Released date: 10 months ago

Version: 1.5.1

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: 2201.4.1

GraalVM compatible: Yes


Pull count

Total: 

Current verison: 0


Weekly downloads


Source repository


Keywords

IT Operations/Cloud Services
Cost/Paid
Vendor/Microsoft

Contributors

Other versions

See more...