Skip to content

Templates

A template is the set of fields that information extraction can fill with data.

The API provides a self-documentation resource returning all the defined templates.

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 templates:

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

client = ExpertAiClient()

output = client.templates()

print("Templates:")

for template in output.templates:
  print(template.name)
  for field in template.fields:
    print(field.name)

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.TemplatesModelResponse;
import ai.expert.nlapi.v2.model.TemplateNamespace;

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();

            TemplatesModelResponse templModelResponse = model.templates();
            List<TemplateNamespace> templates = templModelResponse.getData();
        }
        catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}

The server returns a JSON object.