Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow provide object hashes / classifications #612

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 6 additions & 3 deletions encord/objects/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ def title(self) -> str:
def children(self) -> Sequence[OntologyElement]:
return self.attributes

def create_instance(self) -> ClassificationInstance:
"""Create a :class:`encord.objects.ClassificationInstance` to be used with a label row."""
return ClassificationInstance(self)
def create_instance(self, classification_hash: Optional[str] = None) -> ClassificationInstance:
"""Create a :class:`encord.objects.ClassificationInstance` to be used with a label row.
Args:
classification_hash: str = None. Classification hash for the created instance.
"""
return ClassificationInstance(self, classification_hash=classification_hash)

@classmethod
def from_dict(cls, d: dict) -> Classification:
Expand Down
10 changes: 7 additions & 3 deletions encord/objects/ontology_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ def title(self) -> str:
def children(self) -> Sequence[OntologyElement]:
return self.attributes

def create_instance(self) -> ObjectInstance:
"""Create a :class:`encord.objects.ObjectInstance` to be used with a label row."""
return ObjectInstance(self)
def create_instance(self, object_hash: Optional[str] = None) -> ObjectInstance:
"""
Create a :class:`encord.objects.ObjectInstance` to be used with a label row.
Args:
object_hash: str = None. object_hash for the created instance
"""
return ObjectInstance(self, object_hash=object_hash)

@classmethod
def from_dict(cls, d: dict) -> Object:
Expand Down
8 changes: 8 additions & 0 deletions tests/objects/test_label_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,3 +984,11 @@ def test_classification_can_be_added_edited_and_removed(ontology):
label_row.remove_classification(classification_instance)

assert len(label_row.get_classification_instances()) == 0


def test_can_provide_object_classification_hashes():
object_instance = box_ontology_item.create_instance(object_hash="ObjectHash")
assert object_instance.object_hash == "ObjectHash"

classification_instance = text_classification.create_instance(classification_hash="ClassificationHash")
assert classification_instance.classification_hash == "ClassificationHash"
Loading