Skip to content

common

Common metadata models based on RO-Crate and Schema.org.

SIValue

Bases: QuantitativeValue

QuantitativeValue that holds a numerical value given in SI units.

Uses the pint library to parse and normalize the unit.

Source code in src/metador_core/schema/common/__init__.py
41
42
43
44
45
46
47
48
class SIValue(QuantitativeValue):
    """QuantitativeValue that holds a numerical value given in SI units.

    Uses the `pint` library to parse and normalize the unit.
    """

    value: Number
    Parser = SIValueParser

NumValue

Bases: QuantitativeValue

Quantitative value that can have a unit out of a fixed list.

Source code in src/metador_core/schema/common/__init__.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
class NumValue(QuantitativeValue):
    """Quantitative value that can have a unit out of a fixed list."""

    value: Number

    class Parser(BaseParser):
        schema_info: Dict[str, Any] = {}

        allowed_units: List[str] = []
        infer_unit: Optional[str] = None
        require_unit: bool = False

        @classmethod
        def parse(cls, tcls, v):
            if isinstance(v, (int, float)):
                if cls.require_unit:
                    raise ValueError(f"Value '{v}' must have a unit!")
                return tcls.construct(value=v, unitText=cls.infer_unit)

            if isinstance(v, str):
                arr = v.strip().split(maxsplit=1)

            # important to parse back serialized data!
            if isinstance(v, dict):
                v = tcls.__base__.validate(v)  # -> QuantitativeValue

            if isinstance(v, tcls.__base__):  # unpack QuantitativeValue
                def_unit = cls.infer_unit or ""
                arr = (v.value, v.unitText or v.unitCode or def_unit)

            # check that value and unit are valid:

            if len(arr) == 1:  # no unit given?
                if cls.require_unit:
                    raise ValueError(f"Value '{v}' must have a unit!")
                val = parse_obj_as(Number, arr[0])
                # return with inferred unit
                return tcls.construct(value=val, unitText=cls.infer_unit)

            val = parse_obj_as(Tuple[Number, str], arr)
            if cls.allowed_units and val[1] not in cls.allowed_units:
                msg = (
                    f"Invalid unit '{val[1]}', unit must be one of {cls.allowed_units}"
                )
                raise ValueError(msg)
            return tcls.construct(value=val[0], unitText=val[1])

Pixels

Bases: NumValue

Numeric value representing pixels.

Source code in src/metador_core/schema/common/__init__.py
 99
100
101
102
103
104
class Pixels(NumValue):
    """Numeric value representing pixels."""

    class Parser(NumValue.Parser):
        allowed_units = ["px"]
        infer_unit = "px"

BibMeta

Bases: DirMeta

Minimal bibliographic metadata required for a container.

Source code in src/metador_core/schema/common/__init__.py
113
114
115
116
117
118
119
120
121
122
@make_mandatory("name", "abstract", "dateCreated")
class BibMeta(DirMeta):
    """Minimal bibliographic metadata required for a container."""

    class Plugin:
        name = "core.bib"
        version = (0, 1, 0)

    author: List[Person]
    """List of authors (creators of the actual data)."""

author instance-attribute

author: List[Person]

List of authors (creators of the actual data).

ImageFileMeta

Bases: FileMeta

A rasterized image file with known dimensions.

Also serves as marker schema for the imagefile widget.

Source code in src/metador_core/schema/common/__init__.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
class ImageFileMeta(FileMeta):
    """A rasterized image file with known dimensions.

    Also serves as marker schema for the imagefile widget.
    """

    class Plugin:
        name = "core.imagefile"
        version = (0, 1, 0)

    width: Pixels
    """Width of the image in pixels."""

    height: Pixels
    """Height of the image in pixels."""

width instance-attribute

width: Pixels

Width of the image in pixels.

height instance-attribute

height: Pixels

Height of the image in pixels.

ColumnHeader

Bases: MetadataSchema

Table column metadata.

Source code in src/metador_core/schema/common/__init__.py
145
146
147
148
149
150
151
152
class ColumnHeader(MetadataSchema):
    """Table column metadata."""

    name: Text
    """Column title."""

    unit: PintUnit
    """Physical unit for this column."""

name instance-attribute

name: Text

Column title.

unit instance-attribute

unit: PintUnit

Physical unit for this column.

TableMeta

Bases: MetadataSchema

Table metadata.

Source code in src/metador_core/schema/common/__init__.py
155
156
157
158
159
160
161
162
163
164
165
166
class TableMeta(MetadataSchema):
    """Table metadata."""

    class Plugin:
        name = "core.table"
        version = (0, 1, 0)

    name: Text
    """Table title."""

    columns: List[ColumnHeader]
    """List of column descriptions."""

name instance-attribute

name: Text

Table title.

columns instance-attribute

columns: List[ColumnHeader]

List of column descriptions.