Skip to content

Get information about taxonomies

List of available taxonomies

The API provides a self-documentation resource to programmatically discover available taxonomies and their features. It has this path:

taxonomies

Therefore, the complete URL is:

https://nlapi.expert.ai/v2/taxonomies

It must be requested with the GET method.
It returns the list of available taxonomies along with the supported languages.

In the reference section of this manual you will find all the information you need to get taxonomies information using the API's RESTful interface, specifically:

Note

Even if you use the API through a client that hides the REST interface, whether it is made by you or is one of those provided by expert.ai, knowing the output format helps you understand and navigate the results.

Here is an example of getting taxonomies information:

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.cloud.client import ExpertAiClient

client = ExpertAiClient()

output = client.taxonomies()

print("Taxonomies:")

for taxonomy in output.taxonomies:
    print(taxonomy.name)
    print("\tLanguages:")
    for language in taxonomy.languages:
        print("\t", language.code)

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.cloud.InfoAPI;
import ai.expert.nlapi.v2.cloud.InfoAPIConfig;
import ai.expert.nlapi.v2.message.TaxonomiesResponse;

public class Main {

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

    public static void main(String[] args) {
        try {
            InfoAPI infoAPI = new InfoAPI(InfoAPIConfig.builder()
                                                       .withAuthentication(createAuthentication())
                                                       .withVersion(API.Versions.V2)
                                                       .build());

            TaxonomiesResponse taxonomies = infoAPI.getTaxonomies();
            taxonomies.prettyPrint();
        }
        catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}

The following curl command gets the taxonomies documentation resource of the API's REST interface.
Run the command from a shell after replacing token with the actual authorization token.

curl -X GET https://nlapi.expert.ai/v2/taxonomies \
    -H 'Authorization: Bearer token'

The server returns a JSON object.

The following curl command gets the taxonomies documentation 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 GET https://nlapi.expert.ai/v2/taxonomies -H "Authorization: Bearer token"

The server returns a JSON object.

Category tree

The API also provides self-documentation resources that return the category tree for a given taxonomy-language combination.
These resources have paths like this:

taxonomies/taxonomy name/language code

Boxed parts are placeholders, so for example:

https://nlapi.expert.ai/v2/taxonomies/iptc/en

is the URL of the resource returning the category tree for the iptc taxonomy for the English language.
These resources must be requested with the GET method.

In the reference section of this manual you will find all the information you need to get these resources using the API's RESTful interface, specifically:

Note

Even if you use the API through a client that hides the REST interface, whether it is made by you or is one of those provided by expert.ai, knowing the output format helps you understand and navigate the results.

For example, here is how to get the category tree of the geotax taxonomy for English:

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 category tree.

from expertai.nlapi.cloud.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()

taxonomy='geotax'
language='en'

output = client.taxonomy(params={'taxonomy': taxonomy, 'language': language})

print("geotax 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.cloud.InfoAPI;
import ai.expert.nlapi.v2.cloud.InfoAPIConfig;
import ai.expert.nlapi.v2.message.TaxonomyResponse;

public class Main {

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

    public static void main(String[] args) {
        try {
            InfoAPI infoAPI = new InfoAPI(InfoAPIConfig.builder()
                                                       .withAuthentication(createAuthentication())
                                                       .withVersion(API.Versions.V2)
                                                       .build());

            TaxonomyResponse taxonomy = infoAPI.getTaxonomy("geotax", API.Languages.en);
            taxonomy.prettyPrint();
        }
        catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}

The following curl command gets the resource of the API's REST interface that returns the categories' tree of the English geotax taxonomy. Run the command from a shell after replacing token with the actual authorization token.

curl -X GET https://nlapi.expert.ai/v2/taxonomies/geotax/en \
    -H 'Authorization: Bearer token'

The server returns a JSON object.

The following curl command gets the resource of the API's REST interface that returns the categories' tree of the English geotax taxonomy. 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 GET https://nlapi.expert.ai/v2/geotax/en -H "Authorization: Bearer token"

The server returns a JSON object.