Skip to content

3. Make your first call

Once you have a client tool set up, you can try out named entity recognition on a short English text.

First call with curl

Run the following command from a shell after replacing the string token (only that, the string Bearer must not be changed) with the actual authorization token you obtained in the previous step:

curl -X POST https://nlapi.expert.ai/v1/analyze/standard/en/entities \
    -H 'Authorization: Bearer token' \
    -H 'Content-Type: application/json; charset=utf-8' \
    -d '{
  "document": {
    "text" : "Michael Jordan was one of the best basketball players of all time. Scoring was Jordan stand-out skill, but he still holds a defensive NBA record, with eight steals in a half."
  }
}'

Open a command prompt in the folder where you installed curl and run the following command after replacing the string token (only that, the string Bearer must not be changed) with the actual authorization token you obtained in the previous step:

curl -X POST https://nlapi.expert.ai/v1/analyze/standard/en/entities -H "Authorization: Bearer token" -H "Content-Type: application/json"  -d "{\"document\": {\"text\": \"Michael Jordan was one of the best basketball players of all time. Scoring was Jordan stand-out skill, but he still holds a defensive NBA record, with eight steals in a half.\"}}"

The command result is a JSON object containing recognized entities.

First call with Postman

  1. Run Postman.
  2. Right-click the expert.ai Natural Language API collection and select Edit from the contextual menu.
  3. Select the Variables tab.
  4. Set the current value of variable token to the actual authorization token.
  5. Select Update.
  6. Expand the expert.ai Natural Language API collection.
  7. Expand the Document analysis folder.
  8. Select entities.
  9. Select Send in the right panel. The result is a JSON object containing recognized entities.

First call with SDK

The SDK's API client is able to obtain the authorization token by itself, you only need to provide your account credentials.
The client gets the credentials from two environment variables:

EAI_USERNAME
EAI_PASSWORD

Set those variables before running the script below.

The script prints a JSON object containing the entities recognized in a short English text.

from expertai.client import ExpertAiClient
eai = ExpertAiClient()

text = "Michael Jordan was one of the best basketball players of all time. Scoring was Jordan's stand-out skill, but he still holds a defensive NBA record, with eight steals in a half."
language= 'en'

response = eai.specific_resource_analysis(body={"document": {"text": text}}, params={'language': language, 'resource': 'entities'})


# Output JSON representation

print(response.json)

The SDK's API client is able to obtain the authorization token by itself, you only need to replace yourusername and yourpassword in the line of code highlighted below with your account credentials.

The program prints a JSON object containing the entities recognized in a short English text.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import ai.expert.nlapi.security.Authentication;
import ai.expert.nlapi.security.Authenticator;
import ai.expert.nlapi.security.BasicAuthenticator;
import ai.expert.nlapi.security.Credential;
import ai.expert.nlapi.v1.API;
import ai.expert.nlapi.v1.Analyzer;
import ai.expert.nlapi.v1.AnalyzerConfig;
import ai.expert.nlapi.v1.message.ResponseDocument;
import ai.expert.nlapi.v1.model.DataModel;

public class Main {

    public static Authentication createAuthentication() throws Exception {
        Authenticator authenticator = new BasicAuthenticator(new Credential("avarone@expertsystem.com", "86vVav!96"));
        return new Authentication(authenticator);
    }

    public static Analyzer createAnalyzer() throws Exception {
        return new Analyzer(AnalyzerConfig.builder()
                                          .withVersion(API.Versions.V1)
                                          .withContext(API.Contexts.STANDARD)
                                          .withLanguage(API.Languages.en)
                                          .withAuthentication(createAuthentication())
                                          .build());
    }

    public static void main(String[] args) {
        try {
            String text = "Michael Jordan was one of the best basketball players of all time. Scoring was Jordan's stand-out skill, but " +
                          "he still holds a defensive NBA record, with eight steals in a half.";

            Analyzer analyzer = createAnalyzer();

            ResponseDocument entities = analyzer.entities(text);


            // Output JSON representation

            entities.prettyPrint();
        }
        catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}

The next step

Now that you've had a taste of the API, learn more about using it programmatically.