imerit_ango.sdk.SDK.
create_label_set(project_id, tools, classifications, relations, raw_category_schema)
Create and set the project's ontology.
As this method is more complex than others, we recommend also consulting the examples at the end of this section.
Parameters
tools: List[ToolCategory], optional
List of tools that will be added to the label set.
Example: [ToolCategory(Tool.Segmentation, title="SegmentationTool")]
classifications: List[ClassificationCategory], optional, default None
List of classifications that will be added to the label set.
Example: [ClassificationCategory(Classification.Single_dropdown, title = "Choice", options=[LabelOption("First"), LabelOption("Second")])]
relations: List[RelationCategory], optional, default None
List of relations that will be added to the label set.
Example: [RelationCategory(Relation.Single, title="SingleRelationTool")]
raw_category_schema : Dict, optional, default None
Instead of creating the label set (category schema) using the previous 'tools', 'classifications', and 'relations' parameters, you may pass here a dictionary representing the entire category schema.
See the section below for an example.
To get an example of what can be passed as the raw_category_schema
, there are two ways:
Using the SDK itself, get the category schema from another existing project. This will also allow you to programmatically copy the category schema between two projects, like so:
Example Code
Copy import os
from dotenv import load_dotenv
from imerit_ango . sdk import SDK
load_dotenv ( 'variables.env' )
api_key = os . getenv ( 'API_KEY' )
project_id = os . getenv ( 'PROJECT_ID' )
ango_sdk = SDK (api_key)
# Extract category schema info from the existing project
existing_project = ango_sdk . get_project (project_id = "<EXISTING_PROJECT_ID>" )
cat_schema = existing_project . get ( "data" ). get ( "project" ). get ( "categorySchema" )
# Create a new project and retrieve the ID of the newly created project
new_project = ango_sdk . create_project ( "New Project Title" , "New Project Description" )
new_project_id = new_project . get ( "data" ). get ( "project" ). get ( "_id" )
# Add new category schema to newly created project
ango_sdk . create_label_set (project_id = new_project_id, raw_category_schema = cat_schema)
As an example, a raw_category_schema
obtained from a project could be this:
Sample Category Schema
Copy {
"tools" : [
{
"title" : "Vehicle" ,
"tool" : "bounding-box" ,
"required" : false ,
"schemaId" : "c053da596995f93c2c71520" ,
"ocrEnabled" : false ,
"classifications" : [] ,
"multiple" : false ,
"color" : "#f44336" ,
"shortcutKey" : "1"
}
] ,
"classifications" : [
{
"title" : "Color" ,
"tool" : "radio" ,
"required" : false ,
"schemaId" : "75c02176796c17e7c657955" ,
"frameSpecific" : false ,
"classifications" : [] ,
"multiple" : false ,
"options" : [
{
"value" : "Red" ,
"schemaId" : "95df97dc43d2e1dcc77d536"
} ,
{
"value" : "Yellow" ,
"schemaId" : "f477d05947e30259cc53538"
} ,
{
"value" : "Blue" ,
"schemaId" : "18a8212c7c48c2ee3464602"
}
] ,
"shortcutKey" : "2"
}
] ,
"relations" : []
}
Label Set Classes
ToolCategory:
ToolCategory Parameters:
tool: Tool
The tool type. ex.: Tool.Segmentation
title: string, default ""
required: bool, default None
Whether annotators are required to draw at least one instance of this tool.
schemaId: string, default None
Sets the tool's schemaId.
columnField: bool, default False
Whether this tool should be a table column.
color: string, default ""
The color assigned to this labeling tool, in the format "#FFFFFF"
shortcutKey: string, default ""
The shortcut to quickly select this tool, "0"-"9", "ctrl+0"-"ctrl+9", "a"-"k"
classifications: List[ClassificationCategory], default []
List of nested classifications, if any
options: List[LabelOption], default []
The tool's answers (options.)
ClassificationCategory :
ClassificationCategory Parameters:
classification: Classification
The classification type. ex.:Classification.Tree_dropdown
title: string, default ""
The title of the classification.
required: bool, default None
Whether annotators have to answer this classification or not.
schemaId: string, default None
Sets the classification's Schema ID.
columnField: bool, default False
Whether this classification should be a table column.
color: string, default ""
The color assigned to this labeling tool, in the format "#FFFFFF"
shortcutKey: string, default ""
The shortcut to quickly select this tool, "0"-"9", "ctrl+0"-"ctrl+9", "a"-"k"
classifications: List, default [ClassificationCategory]
List of nested classifications, if any
options: List[LabelOption], default []
The classification's answers (options.)
treeOptions: List[TreeOption], default []
For trees, the tree's leaves/branches.
parentOptionId: string, default ""
The schema ID of the parent option. That is, the option that the labeler needs to select in order for this classification to appear. Enables conditional nesting.
richText : bool, default False
Set to True to enable the Rich Text editor for the selected text classification tool.
RelationCategory:
RelationCategory Parameters:
relation: Relation
The classification type. ex.:Relation.Single
title: string, default ""
The title of the relation.
required: bool, default None
Whether annotators have to include at least one such relation in order to submit their annotation.
schemaId: string, default None
Sets the schemaId of the relation.
columnField: bool, default False
Whether this relation should be a table column.
color: string, default ""
The color assigned to this relation, in the format "#FFFFFF"
shortcutKey: string, default ""
The shortcut to quickly select this relation, "0"-"9", "ctrl+0"-"ctrl+9", "a"-"k"
classifications: List[ClassificationCategory], default []
List of nested classifications, if any
options: List[LabelOption], default []
The relation's answers (options.)
LabelOption parameters:
value: string
The text of the answer (option.)
schemaId: string, default None
The schema ID of the option. Necessary for conditional nesting.
Returns:
Examples
Example-1: Creating an ontology with:
A Single Dropdown classification, with two choices named "First" and "Second":
Copy import os
from dotenv import load_dotenv
from imerit_ango . sdk import SDK
from imerit_ango . models . label_category import LabelOption , ClassificationCategory , Classification
load_dotenv ( 'variables.env' )
api_key = os . getenv ( 'API_KEY' )
project_id = os . getenv ( 'PROJECT_ID' )
ango_sdk = SDK (api_key)
category = ClassificationCategory (Classification.Single_dropdown,
title = "Choice" ,
options = [ LabelOption ( "First" ),
LabelOption ( "Second" )])
label_set = [category]
response = ango_sdk . create_label_set (project_id = project_id, classifications = label_set)
Resulting category schema
Copy {
"tools" : [] ,
"classifications" : [
{
"treeOptions" : [] ,
"tool" : "single-dropdown" ,
"title" : "Choice" ,
"required" : false ,
"columnField" : false ,
"color" : "#20549F" ,
"shortcutKey" : "" ,
"classifications" : [] ,
"options" : [
{
"value" : "First" ,
"schemaId" : "793a5f9474b64bf5919d943b4cef9b65"
} ,
{
"value" : "Second" ,
"schemaId" : "47e022c1cc9b41aa9a3d000c7bbc6524"
}
] ,
"schemaId" : "e4dd1c6f65a04d51b3ea66d23c92a321" ,
"regex" : null ,
"parentOptionId" : null ,
"frameSpecific" : false ,
"showDropdown" : false ,
"richText" : false
}
] ,
"relations" : []
}
Example-2: Creating an ontology with:
A Single Dropdown classification with the classifications "First" and "Second"
Copy import os
from dotenv import load_dotenv
from imerit_ango . sdk import SDK
from imerit_ango . models . label_category import ClassificationCategory , Classification , LabelOption , Tool , ToolCategory , RelationCategory , Relation
load_dotenv ( 'variables.env' )
api_key = os . getenv ( 'API_KEY' )
project_id = os . getenv ( 'PROJECT_ID' )
ango_sdk = SDK (api_key)
dropdown = ClassificationCategory (Classification.Single_dropdown,
title = "SingleDropdown" ,
options = [ LabelOption ( 'First' ),
LabelOption ( 'Second' )])
classifications = [dropdown]
segmentation = ToolCategory (Tool.Segmentation, title = "SegmentationTool" )
tools = [segmentation]
relation = RelationCategory (Relation.Single, title = "SingleRelationTool" )
relations = [relation]
ango_sdk . create_label_set (project_id = project_id,
tools = tools,
classifications = classifications,
relations = relations)
Resulting category schema
Copy {
"tools" : [
{
"tool" : "segmentation" ,
"title" : "SegmentationTool" ,
"required" : false ,
"columnField" : false ,
"color" : "#8BE297" ,
"shortcutKey" : "" ,
"classifications" : [] ,
"options" : [] ,
"schemaId" : "c51c18700440443695cf1c8239c44360"
}
] ,
"classifications" : [
{
"treeOptions" : [] ,
"tool" : "single-dropdown" ,
"title" : "SingleDropdown" ,
"required" : false ,
"columnField" : false ,
"color" : "#C3C6FF" ,
"shortcutKey" : "" ,
"classifications" : [] ,
"options" : [
{
"value" : "First" ,
"schemaId" : "0c26447159ce4e7790b47da8c4481681"
} ,
{
"value" : "Second" ,
"schemaId" : "e39099d2176a494da89833488cf1f88e"
}
] ,
"schemaId" : "5375ac19fd264d6b9fe07060faaac0d6" ,
"regex" : null ,
"parentOptionId" : null ,
"frameSpecific" : false ,
"showDropdown" : false ,
"richText" : false
}
] ,
"relations" : [
{
"tool" : "one-to-one" ,
"title" : "SingleRelationTool" ,
"required" : false ,
"columnField" : false ,
"color" : "#2D0509" ,
"shortcutKey" : "" ,
"classifications" : [] ,
"options" : [] ,
"schemaId" : "412f56e2fce4479da05470317e2845c8"
}
]
}
Example-3: Creating an ontology with:
A Single Dropdown classification called "Entity Type" with the choices "Vehicle" and "Person"
Another Single Dropdown classification nested inside the first unconditionally (that is, any choice in the first dropdown will open this second) named "Position" with the choices "On Road" and "Off Road".
Copy import os
from dotenv import load_dotenv
from imerit_ango . sdk import SDK
from imerit_ango . models . label_category import ClassificationCategory , LabelOption , Classification
load_dotenv ( 'variables.env' )
api_key = os . getenv ( 'API_KEY' )
project_id = os . getenv ( 'PROJECT_ID' )
ango_sdk = SDK (api_key)
nested_class_in_dropdown = ClassificationCategory (Classification.Single_dropdown,
title = "Position" ,
options = [ LabelOption ( 'On Road' ),
LabelOption ( 'Off Road' )])
dropdown = ClassificationCategory (Classification.Single_dropdown,
title = "Entity Type" ,
options = [ LabelOption ( 'Vehicle' ),
LabelOption ( 'Person' )],
classifications = [nested_class_in_dropdown],
required = True )
classifications = [dropdown]
ango_sdk . create_label_set (project_id = project_id, classifications = classifications)
Resulting category schema
Copy {
"tools" : [] ,
"classifications" : [
{
"treeOptions" : [] ,
"tool" : "single-dropdown" ,
"title" : "Entity Type" ,
"required" : true ,
"columnField" : false ,
"color" : "#96934B" ,
"shortcutKey" : "" ,
"classifications" : [
{
"treeOptions" : [] ,
"tool" : "single-dropdown" ,
"title" : "Position" ,
"required" : false ,
"columnField" : false ,
"color" : "#978D5E" ,
"shortcutKey" : "" ,
"classifications" : [] ,
"options" : [
{
"value" : "On Road" ,
"schemaId" : "8b9cad52f7b84905a697589f402e11e0"
} ,
{
"value" : "Off Road" ,
"schemaId" : "cbd698bc6805461c9ce2380bec54c429"
}
] ,
"schemaId" : "ab3ed5e9422c453d93c2bb02d6461ca3" ,
"regex" : null ,
"parentOptionId" : null ,
"frameSpecific" : false ,
"showDropdown" : false ,
"richText" : false
}
] ,
"options" : [
{
"value" : "Vehicle" ,
"schemaId" : "a21ba3c88b8440738e7945e295ca7545"
} ,
{
"value" : "Person" ,
"schemaId" : "7c13355b336840f9a9eb10def5c04971"
}
] ,
"schemaId" : "9b42eea24ffc405788a4fad64e21af54" ,
"regex" : null ,
"parentOptionId" : null ,
"frameSpecific" : false ,
"showDropdown" : false ,
"richText" : false
}
] ,
"relations" : []
}
Example-4: Creating an ontology with:
Copy import os
from dotenv import load_dotenv
from imerit_ango . sdk import SDK
from imerit_ango . models . label_category import ClassificationCategory , Classification , TreeOption
load_dotenv ( 'variables.env' )
api_key = os . getenv ( 'API_KEY' )
project_id = os . getenv ( 'PROJECT_ID' )
ango_sdk = SDK (api_key)
subtree0 = TreeOption (title = "subtree0" )
subtree1 = TreeOption (title = "subtree1" )
tree0 = TreeOption (title = "tree0" , children = [subtree0, subtree1])
tree1 = TreeOption (title = "tree1" )
tree_tool = ClassificationCategory (classification = Classification.Tree_dropdown,
title = "Tree One" ,
treeOptions = [tree0, tree1])
ango_sdk . create_label_set (project_id = project_id, classifications = [tree_tool])
Resulting category schema
Copy {
"tools" : [] ,
"classifications" : [
{
"treeOptions" : [
{
"title" : "tree0" ,
"children" : [
{
"title" : "subtree0" ,
"children" : [] ,
"key" : "b4188077d99e4f2cb81cb8089977ee02" ,
"value" : "b4188077d99e4f2cb81cb8089977ee02"
} ,
{
"title" : "subtree1" ,
"children" : [] ,
"key" : "1d313ed3c7e54082af5400f1f589fc4c" ,
"value" : "1d313ed3c7e54082af5400f1f589fc4c"
}
] ,
"key" : "bcadecdb205d41e783289638a23ad959" ,
"value" : "bcadecdb205d41e783289638a23ad959"
} ,
{
"title" : "tree1" ,
"children" : [] ,
"key" : "96e3ae4f72c84539a0cfc91d7f48c54c" ,
"value" : "96e3ae4f72c84539a0cfc91d7f48c54c"
}
] ,
"tool" : "tree-dropdown" ,
"title" : "Tree One" ,
"required" : false ,
"columnField" : false ,
"color" : "#9B0EE5" ,
"shortcutKey" : "" ,
"classifications" : [] ,
"options" : [
{
"value" : "tree0" ,
"schemaId" : "bcadecdb205d41e783289638a23ad959"
} ,
{
"value" : "tree0 / subtree0" ,
"schemaId" : "b4188077d99e4f2cb81cb8089977ee02"
} ,
{
"value" : "tree0 / subtree1" ,
"schemaId" : "1d313ed3c7e54082af5400f1f589fc4c"
} ,
{
"value" : "tree1" ,
"schemaId" : "96e3ae4f72c84539a0cfc91d7f48c54c"
}
] ,
"schemaId" : "70d5b1df35764048bfebdec5290d6294" ,
"regex" : null ,
"parentOptionId" : null ,
"frameSpecific" : false ,
"showDropdown" : false ,
"richText" : false
}
] ,
"relations" : []
}
Example-5: Creating an ontology with:
A conditionally nested Text classification tool using the rich text editor, which only appears if the labeler clicks on "Radio Option 1" (here, parentOptionId
links the text tool to the option which reveals it)
Copy import os
from dotenv import load_dotenv
from imerit_ango . sdk import SDK
from imerit_ango . models . label_category import ClassificationCategory , LabelOption , Classification
load_dotenv ( 'variables.env' )
api_key = os . getenv ( 'API_KEY' )
project_id = os . getenv ( 'PROJECT_ID' )
ango_sdk = SDK (api_key)
radio1 = LabelOption (value = "Radio Option 1" , schemaId = "radioOption1SchemaId" )
radio2 = LabelOption (value = "Radio Option 2" )
conditional_text = ClassificationCategory (classification = Classification.Text,
title = "Text Tool" ,
parentOptionId = "radioOption1SchemaId" ,
color = "#333333" ,
richText = True )
radio = ClassificationCategory (classification = Classification.Radio,
title = "Radio Classification" ,
options = [radio1, radio2],
classifications = [conditional_text])
ango_sdk . create_label_set (project_id = project_id, classifications = [radio])
Resulting category schema
Copy {
"tools" : [] ,
"classifications" : [
{
"treeOptions" : [] ,
"tool" : "radio" ,
"title" : "Radio Classification" ,
"required" : false ,
"columnField" : false ,
"color" : "#C9ABFF" ,
"shortcutKey" : "" ,
"classifications" : [
{
"treeOptions" : [] ,
"tool" : "text" ,
"title" : "Text Tool" ,
"required" : false ,
"columnField" : false ,
"color" : "#333333" ,
"shortcutKey" : "" ,
"classifications" : [] ,
"options" : [] ,
"schemaId" : "62d8398f548b4fa4915e639cf4180fbc" ,
"regex" : null ,
"parentOptionId" : "radioOption1SchemaId" ,
"frameSpecific" : false ,
"showDropdown" : false ,
"richText" : true
}
] ,
"options" : [
{
"value" : "Radio Option 1" ,
"schemaId" : "radioOption1SchemaId"
} ,
{
"value" : "Radio Option 2" ,
"schemaId" : "8daa04c07bd6462294a45870c9c4fa49"
}
] ,
"schemaId" : "b79f2aeda12346eea6bf16ab5dc0c84f" ,
"regex" : null ,
"parentOptionId" : null ,
"frameSpecific" : false ,
"showDropdown" : false ,
"richText" : false
}
] ,
"relations" : []
}
Example-6: Creating an ontology with:
A Tree Dropdown classification tool which only appears if the annotator clicks on "Radio Answer 1"
The Tree Dropdown has a main root
With a branch called "Branch 1"
With leaves called "Leaf 1" and "Leaf 2"
With a leaf called "Leaf 3"
Copy import os
from dotenv import load_dotenv
from imerit_ango . sdk import SDK
from imerit_ango . models . label_category import ClassificationCategory , TreeOption , LabelOption , Classification
load_dotenv ( 'variables.env' )
api_key = os . getenv ( 'API_KEY' )
project_id = os . getenv ( 'PROJECT_ID' )
ango_sdk = SDK (api_key)
leaf1 = TreeOption (title = "Leaf 1" )
leaf2 = TreeOption (title = "Leaf 2" )
leaf3 = TreeOption (title = "Leaf 3" )
branch1 = TreeOption (title = "Branch 1" ,
children = [leaf1, leaf2])
tree_tool = ClassificationCategory (classification = Classification.Tree_dropdown,
title = 'tree' ,
treeOptions = [branch1, leaf3],
parentOptionId = "radioOptionSchemaId" )
radio1 = LabelOption (value = "Radio Answer 1" )
radio2 = LabelOption (value = "Radio Answer 2" )
radio = ClassificationCategory (classification = Classification.Radio,
title = 'radio' ,
classifications = [tree_tool],
options = [radio1, radio2])
ango_sdk . create_label_set (project_id = project_id, classifications = [radio])
Resulting category schema
Copy {
"tools" : [] ,
"classifications" : [
{
"treeOptions" : [] ,
"tool" : "radio" ,
"title" : "radio" ,
"required" : false ,
"columnField" : false ,
"color" : "#C5FA61" ,
"shortcutKey" : "" ,
"classifications" : [
{
"treeOptions" : [
{
"title" : "Branch 1" ,
"children" : [
{
"title" : "Leaf 1" ,
"children" : [] ,
"key" : "a5932cf49f804e0fa5c6ae2066875242" ,
"value" : "a5932cf49f804e0fa5c6ae2066875242"
} ,
{
"title" : "Leaf 2" ,
"children" : [] ,
"key" : "bbb54a7814f84b96857b0b8acb96c0b0" ,
"value" : "bbb54a7814f84b96857b0b8acb96c0b0"
}
] ,
"key" : "ba8ce5a3b853420f9b2fb146db969d3f" ,
"value" : "ba8ce5a3b853420f9b2fb146db969d3f"
} ,
{
"title" : "Leaf 3" ,
"children" : [] ,
"key" : "25b78c7dceff4600ad4074ad316980e6" ,
"value" : "25b78c7dceff4600ad4074ad316980e6"
}
] ,
"tool" : "tree-dropdown" ,
"title" : "tree" ,
"required" : false ,
"columnField" : false ,
"color" : "#F9F415" ,
"shortcutKey" : "" ,
"classifications" : [] ,
"options" : [
{
"value" : "Branch 1" ,
"schemaId" : "ba8ce5a3b853420f9b2fb146db969d3f"
} ,
{
"value" : "Branch 1 / Leaf 1" ,
"schemaId" : "a5932cf49f804e0fa5c6ae2066875242"
} ,
{
"value" : "Branch 1 / Leaf 2" ,
"schemaId" : "bbb54a7814f84b96857b0b8acb96c0b0"
} ,
{
"value" : "Leaf 3" ,
"schemaId" : "25b78c7dceff4600ad4074ad316980e6"
}
] ,
"schemaId" : "499e34ff61f4404eac8d7925f8a48119" ,
"regex" : null ,
"parentOptionId" : "radioOptionSchemaId" ,
"frameSpecific" : false ,
"showDropdown" : false ,
"richText" : false
}
] ,
"options" : [
{
"value" : "Radio Answer 1" ,
"schemaId" : "0805c3451c6045e0b2bd5179f8c2f858"
} ,
{
"value" : "Radio Answer 2" ,
"schemaId" : "22f59c2ee19d4ca4856a0894388d9780"
}
] ,
"schemaId" : "fbb179f75e334396b31774d4d83badf3" ,
"regex" : null ,
"parentOptionId" : null ,
"frameSpecific" : false ,
"showDropdown" : false ,
"richText" : false
}
] ,
"relations" : []
}
Last updated 2 months ago