Skip to main content

Classification Objects

@dataclass
class Classification(OntologyElement)
Represents a whole-image classification as part of the Ontology structure. Wraps a single Attribute that describes the image in general rather than an individual object. Attributes:
  • uid int - The unique identifier for the classification.
  • feature_node_hash str - A unique hash identifying the feature node.
  • attributes List[Attribute] - A list of attributes associated with this classification.

title

@property
def title() -> str
Returns the title of the classification, which is the name of the first attribute. Returns:
  • str - The title of the classification.

children

@property
def children() -> Sequence[OntologyElement]
Returns the attributes of the classification as children elements. Returns:
  • Sequence[OntologyElement] - The attributes of the classification.

is_global

@property
def is_global() -> bool
Check if the classification is global. Returns:
  • bool - True if the classification level is global, False otherwise.

create_instance

def create_instance(range_only: bool = False) -> ClassificationInstance
Create a ClassificationInstance to be used with a label row. Returns:
  • ClassificationInstance - An instance of ClassificationInstance.

from_dict

@classmethod
def from_dict(cls, d: dict) -> Classification
Create a Classification instance from a dictionary. Arguments:
  • d dict - A dictionary containing classification information.
Returns:
  • Classification - An instance of Classification.

to_dict

def to_dict() -> Dict[str, Any]
Convert the Classification instance to a dictionary. Returns: Dict[str, Any]: A dictionary representation of the classification. Raises:
  • ValueError - If the classification does not have any attributes.

add_attribute

def add_attribute(cls: Type[AttributeType],
                  name: str,
                  local_uid: Optional[int] = None,
                  feature_node_hash: Optional[str] = None,
                  required: bool = False) -> AttributeType
Adds an attribute to the classification. Arguments:
  • cls Type[AttributeType] - The attribute type, one of RadioAttribute, ChecklistAttribute, TextAttribute.
  • name str - The user-visible name of the attribute.
  • local_uid Optional[int] - Integer identifier of the attribute. Normally auto-generated; omit this unless the aim is to create an exact clone of an existing ontology.
  • feature_node_hash Optional[str] - Global identifier of the attribute. Normally auto-generated; omit this unless the aim is to create an exact clone of an existing ontology.
  • required bool - Whether the label editor would mark this attribute as ‘required’.
Returns:
  • AttributeType - The created attribute that can be further specified with Options, where appropriate.
Raises:
  • ValueError - If the classification already has an attribute assigned.