tensorbay.label.attributes¶
Items and AttributeInfo.
AttributeInfo
represents the information of an attribute.
It refers to the Json schema method to describe an attribute.
Items
is the base class of AttributeInfo
, representing the items of an attribute.
- class tensorbay.label.attributes.Items(*, type_: Union[str, None, Type[Optional[Union[list, bool, int, float, str]]], Iterable[Union[str, None, Type[Optional[Union[list, bool, int, float, str]]]]]] = '', enum: Optional[Iterable[Optional[Union[str, float, bool]]]] = None, minimum: Optional[float] = None, maximum: Optional[float] = None, items: Optional[tensorbay.label.attributes.Items] = None)[source]¶
Bases:
tensorbay.utility.repr.ReprMixin
,tensorbay.utility.common.EqMixin
The base class of
AttributeInfo
, representing the items of an attribute.When the value type of an attribute is array, the
AttributeInfo
would contain an ‘items’ field.Todo
The format of argument type_ on the generated web page is incorrect.
- Parameters
type –
The type of the attribute value, could be a single type or multi-types. The type must be within the followings:
array
boolean
integer
number
string
null
instance
enum – All the possible values of an enumeration attribute.
minimum – The minimum value of number type attribute.
maximum – The maximum value of number type attribute.
items – The items inside array type attributes.
- type¶
The type of the attribute value, could be a single type or multi-types.
- enum¶
All the possible values of an enumeration attribute.
- minimum¶
The minimum value of number type attribute.
- maximum¶
The maximum value of number type attribute.
- items¶
The items inside array type attributes.
- Raises
TypeError – When both
enum
andtype_
are absent or whentype_
is array anditems
is absent.
Examples
>>> Items(type_="integer", enum=[1, 2, 3, 4, 5], minimum=1, maximum=5) Items( (type): 'integer', (enum): [...], (minimum): 1, (maximum): 5 )
- classmethod loads(contents: Dict[str, Any]) tensorbay.label.attributes._T [source]¶
Load an Items from a dict containing the items information.
- Parameters
contents – A dict containing the information of the items.
- Returns
The loaded
Items
object.
Examples
>>> contents = { ... "type": "array", ... "enum": [1, 2, 3, 4, 5], ... "minimum": 1, ... "maximum": 5, ... "items": { ... "enum": [None], ... "type": "null", ... }, ... } >>> Items.loads(contents) Items( (type): 'array', (enum): [...], (minimum): 1, (maximum): 5, (items): Items(...) )
- dumps() Dict[str, Any] [source]¶
Dumps the information of the items into a dict.
- Returns
A dict containing all the information of the items.
Examples
>>> items = Items(type_="integer", enum=[1, 2, 3, 4, 5], minimum=1, maximum=5) >>> items.dumps() {'type': 'integer', 'enum': [1, 2, 3, 4, 5], 'minimum': 1, 'maximum': 5}
- class tensorbay.label.attributes.AttributeInfo(name: str, *, type_: Union[str, None, Type[Optional[Union[list, bool, int, float, str]]], Iterable[Union[str, None, Type[Optional[Union[list, bool, int, float, str]]]]]] = '', enum: Optional[Iterable[Optional[Union[str, float, bool]]]] = None, minimum: Optional[float] = None, maximum: Optional[float] = None, items: Optional[tensorbay.label.attributes.Items] = None, parent_categories: Union[None, str, Iterable[str]] = None, description: str = '')[source]¶
Bases:
tensorbay.utility.name.NameMixin
,tensorbay.label.attributes.Items
This class represents the information of an attribute.
It refers to the Json schema method to describe an attribute.
Todo
The format of argument type_ on the generated web page is incorrect.
- Parameters
name – The name of the attribute.
type –
The type of the attribute value, could be a single type or multi-types. The type must be within the followings:
array
boolean
integer
number
string
null
instance
enum – All the possible values of an enumeration attribute.
minimum – The minimum value of number type attribute.
maximum – The maximum value of number type attribute.
items – The items inside array type attributes.
parent_categories – The parent categories of the attribute.
description – The description of the attribute.
- type¶
The type of the attribute value, could be a single type or multi-types.
- enum¶
All the possible values of an enumeration attribute.
- minimum¶
The minimum value of number type attribute.
- maximum¶
The maximum value of number type attribute.
- items¶
The items inside array type attributes.
- parent_categories¶
The parent categories of the attribute.
- Type
List[str]
- description¶
The description of the attribute.
- Type
str
Examples
>>> from tensorbay.label import Items >>> items = Items(type_="integer", enum=[1, 2, 3, 4, 5], minimum=1, maximum=5) >>> AttributeInfo( ... name="example", ... type_="array", ... enum=[1, 2, 3, 4, 5], ... items=items, ... minimum=1, ... maximum=5, ... parent_categories=["parent_category_of_example"], ... description="This is an example", ... ) AttributeInfo("example")( (type): 'array', (enum): [ 1, 2, 3, 4, 5 ], (minimum): 1, (maximum): 5, (items): Items( (type): 'integer', (enum): [...], (minimum): 1, (maximum): 5 ), (parent_categories): [ 'parent_category_of_example' ] )
- classmethod loads(contents: Dict[str, Any]) tensorbay.label.attributes._T [source]¶
Load an AttributeInfo from a dict containing the attribute information.
- Parameters
contents – A dict containing the information of the attribute.
- Returns
The loaded
AttributeInfo
object.
Examples
>>> contents = { ... "name": "example", ... "type": "array", ... "items": {"type": "boolean"}, ... "description": "This is an example", ... "parentCategories": ["parent_category_of_example"], ... } >>> AttributeInfo.loads(contents) AttributeInfo("example")( (type): 'array', (items): Items( (type): 'boolean', ), (parent_categories): [ 'parent_category_of_example' ] )
- dumps() Dict[str, Any] [source]¶
Dumps the information of this attribute into a dict.
- Returns
A dict containing all the information of this attribute.
Examples
>>> from tensorbay.label import Items >>> items = Items(type_="integer", minimum=1, maximum=5) >>> attributeinfo = AttributeInfo( ... name="example", ... type_="array", ... items=items, ... parent_categories=["parent_category_of_example"], ... description="This is an example", ... ) >>> attributeinfo.dumps() { 'name': 'example', 'description': 'This is an example', 'type': 'array', 'items': {'type': 'integer', 'minimum': 1, 'maximum': 5}, 'parentCategories': ['parent_category_of_example'], }