Skip to content

Full analysis

Full analysis is the sum of all possible document analyses:

Natural Language API resources carrying out full document analysis have paths like this:

analyze/context/language

Boxed parts are placeholders.

In the reference section of this manual you will find all the information you need to perform full document analysis using the API's RESTful interface, specifically:

Even if you use the API through a client that hides the REST interface, whether it is made by you or one offered by expert.ai, the last piece of information is useful as it helps understand the data returned by the API.

Here is an example of performing full document analysis on a short English text:

This example is based on the Python client you can find on GitHub.

The client gets user credentials from two environment variables:

EAI_USERNAME
EAI_PASSWORD

Set those variables with your account credentials before running the sample program below.

The program prints the number of items for each of the output's arrays.

from expertai.nlapi.cloud.client import ExpertAiClient
client = 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'

output = client.full_analysis(body={"document": {"text": text}}, params={'language': language})


# Output arrays size

print("Output arrays size:");

print("knowledge: ", len(output.knowledge))
print("paragraphs: ", len(output.paragraphs))
print("sentences: ", len(output.sentences))
print("phrases: ", len(output.phrases))
print("tokens: ", len(output.tokens))
print("mainSentences: ", len(output.main_sentences))
print("mainPhrases: ", len(output.main_phrases))
print("mainLemmas: ", len(output.main_lemmas))
print("mainSyncons: ", len(output.main_syncons))
print("topics: ", len(output.topics))
print("entities: ", len(output.entities))
print("entities: ", len(output.relations))
print("sentiment.items: ", len(output.sentiment.items))

This example is based on the Java client you can find on GitHub.

The client gets user credentials from two environment variables:

EAI_USERNAME
EAI_PASSWORD

Set those variables with your account credentials before running the sample program below.

The program prints the number of items for each of the output's arrays.

import ai.expert.nlapi.security.Authentication;
import ai.expert.nlapi.security.Authenticator;
import ai.expert.nlapi.security.BasicAuthenticator;
import ai.expert.nlapi.security.DefaultCredentialsProvider;
import ai.expert.nlapi.v2.API;
import ai.expert.nlapi.v2.Analyzer;
import ai.expert.nlapi.v2.AnalyzerConfig;
import ai.expert.nlapi.v2.message.AnalyzeResponse;
import ai.expert.nlapi.v2.model.AnalyzeDocument;

public class Main {

    public static Authentication createAuthentication() throws Exception {
        DefaultCredentialsProvider credentialsProvider = new DefaultCredentialsProvider();
        Authenticator authenticator = new BasicAuthenticator(credentialsProvider);
        return new Authentication(authenticator);
    }

    public static Analyzer createAnalyzer() throws Exception {
        return new Analyzer(AnalyzerConfig.builder()
                                      .withVersion(API.Versions.V2)
                                      .withContext("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();

            AnalyzeResponse analysis = analyzer.analyze(text);


            // Output JSON representation

            System.out.println("JSON representation:");
            analysis.prettyPrint();


            // Output arrays size

            System.out.println("Output arrays size:");
            AnalyzeDocument data = analysis.getData();

            System.out.println("knowledge: " + data.getKnowledge().size());
            System.out.println("paragraphs: " + data.getParagraphs().size());
            System.out.println("sentences: " + data.getSentences().size());
            System.out.println("phrases: " + data.getPhrases().size());
            System.out.println("tokens: " + data.getTokens().size());
            System.out.println("mainSentences: " + data.getMainSentences().size());
            System.out.println("mainPhrases: " + data.getMainPhrases().size());
            System.out.println("mainLemmas: " + data.getMainLemmas().size());
            System.out.println("mainSyncons: " + data.getMainSyncons().size());
            System.out.println("topics: " + data.getTopics().size());
            System.out.println("entities: " + data.getEntities().size());
            System.out.println("relations: " + data.getRelations().size());
            System.out.println("sentiment/items: " + data.getSentiment().getItems().size());
        }
        catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}

The following curl command posts a document to the full document analysis resource of the API's REST interface.
Run the command from a shell after replacing token with the actual authorization token.

curl -X POST https://nlapi.expert.ai/v2/analyze/standard/en \
    -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'\''s stand-out skill, but he still holds a defensive NBA record, with eight steals in a half."
  }
}'

The server returns a JSON object.

The following curl command posts a document to the full document analysis resource of the API's REST interface.
Open a command prompt in the folder where you installed curl and run the command after replacing token with the actual authorization token.

curl -X POST https://nlapi.expert.ai/v2/analyze/standard/en  -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's stand-out skill, but he still holds a defensive NBA record, with eight steals in a half.\"}}"

The server returns a JSON object.