-
Notifications
You must be signed in to change notification settings - Fork 36
Analyse text
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.
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')
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
})
A Response is generated after a call to the analyseText Request method.
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 |
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
}
})
Method | Params | Return |
---|---|---|
get(name) | name: String | Entity: the first Entity matched |
request.analyseText('YOUR_TEXT')
.then(function(res) {
var location = res.get('location')
})
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')
})
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 |
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 |
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 |
For more information, do not hesitate to dive deeper in the code, as it is commented.