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_='', enum=None, minimum=None, maximum=None, 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 (Optional[Iterable[Optional[Union[str, float, bool]]]]) – All the possible values of an enumeration attribute.

  • minimum (Optional[float]) – The minimum value of number type attribute.

  • maximum (Optional[float]) – The maximum value of number type attribute.

  • items (Optional[Items]) – The items inside array type attributes.

  • type_ (Union[str, None, Type[Optional[Union[list, bool, int, float, str]]], Iterable[Union[str, None, Type[Optional[Union[list, bool, int, float, str]]]]]]) –

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 and type_ are absent or when type_ is array and items is absent.

Parameters
  • 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]]]]) –

  • minimum (Optional[float]) –

  • maximum (Optional[float]) –

  • items (Optional[Items]) –

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)[source]

Load an Items from a dict containing the items information.

Parameters

contents (Dict[str, Any]) – A dict containing the information of the items.

Returns

The loaded Items object.

Return type

tensorbay.label.attributes._T

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()[source]

Dumps the information of the items into a dict.

Returns

A dict containing all the information of the items.

Return type

Dict[str, Any]

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, *, type_='', enum=None, minimum=None, maximum=None, items=None, parent_categories=None, description='')[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 (str) – 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 (Optional[Iterable[Optional[Union[str, float, bool]]]]) – All the possible values of an enumeration attribute.

  • minimum (Optional[float]) – The minimum value of number type attribute.

  • maximum (Optional[float]) – The maximum value of number type attribute.

  • items (Optional[tensorbay.label.attributes.Items]) – The items inside array type attributes.

  • parent_categories (List[str]) – The parent categories of the attribute.

  • description (str) – The description of the attribute.

  • type_ (Union[str, None, Type[Optional[Union[list, bool, int, float, str]]], Iterable[Union[str, None, Type[Optional[Union[list, bool, int, float, str]]]]]]) –

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)[source]

Load an AttributeInfo from a dict containing the attribute information.

Parameters

contents (Dict[str, Any]) – A dict containing the information of the attribute.

Returns

The loaded AttributeInfo object.

Return type

tensorbay.label.attributes._T

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()[source]

Dumps the information of this attribute into a dict.

Returns

A dict containing all the information of this attribute.

Return type

Dict[str, Any]

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'],
}