Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions labelbox/schema/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ class Option:
options: (list)
"""
value: Union[str, int]
label: Optional[Union[str, int]] = None
schema_id: Optional[str] = None
feature_schema_id: Optional[FeatureSchemaId] = None
options: List["Classification"] = field(default_factory=list)

@property
def label(self):
return self.value
def __post_init__(self):
if self.label is None:
self.label = self.value

@classmethod
def from_dict(cls, dictionary: Dict[str, Any]):
return cls(value=dictionary["value"],
label=dictionary["label"],
schema_id=dictionary.get("schemaNodeId", None),
feature_schema_id=dictionary.get("featureSchemaId", None),
options=[
Expand Down
16 changes: 13 additions & 3 deletions tests/integration/test_ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@
"schemaNodeId": None,
"featureSchemaId": None,
"label": "yes",
"value": "yes",
"value": "definitely yes",
"options": []
}, {
"schemaNodeId": None,
"featureSchemaId": None,
"label": "no",
"value": "no",
"value": "definitely not",
"options": []
}]
}]
Expand All @@ -149,12 +149,22 @@ def test_create_classification(class_type) -> None:

@pytest.mark.parametrize("value, expected_value, typing",
[(3, 3, int), ("string", "string", str)])
def test_create_option(value, expected_value, typing) -> None:
def test_create_option_with_value(value, expected_value, typing) -> None:
o = Option(value=value)
assert (o.value == expected_value)
assert (o.value == o.label)


@pytest.mark.parametrize("value, label, expected_value, typing",
[(3, 2, 3, int),
("string", "another string", "string", str)])
def test_create_option_with_value_and_label(value, label, expected_value,
typing) -> None:
o = Option(value=value, label=label)
assert (o.value == expected_value)
assert o.value != o.label


def test_create_empty_ontology() -> None:
o = OntologyBuilder()
assert (o.tools == [])
Expand Down