|
44 | 44 | _LABELBOX_API_KEY = "LABELBOX_API_KEY" |
45 | 45 |
|
46 | 46 |
|
| 47 | +class DeleteFeatureFromOntologyResult: |
| 48 | + archived: bool |
| 49 | + deleted: bool |
| 50 | + |
| 51 | + |
47 | 52 | class Client: |
48 | 53 | """ A Labelbox client. |
49 | 54 |
|
@@ -931,7 +936,6 @@ def delete_unused_ontology(self, ontology_id: str) -> None: |
931 | 936 | Example: |
932 | 937 | >>> client.delete_unused_ontology("cleabc1my012ioqvu5anyaabc") |
933 | 938 | """ |
934 | | - |
935 | 939 | endpoint = self.rest_endpoint + "/ontologies/" + urllib.parse.quote( |
936 | 940 | ontology_id) |
937 | 941 | response = requests.delete( |
@@ -1597,3 +1601,48 @@ def get_model_slice(self, slice_id) -> ModelSlice: |
1597 | 1601 | """ |
1598 | 1602 | res = self.execute(query_str, {"id": slice_id}) |
1599 | 1603 | return Entity.ModelSlice(self, res["getSavedQuery"]) |
| 1604 | + |
| 1605 | + def delete_feature_schema_from_ontology( |
| 1606 | + self, ontology_id: str, |
| 1607 | + feature_schema_id: str) -> DeleteFeatureFromOntologyResult: |
| 1608 | + """ |
| 1609 | + Deletes or archives a feature schema from an ontology. |
| 1610 | + If the feature schema is a root level node with associated labels, it will be archived. |
| 1611 | + If the feature schema is a nested node in the ontology and does not have associated labels, it will be deleted. |
| 1612 | + If the feature schema is a nested node in the ontology and has associated labels, it will not be deleted. |
| 1613 | +
|
| 1614 | + Args: |
| 1615 | + ontology_id (str): The ID of the ontology. |
| 1616 | + feature_schema_id (str): The ID of the feature schema. |
| 1617 | +
|
| 1618 | + Returns: |
| 1619 | + DeleteFeatureFromOntologyResult: The result of the feature schema removal. |
| 1620 | +
|
| 1621 | + Example: |
| 1622 | + >>> client.remove_feature_schema_from_ontology(<ontology_id>, <feature_schema_id>) |
| 1623 | + """ |
| 1624 | + ontology_endpoint = self.rest_endpoint + "/ontologies/" + urllib.parse.quote( |
| 1625 | + ontology_id) + "/feature-schemas/" + urllib.parse.quote( |
| 1626 | + feature_schema_id) |
| 1627 | + response = requests.delete( |
| 1628 | + ontology_endpoint, |
| 1629 | + headers=self.headers, |
| 1630 | + ) |
| 1631 | + |
| 1632 | + if response.status_code == requests.codes.ok: |
| 1633 | + response_json = response.json() |
| 1634 | + if response_json['archived'] == True: |
| 1635 | + logger.info( |
| 1636 | + 'Feature schema was archived from the ontology because it had associated labels.' |
| 1637 | + ) |
| 1638 | + elif response_json['deleted'] == True: |
| 1639 | + logger.info( |
| 1640 | + 'Feature schema was successfully removed from the ontology') |
| 1641 | + result = DeleteFeatureFromOntologyResult() |
| 1642 | + result.archived = bool(response_json['archived']) |
| 1643 | + result.deleted = bool(response_json['deleted']) |
| 1644 | + return result |
| 1645 | + else: |
| 1646 | + raise labelbox.exceptions.LabelboxError( |
| 1647 | + "Failed to remove feature schema from ontology, message: " + |
| 1648 | + str(response.json()['message'])) |
0 commit comments