Skip to content

Latest commit

 

History

History
93 lines (55 loc) · 4.67 KB

File metadata and controls

93 lines (55 loc) · 4.67 KB

Azure Text Analytics Client library for JavaScript

This package contains an isomorphic SDK for Azure Text Analytics Client.

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 in https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview

Source code | Package (NPM) | API reference documentation | Samples

Getting started

Currently supported environments

  • Node.js version 8.x.x or higher

Prerequisites

Install the @azure/ai-text-analytics package

Install the Azure Text Analytics Client library for Javascript with npm:

npm install @azure/ai-text-analytics

Create and authenticate a TextAnalyticsClient

To create a client object to access the Text Analytics API, you will need the endpoint of your Text Analytics resource and a credential. The Azure Text Analytics Client can use Azure Active Directory credentials to authenticate.

You can find the endpoint for your Text Analytics resource in the Azure Portal.

Using an Azure Active Directory Credential

Client API key authentication is used in most of the examples, but you can also authenticate with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below, or other credential providers provided with the Azure SDK, please install the @azure/identity package:

npm install @azure/identity

You will also need to register a new AAD application and grant access to Text Analytics by assigning the suitable role to your service principal (note: roles such as "Owner" will not grant the necessary permissions).

Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.

const { TextAnalyticsClient } = require("@azure/ai-text-analytics");
const { DefaultAzureCredential } = require("@azure/identity");

const client = new TextAnalyticsClient("<endpoint>", new DefaultAzureCredential());

Key concepts

TextAnalyticsClient

TextAnalyticsClient is the primary interface for developers using the Azure Text Analytics Client library. It provides asynchronous methods to access a specific use of Text Analytics.

Troubleshooting

Logging

Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the AZURE_LOG_LEVEL environment variable to info. Alternatively, logging can be enabled at runtime by calling setLogLevel in the @azure/logger:

import { setLogLevel } from "@azure/logger";

setLogLevel("info");

For more detailed instructions on how to enable logs, you can look at the @azure/logger package docs.

Next steps

Please take a look at the samples directory for detailed examples on how to use this library.

Contributing

If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.

Related projects

Impressions