Skip to content

Categories' tree

The API provides a self-documentation resource that returns the tree of categories detected by document classification.

The resource has the following endpoint:

/api/model

It must be requested using the POST method.
In the reference section of this manual you will find:

Here is an example of getting the categories' tree:

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 list of taxonomies with the language they support.

from expertai.nlapi.edge.client import ExpertAiClient

def printCategory(level, category):
    tabs = "\t" * level
    print(tabs, category.id, "(", category.label, ")")
    for nestedCategory in category.categories:
        printCategory(level + 1, nestedCategory)

client = ExpertAiClient()

output = client.taxonomy()

print("Custom categories' tree:")

for category in output.taxonomy[0].categories:
    printCategory(1, category)

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 JSON response.

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.edge.Model;
import ai.expert.nlapi.v2.edge.ModelConfig;
import ai.expert.nlapi.v2.message.TaxonomyModelResponse;
import ai.expert.nlapi.v2.model.Taxonomy;

import java.util.List;

public class Main {

    public static Model createModel() throws Exception {
        return new Model(ModelConfig.builder()
                     .withVersion(API.Versions.V2)
                     .withHost(API.DEFAULT_EDGE_HOST)
                     .build());
    }

    public static void main(String[] args) {
        try {
            Model model = createModel();

            TaxonomyModelResponse taxModelResponse = model.taxonomy();
            List<Taxonomy> taxonomies = taxModelResponse.getData();
        }
        catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}

The server returns a JSON object.