Source code for annofabapi.pydantic_models.full_annotation_data

"""


No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""

from __future__ import annotations

import json
import pprint
from typing import Any, Dict, Set, Union

from pydantic import BaseModel, ConfigDict, ValidationError, field_validator
from typing_extensions import Self

from annofabapi.pydantic_models.full_annotation_data_bounding_box import FullAnnotationDataBoundingBox
from annofabapi.pydantic_models.full_annotation_data_classification import FullAnnotationDataClassification
from annofabapi.pydantic_models.full_annotation_data_points import FullAnnotationDataPoints
from annofabapi.pydantic_models.full_annotation_data_range import FullAnnotationDataRange
from annofabapi.pydantic_models.full_annotation_data_segmentation import FullAnnotationDataSegmentation
from annofabapi.pydantic_models.full_annotation_data_segmentation_v2 import FullAnnotationDataSegmentationV2
from annofabapi.pydantic_models.full_annotation_data_single_point import FullAnnotationDataSinglePoint
from annofabapi.pydantic_models.full_annotation_data_unknown import FullAnnotationDataUnknown

FULLANNOTATIONDATA_ONE_OF_SCHEMAS = [
    "FullAnnotationDataBoundingBox",
    "FullAnnotationDataClassification",
    "FullAnnotationDataPoints",
    "FullAnnotationDataRange",
    "FullAnnotationDataSegmentation",
    "FullAnnotationDataSegmentationV2",
    "FullAnnotationDataSinglePoint",
    "FullAnnotationDataUnknown",
]


[docs] class FullAnnotationData(BaseModel): """ アノテーションのデータが格納されます。 * `FullAnnotationDataClassification`: 入力データ全体アノテーション * `FullAnnotationDataSegmentation`: 塗りつぶしアノテーション * `FullAnnotationDataSegmentationV2`: 塗りつぶしv2アノテーション * `FullAnnotationDataBoundingBox`: 矩形アノテーション * `FullAnnotationDataPoints`: ポリゴンまたはポリラインアノテーション * `FullAnnotationDataSinglePoint`: 点アノテーション * `FullAnnotationDataRange`: 動画区間アノテーション * `FullAnnotationDataUnknown`: カスタムアノテーション """ # data type: FullAnnotationDataClassification oneof_schema_1_validator: FullAnnotationDataClassification | None = None # data type: FullAnnotationDataSegmentation oneof_schema_2_validator: FullAnnotationDataSegmentation | None = None # data type: FullAnnotationDataSegmentationV2 oneof_schema_3_validator: FullAnnotationDataSegmentationV2 | None = None # data type: FullAnnotationDataBoundingBox oneof_schema_4_validator: FullAnnotationDataBoundingBox | None = None # data type: FullAnnotationDataPoints oneof_schema_5_validator: FullAnnotationDataPoints | None = None # data type: FullAnnotationDataSinglePoint oneof_schema_6_validator: FullAnnotationDataSinglePoint | None = None # data type: FullAnnotationDataRange oneof_schema_7_validator: FullAnnotationDataRange | None = None # data type: FullAnnotationDataUnknown oneof_schema_8_validator: FullAnnotationDataUnknown | None = None actual_instance: ( Union[ FullAnnotationDataBoundingBox, FullAnnotationDataClassification, FullAnnotationDataPoints, FullAnnotationDataRange, FullAnnotationDataSegmentation, FullAnnotationDataSegmentationV2, FullAnnotationDataSinglePoint, FullAnnotationDataUnknown, ] | None ) = None one_of_schemas: Set[str] = { "FullAnnotationDataBoundingBox", "FullAnnotationDataClassification", "FullAnnotationDataPoints", "FullAnnotationDataRange", "FullAnnotationDataSegmentation", "FullAnnotationDataSegmentationV2", "FullAnnotationDataSinglePoint", "FullAnnotationDataUnknown", } model_config = ConfigDict( validate_assignment=True, protected_namespaces=(), ) discriminator_value_class_map: Dict[str, str] = {} def __init__(self, *args, **kwargs) -> None: if args: if len(args) > 1: raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) else: super().__init__(**kwargs)
[docs] @field_validator("actual_instance") def actual_instance_must_validate_oneof(cls, v): instance = FullAnnotationData.model_construct() error_messages = [] match = 0 # validate data type: FullAnnotationDataClassification if not isinstance(v, FullAnnotationDataClassification): error_messages.append(f"Error! Input type `{type(v)}` is not `FullAnnotationDataClassification`") else: match += 1 # validate data type: FullAnnotationDataSegmentation if not isinstance(v, FullAnnotationDataSegmentation): error_messages.append(f"Error! Input type `{type(v)}` is not `FullAnnotationDataSegmentation`") else: match += 1 # validate data type: FullAnnotationDataSegmentationV2 if not isinstance(v, FullAnnotationDataSegmentationV2): error_messages.append(f"Error! Input type `{type(v)}` is not `FullAnnotationDataSegmentationV2`") else: match += 1 # validate data type: FullAnnotationDataBoundingBox if not isinstance(v, FullAnnotationDataBoundingBox): error_messages.append(f"Error! Input type `{type(v)}` is not `FullAnnotationDataBoundingBox`") else: match += 1 # validate data type: FullAnnotationDataPoints if not isinstance(v, FullAnnotationDataPoints): error_messages.append(f"Error! Input type `{type(v)}` is not `FullAnnotationDataPoints`") else: match += 1 # validate data type: FullAnnotationDataSinglePoint if not isinstance(v, FullAnnotationDataSinglePoint): error_messages.append(f"Error! Input type `{type(v)}` is not `FullAnnotationDataSinglePoint`") else: match += 1 # validate data type: FullAnnotationDataRange if not isinstance(v, FullAnnotationDataRange): error_messages.append(f"Error! Input type `{type(v)}` is not `FullAnnotationDataRange`") else: match += 1 # validate data type: FullAnnotationDataUnknown if not isinstance(v, FullAnnotationDataUnknown): error_messages.append(f"Error! Input type `{type(v)}` is not `FullAnnotationDataUnknown`") else: match += 1 if match > 1: # more than 1 match raise ValueError( "Multiple matches found when setting `actual_instance` in FullAnnotationData with oneOf schemas: FullAnnotationDataBoundingBox, FullAnnotationDataClassification, FullAnnotationDataPoints, FullAnnotationDataRange, FullAnnotationDataSegmentation, FullAnnotationDataSegmentationV2, FullAnnotationDataSinglePoint, FullAnnotationDataUnknown. Details: " + ", ".join(error_messages) ) elif match == 0: # no match raise ValueError( "No match found when setting `actual_instance` in FullAnnotationData with oneOf schemas: FullAnnotationDataBoundingBox, FullAnnotationDataClassification, FullAnnotationDataPoints, FullAnnotationDataRange, FullAnnotationDataSegmentation, FullAnnotationDataSegmentationV2, FullAnnotationDataSinglePoint, FullAnnotationDataUnknown. Details: " + ", ".join(error_messages) ) else: return v
[docs] @classmethod def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: return cls.from_json(json.dumps(obj))
[docs] @classmethod def from_json(cls, json_str: str) -> Self: """Returns the object represented by the json string""" instance = cls.model_construct() error_messages = [] match = 0 # deserialize data into FullAnnotationDataClassification try: instance.actual_instance = FullAnnotationDataClassification.from_json(json_str) match += 1 except (ValidationError, ValueError) as e: error_messages.append(str(e)) # deserialize data into FullAnnotationDataSegmentation try: instance.actual_instance = FullAnnotationDataSegmentation.from_json(json_str) match += 1 except (ValidationError, ValueError) as e: error_messages.append(str(e)) # deserialize data into FullAnnotationDataSegmentationV2 try: instance.actual_instance = FullAnnotationDataSegmentationV2.from_json(json_str) match += 1 except (ValidationError, ValueError) as e: error_messages.append(str(e)) # deserialize data into FullAnnotationDataBoundingBox try: instance.actual_instance = FullAnnotationDataBoundingBox.from_json(json_str) match += 1 except (ValidationError, ValueError) as e: error_messages.append(str(e)) # deserialize data into FullAnnotationDataPoints try: instance.actual_instance = FullAnnotationDataPoints.from_json(json_str) match += 1 except (ValidationError, ValueError) as e: error_messages.append(str(e)) # deserialize data into FullAnnotationDataSinglePoint try: instance.actual_instance = FullAnnotationDataSinglePoint.from_json(json_str) match += 1 except (ValidationError, ValueError) as e: error_messages.append(str(e)) # deserialize data into FullAnnotationDataRange try: instance.actual_instance = FullAnnotationDataRange.from_json(json_str) match += 1 except (ValidationError, ValueError) as e: error_messages.append(str(e)) # deserialize data into FullAnnotationDataUnknown try: instance.actual_instance = FullAnnotationDataUnknown.from_json(json_str) match += 1 except (ValidationError, ValueError) as e: error_messages.append(str(e)) if match > 1: # more than 1 match raise ValueError( "Multiple matches found when deserializing the JSON string into FullAnnotationData with oneOf schemas: FullAnnotationDataBoundingBox, FullAnnotationDataClassification, FullAnnotationDataPoints, FullAnnotationDataRange, FullAnnotationDataSegmentation, FullAnnotationDataSegmentationV2, FullAnnotationDataSinglePoint, FullAnnotationDataUnknown. Details: " + ", ".join(error_messages) ) elif match == 0: # no match raise ValueError( "No match found when deserializing the JSON string into FullAnnotationData with oneOf schemas: FullAnnotationDataBoundingBox, FullAnnotationDataClassification, FullAnnotationDataPoints, FullAnnotationDataRange, FullAnnotationDataSegmentation, FullAnnotationDataSegmentationV2, FullAnnotationDataSinglePoint, FullAnnotationDataUnknown. Details: " + ", ".join(error_messages) ) else: return instance
[docs] def to_json(self) -> str: """Returns the JSON representation of the actual instance""" if self.actual_instance is None: return "null" if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): return self.actual_instance.to_json() else: return json.dumps(self.actual_instance)
[docs] def to_dict( self, ) -> ( Union[ Dict[str, Any], FullAnnotationDataBoundingBox, FullAnnotationDataClassification, FullAnnotationDataPoints, FullAnnotationDataRange, FullAnnotationDataSegmentation, FullAnnotationDataSegmentationV2, FullAnnotationDataSinglePoint, FullAnnotationDataUnknown, ] | None ): """Returns the dict representation of the actual instance""" if self.actual_instance is None: return None if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): return self.actual_instance.to_dict() else: # primitive type return self.actual_instance
[docs] def to_str(self) -> str: """Returns the string representation of the actual instance""" return pprint.pformat(self.model_dump())