Import/Export a model

The import and export processes are batch operations on the classification model. The export process allows you to extract all the categories from a model, while the import process allows you to create or update a classification model in batch, instead of adding categories one by one.

You can access both operations by clicking on the corresponding buttons on the sidebar.

The format for both operations is going to be the same, a tsv file (tab separated values) with UTF-8 encoding. This means that you will be able to edit categories massively: you will only need to export them, modify the necessary information, and then import back the file into the model.

To export a model's categories to a file, just click on the sidebar's Export button and it will create a file with the same format required to import a model.

It's important to know that this action doesn't create an exact backup of the model. Fields of the model such as name, language, description or any other configuration are not saved in the export file.

The file does not need to have a specific extension, the only conditions that it must fulfill are that:

  • Each category is defined in a different line.
  • The category definition has the following format:
  • Code\tLabel\tParents\tComments

  • After the line that defines a category, all the other lines related to it will be included and they will be written in any of the following formats:

    \tmandatory\tmandatory term

    \texcluding\texcluding term

    \trelevant\trelevant term

    \tirrelevant\tirrelevant term

    \ttext\ttraining text

    The symbol \t is a tabulation.

This is an example of a possible file:

001\tPlanet Express\t\tPlanet Express employees

002\tProfessor Hubert J. Farnsworth\t001\t

003\tPhilip J. Fry\t001\tThis category is related to Fry

\trelevant\tpizza AND "delivery boy"

\tirrelevant\tbureaucracy

004\tTuranga Leela\t001\t

\trelevant\tcyclops

\trelevant\tpilot

\trelevant\tmutant

005\tHermes Conrad\t001\t

\trelevant\tbureaucracy

\trelevant\tjamaican

006\tZapp Brannigan\t\t

\trelevant\t"democratic order of planets"

007\tBender Bending Rodriguez\t001\tThis category is related to Bender

\trelevant\t"foul mouthed"

\trelevant\t"heavy drinking"

\trelevant\tFlexo

As you can see, each category can have a different format, but if a field does not contain information, you must keep its position in any case.

Important

Training text cannot contain carriage returns, as they would be considered the beginning of another category.

This is the result of importing the file used as an example into an empty model:

Import result

Every import process will result in an import report that will detail how many and which items were created, how many and which items were updated, and which ones failed. For the ones that fail, an error message will provide further information for identifying and then resolving the issue.

Initially, all the items will appear grouped by their result; they can be expanded to see the detail by clicking on the plus sign next to them.

If any of the categories in the file is not imported, the import process will return an alert informing that the import process was not completely successful. The import report will show the detail of which categories generated an error.

Errors in the import process can be related either to the format of the data in the file (incorrect number of fields), or its contents (values not valid, model incoherence, etc.)

There can be errors in the import process, mainly of three types:

Import result with errors

In the report above we can see that:

  • A category was created when we specified an ID that did not exist in the model (entry in line 16).
  • A category that already exists in the model is overwritten with the information defined in the import file (line 7).
  • We get an error if we try to specify rule terms without a category defined (line 1).
  • We get an error if we include a parent code that does not exist in the model (line 2)
  • We get an error if we include the same term in two incompatible term rules, relevant and irrelevant (line 3).
  • We get an error if we don't include the exact keyword that defines a type of term, relvant instead of relevant (line 14).
  • We get an error if the number of fields in the line is not the correct one (line 15).

Important

When a new category fails because of the terms included in it, the category will be created empty in order to avoid propagating the error to any of its children (as if it's not created, then the parent of those categories will not exist) and an error on the term that failed will be listed in the failed section of the import report.

Usually, when you import a model from a file and there is any of the above errors, you may want to correct it and finish importing the model.

A possible way to do it is to correct the affected rows in the import file (shown in the error message) and try to import it again. If everything is correct, the categories that haven't been imported before should now appear in the model.

Did you notice... ?

Unlike the import process in the customization console 1.0, now when you try to import an existing category, the category will be updated.

There is another error that will occur if the amount of categories of your model after the import process exceeds your plan limit. If the import results in this error, other possible errors of the file won’t be shown.

Plan limit error