Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Analyse text

Jasmine Anteunis edited this page Jan 15, 2019 · 21 revisions

You can use the SAP Conversational AI API to analyse your text or your audio file, and extract useful information from it.

You can jump at the end of this page if you're looking for more details on the Response returned by the calls to analyseText method.

Usage

Start by instantiating either a Client or a Request object, as shown below:

var sapcai = require('sapcai').default

var client = new sapcai('YOUR_TOKEN')
var request = client.request

// ...is the same as...

var request = new sapcai.request('YOUR_TOKEN')

Text analysis

Use the analyseText method of the client, and after a call to our API, we return a Response object containing the enriched entities extracted from your text, the intents detected and some additional information.

Please note that the length of the text is limited to 512 chars by call.

request.analyseText('YOUR_TEXT')
  .then(function(res) {
    // get the intent detected
    var intent = res.intent()

    // get all the location entities extracted from your text
    var locations = res.all('location')

    // Do your code
  }).catch(function(err) {
    // Handle error
  })

Response

A Response is generated after a call to the analyseText Request method.

Attributes

An instance of the Response class provides each of the following attributes:

Attributes Type
raw String: the raw unparsed json response
uuid String: the uuid of the request
source String: the user input
intents Array[object]: all the matched intents
act String: the act of the processed sentence
type String: the type of the processed sentence
sentiment String: the sentiment of the processed sentence
entities Object[Key: String (Entity Name), Value: Entity]: the array of entities
processing_language String: the language used to process the input
language String: the language of the input
version String: the version of the json
timestamp String: the timestamp at the end of the processing
status String: the status of the response

Methods

Get the first detected intent

Method Params Return
intent() Object: the first detected intent
request.analyseText('YOUR_TEXT')
  .then(function(res) {

    var intent = res.intent()

    if (intent.slug === 'geetings' && intent.confidence > 0.7) {
      // Do your code
    }

  })

Get one entity

Method Params Return
get(name) name: String Entity: the first Entity matched
request.analyseText('YOUR_TEXT')
  .then(function(res) {

    var location = res.get('location')

  })

Get all entities matching name

Method Params Return
all(name) name: String Array[Entity]: all the Entities matched
request.analyseText('YOUR_TEXT')
  .then(function(res) {

    var locations = res.all('location')

  })

Act helpers

Method Params Return
isAssert() Bool: whether or not the act is an assertion
isCommand() Bool: whether or not the act is a command
isWhQuery() Bool: whether or not the act is a question
isYnQuery() Bool: whether or not the act is a query

Type helpers

Method Params Return
isAbbreviation() Bool: whether or not the sentence is asking for an abbreviation
isEntity() Bool: whether or not the sentence is asking for an entity
isDescription() Bool: whether or not the sentence is asking for a description
isHuman() Bool: whether or not the sentence is asking for a human
isLocation() Bool: whether or not the sentence is asking for a location
isNumber() Bool: whether or not the sentence is asking for a number

Sentiment helpers

Method Params Return
isVPositive() Bool: whether or not the sentiment is very positive
isPositive() Bool: whether or not the sentiment is positive
isNeutral() Bool: whether or not the sentiment is neutral
isNegative() Bool: whether or not the sentiment is negative
isVNegative() Bool: whether or not the sentiment is very negative

More

For more information, do not hesitate to dive deeper in the code, as it is commented.