Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

azure-cognitiveservices-textanalytics

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

azure-cognitiveservices-textanalytics

TextAnalyticsClient Library with typescript type definitions for node

  • 2.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Microsoft Azure SDK for Node.js - Cognitive Services Text Analytics

This project provides a Node.js package that makes it easy to work with the Microsoft Azure Cognitive Services Text Analytics API. Right now it supports:

  • Node.js version: 6.x or higher

How to Install

npm install azure-cognitiveservices-textanalytics

How to use

Create a Cognitive Services Account(ex. Text Analytics)

  const msRestAzure = require('ms-rest-azure');
  const CognitiveServicesManagement = require("azure-arm-cognitiveservices");
  let client;
  let createAccount = msRestAzure.interactiveLogin().then((credentials) => {
    client = new CognitiveServicesManagement(credentials, suite.subscriptionId);
    return client.accounts.create('groupname', 'accountname', {
      sku: {
        name: "F0"
      },
      kind: "TextAnalytics",
      location: "westus",
      properties: {}
    });
  }).catch((err) => {
    console.log('An error ocurred');
    console.dir(err, {depth: null, colors: true});
  });

List the keys from the created account

  let serviceKey;
  createAccount.then((result) => {
    return client.accounts.listKeys('groupname', 'accountname');
  }).then((result) => {
    serviceKey = result.key1;
    console.log(result.key2);
  }).catch((err) => {
    console.log('An error ocurred');
    console.dir(err, {depth: null, colors: true});
  });

Create credentials

const CognitiveServicesCredentials = require('ms-rest-azure').CognitiveServicesCredentials;

// Creating the Cognitive Services credentials
// This requires a key corresponding to the service being used (i.e. text-analytics, etc)
let credentials = new CognitiveServicesCredentials(serviceKey);

Text Analytics API

const TextAnalyticsAPIClient = require('azure-cognitiveservices-textanalytics');

let client = new TextAnalyticsAPIClient(credentials);
let input = {
   documents: [
       {
       'id': "1",
       'text': "I had a wonderful experience! The rooms were wonderful and the staff was helpful."
       }
   ]
}
let operation = client.detectLanguage(input)
operation.then(function (result){
  console.log(result.documents[0].detectedLanguages[0].name);
  console.log(result.documents[0].detectedLanguages[0].score);
}).catch(function (err){
  throw err;
});

More Detailed Information

https://azure.microsoft.com/en-us/try/cognitive-services/ under "Language"

Keywords

FAQs

Package last updated on 07 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc