-
Notifications
You must be signed in to change notification settings - Fork 20
01 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 analyse_text and analyse_file methods.
Start by instantiating either a Client or a Request object, as shown below:
import sapcai
client = new sapcai.Client('YOUR_TOKEN')
request = client.request
# ...is the same as...
request = sapcai.Request('YOUR_TOKEN')
Use the analyse_text 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.
response = request.analyse_text('YOUR_TEXT')
# get the intent detected
intent = response.intent
# get all the location entities extracted from your text
locations = response.all('location')
# Do your code
Use the analyse_file method of the client, and after a call to our API, we return you a Response object containing the enriched entities extracted from your speech, the intents detected and some other useful information.
Please note that the length of the audio is limited to 10 seconds by call.
response = request.analyse_file('YOUR_FILE')
# get the intent detected
intent = response.intent
# get all the location entities extracted from your text
locations = response.all('location')
# Do your code
A Response is generated after a call to either analyse_text or analyse_file Request methods.
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 | Array[Entity]: the array of entities |
language | String: the language of the input |
processing_language | String: the language used to process 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 |
response = request.analyse_text('YOUR_TEXT')
intent = response.intent
if (intent.slug === 'geetings' && intent.confidence > 0.7):
# Do your code
Method | Params | Return |
---|---|---|
get(name) | name: String | Entity: the first Entity matched |
response = request.analyse_text('YOUR_TEXT')
location = response.get('location')
Method | Params | Return |
---|---|---|
all(name) | name: String | Array[Entity]: all the Entities matched |
response = request.analyse_text('YOUR_TEXT')
locations = response.all('location')
Method | Params | Return |
---|---|---|
is_assert | Bool: whether or not the act is an assertion | |
is_command | Bool: whether or not the act is a command | |
is_wh_query | Bool: whether or not the act is a question | |
is_yn_query | Bool: whether or not the act is a query |
Method | Params | Return |
---|---|---|
is_abbreviation | Bool: whether or not the sentence is asking for an abbreviation | |
is_entity | Bool: whether or not the sentence is asking for an entity | |
is_description | Bool: whether or not the sentence is asking for a description | |
is_Human | Bool: whether or not the sentence is asking for a human | |
is_location | Bool: whether or not the sentence is asking for a location | |
is_number | Bool: whether or not the sentence is asking for a number |
Method | Params | Return |
---|---|---|
is_vpositive | Bool: whether or not the sentiment is very positive | |
is_positive | Bool: whether or not the sentiment is positive | |
is_neutral | Bool: whether or not the sentiment is neutral | |
is_negative | Bool: whether or not the sentiment is negative | |
is_vnegative | 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.