|
36 | 36 | from labelbox.schema.role import Role |
37 | 37 | from labelbox.schema.slice import CatalogSlice, ModelSlice |
38 | 38 | from labelbox.schema.queue_mode import QueueMode |
| 39 | +from labelbox.schema.ontology import Ontology, DeleteFeatureFromOntologyResult |
39 | 40 |
|
40 | 41 | from labelbox.schema.media_type import MediaType, get_media_type_validation_error |
41 | 42 |
|
|
44 | 45 | _LABELBOX_API_KEY = "LABELBOX_API_KEY" |
45 | 46 |
|
46 | 47 |
|
47 | | -class DeleteFeatureFromOntologyResult: |
48 | | - archived: bool |
49 | | - deleted: bool |
50 | | - |
51 | | - |
52 | 48 | class Client: |
53 | 49 | """ A Labelbox client. |
54 | 50 |
|
@@ -1578,6 +1574,49 @@ def get_catalog_slice(self, slice_id) -> CatalogSlice: |
1578 | 1574 | res = self.execute(query_str, {'id': slice_id}) |
1579 | 1575 | return Entity.CatalogSlice(self, res['getSavedQuery']) |
1580 | 1576 |
|
| 1577 | + def is_feature_schema_archived(self, ontology_id: str, |
| 1578 | + feature_schema_id: str) -> bool: |
| 1579 | + """ |
| 1580 | + Returns true if a feature schema is archived in the specified ontology, returns false otherwise. |
| 1581 | +
|
| 1582 | + Args: |
| 1583 | + feature_schema_id (str): The ID of the feature schema |
| 1584 | + ontology_id (str): The ID of the ontology |
| 1585 | + Returns: |
| 1586 | + bool |
| 1587 | + """ |
| 1588 | + |
| 1589 | + ontology_endpoint = self.rest_endpoint + "/ontologies/" + urllib.parse.quote( |
| 1590 | + ontology_id) |
| 1591 | + response = requests.get( |
| 1592 | + ontology_endpoint, |
| 1593 | + headers=self.headers, |
| 1594 | + ) |
| 1595 | + |
| 1596 | + if response.status_code == requests.codes.ok: |
| 1597 | + feature_schema_nodes = response.json()['featureSchemaNodes'] |
| 1598 | + tools = feature_schema_nodes['tools'] |
| 1599 | + classifications = feature_schema_nodes['classifications'] |
| 1600 | + relationships = feature_schema_nodes['relationships'] |
| 1601 | + feature_schema_node_list = tools + classifications + relationships |
| 1602 | + filtered_feature_schema_nodes = [ |
| 1603 | + feature_schema_node |
| 1604 | + for feature_schema_node in feature_schema_node_list |
| 1605 | + if feature_schema_node['featureSchemaId'] == feature_schema_id |
| 1606 | + ] |
| 1607 | + if filtered_feature_schema_nodes: |
| 1608 | + return bool(filtered_feature_schema_nodes[0]['archived']) |
| 1609 | + else: |
| 1610 | + raise labelbox.exceptions.LabelboxError( |
| 1611 | + "The specified feature schema was not in the ontology.") |
| 1612 | + |
| 1613 | + elif response.status_code == 404: |
| 1614 | + raise labelbox.exceptions.ResourceNotFoundError( |
| 1615 | + Ontology, ontology_id) |
| 1616 | + else: |
| 1617 | + raise labelbox.exceptions.LabelboxError( |
| 1618 | + "Failed to get the feature schema archived status.") |
| 1619 | + |
1581 | 1620 | def get_model_slice(self, slice_id) -> ModelSlice: |
1582 | 1621 | """ |
1583 | 1622 | Fetches a Model Slice by ID. |
|
0 commit comments