Skip to content

Commit aed5a98

Browse files
committed
made minor adjustments
1 parent c910fad commit aed5a98

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

labelbox/schema/ontology_generator.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from dataclasses import dataclass, field
77
from enum import Enum, auto
88
import os
9-
from typing import List, Optional
9+
from typing import List, Optional, Dict
1010

1111
from labelbox import Client, Project, Dataset, LabelingFrontend
1212

@@ -28,7 +28,7 @@ class Option:
2828
def label(self):
2929
return self.value
3030

31-
def to_dict(self,for_different_project=False) -> dict:
31+
def to_dict(self,for_different_project=False) -> Dict[str, str]:
3232
return {
3333
"schemaNodeId": None if for_different_project else self.schema_id,
3434
"featureSchemaId": None if for_different_project else self.feature_schema_id,
@@ -38,11 +38,9 @@ def to_dict(self,for_different_project=False) -> dict:
3838
}
3939

4040
@classmethod
41-
def from_dict(cls, dictionary: dict):
42-
def has_nested_classifications(dictionary: dict):
43-
if "options" in dictionary.keys():
44-
return [Classification.from_dict(nested_class) for nested_class in dictionary["options"]]
45-
return list()
41+
def from_dict(cls, dictionary: Dict[str,str]):
42+
def has_nested_classifications(dictionary: Dict[str,str]):
43+
return [Classification.from_dict(nested_class) for nested_class in dictionary.get("options", [])]
4644

4745
return Option(
4846
value = dictionary["value"],
@@ -74,16 +72,16 @@ class Type(Enum):
7472
schema_id: Optional[str] = None
7573
feature_schema_id: Optional[str] = None
7674

77-
@property
78-
def requires_options(self):
75+
@staticmethod
76+
def requires_options():
7977
return set((Classification.Type.CHECKLIST, Classification.Type.RADIO, Classification.Type.DROPDOWN))
8078

8179
@property
8280
def name(self):
8381
return self.instructions
8482

85-
def to_dict(self, for_different_project=False) -> dict:
86-
if self.class_type in self.requires_options and len(self.options) < 1:
83+
def to_dict(self, for_different_project=False) -> Dict[str,str]:
84+
if self.class_type in Classification.requires_options() and len(self.options) < 1:
8785
raise InconsistentOntologyException(f"Classification '{self.instructions}' requires options.")
8886
return {
8987
"type": self.class_type.value,
@@ -96,7 +94,7 @@ def to_dict(self, for_different_project=False) -> dict:
9694
}
9795

9896
@classmethod
99-
def from_dict(cls, dictionary: dict):
97+
def from_dict(cls, dictionary: Dict[str,str]):
10098
return Classification(
10199
class_type = Classification.Type(dictionary["type"]),
102100
instructions = dictionary["instructions"],
@@ -132,7 +130,7 @@ class Type(Enum):
132130
schema_id: Optional[str] = None
133131
feature_schema_id: Optional[str] = None
134132

135-
def to_dict(self,for_different_project=False) -> dict:
133+
def to_dict(self,for_different_project=False) -> Dict[str,str]:
136134
return {
137135
"tool": self.tool.value,
138136
"name": self.name,
@@ -144,7 +142,7 @@ def to_dict(self,for_different_project=False) -> dict:
144142
}
145143

146144
@classmethod
147-
def from_dict(cls, dictionary: dict):
145+
def from_dict(cls, dictionary: Dict[str,str]):
148146
return Tool(
149147
name = dictionary['name'],
150148
schema_id = dictionary["schemaNodeId"],
@@ -238,11 +236,11 @@ def print_stuff():
238236

239237

240238
#create a Point tool and add a nested dropdown in it
241-
tool = o.add_tool(tool = Tool.Type.POINT, name = "Example Point Tool")
242-
nested_class = tool.add_nested_class(class_type = Classification.Type.DROPDOWN, instructions = "nested class")
243-
dropdown_option = nested_class.add_option(value="answer")
239+
# tool = o.add_tool(tool = Tool.Type.POINT, name = "Example Point Tool")
240+
# nested_class = tool.add_nested_class(class_type = Classification.Type.DROPDOWN, instructions = "nested class")
241+
# dropdown_option = nested_class.add_option(value="answer")
244242

245-
tool = o.add_tool(tool = Tool.Type.NER, name="NER value")
243+
# tool = o.add_tool(tool = Tool.Type.NER, name="NER value")
246244

247245
#to old existing project
248246
frontend = list(client.get_labeling_frontends(where=LabelingFrontend.name == "Editor"))[0]

0 commit comments

Comments
 (0)