Skip to content

matchers

Classes

ValueMatcher

Bases: KiaraModel

An object describing requirements values should satisfy in order to be included in a query result.

Source code in kiara/models/values/matchers.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class ValueMatcher(KiaraModel):
    """An object describing requirements values should satisfy in order to be included in a query result."""

    @classmethod
    def create_matcher(self, **match_options: Any):

        m = ValueMatcher(**match_options)
        return m

    data_types: List[str] = Field(description="The data type.", default_factory=list)
    allow_sub_types: bool = Field(description="Allow subtypes.", default=True)
    min_size: int = Field(description="The minimum size for the dataset.", default=0)
    max_size: Union[None, int] = Field(
        description="The maximum size for the dataset.", default=None
    )
    allow_internal: bool = Field(
        description="Allow internal data types.", default=False
    )
    has_alias: bool = Field(
        description="Value must have at least one alias.", default=True
    )

    def is_match(self, value: Value, kiara: "Kiara") -> bool:
        if self.data_types:
            match = False
            if not self.allow_sub_types:
                for data_type in self.data_types:
                    if data_type == value.data_type_name:
                        match = True
                        break
            else:
                if value.data_type_name not in kiara.type_registry.data_type_names:
                    return False
                lineage = kiara.type_registry.get_type_lineage(value.data_type_name)
                for data_type in self.data_types:
                    if data_type in lineage:
                        match = True
                        break
            if not match:
                return False

        if self.min_size:
            if value.value_size < self.min_size:
                return False
        if self.max_size:
            if value.value_size > self.max_size:
                return False

        if not self.allow_internal:
            if kiara.type_registry.is_internal_type(
                data_type_name=value.data_type_name
            ):
                return False

        if self.has_alias:
            aliases = kiara.alias_registry.find_aliases_for_value_id(
                value_id=value.value_id
            )
            if not aliases:
                return False

        return True

Attributes

data_types: List[str] = Field(description='The data type.', default_factory=list) class-attribute
allow_sub_types: bool = Field(description='Allow subtypes.', default=True) class-attribute
min_size: int = Field(description='The minimum size for the dataset.', default=0) class-attribute
max_size: Union[None, int] = Field(description='The maximum size for the dataset.', default=None) class-attribute
allow_internal: bool = Field(description='Allow internal data types.', default=False) class-attribute
has_alias: bool = Field(description='Value must have at least one alias.', default=True) class-attribute

Functions

create_matcher(**match_options: Any) classmethod
Source code in kiara/models/values/matchers.py
15
16
17
18
19
@classmethod
def create_matcher(self, **match_options: Any):

    m = ValueMatcher(**match_options)
    return m
is_match(value: Value, kiara: Kiara) -> bool
Source code in kiara/models/values/matchers.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def is_match(self, value: Value, kiara: "Kiara") -> bool:
    if self.data_types:
        match = False
        if not self.allow_sub_types:
            for data_type in self.data_types:
                if data_type == value.data_type_name:
                    match = True
                    break
        else:
            if value.data_type_name not in kiara.type_registry.data_type_names:
                return False
            lineage = kiara.type_registry.get_type_lineage(value.data_type_name)
            for data_type in self.data_types:
                if data_type in lineage:
                    match = True
                    break
        if not match:
            return False

    if self.min_size:
        if value.value_size < self.min_size:
            return False
    if self.max_size:
        if value.value_size > self.max_size:
            return False

    if not self.allow_internal:
        if kiara.type_registry.is_internal_type(
            data_type_name=value.data_type_name
        ):
            return False

    if self.has_alias:
        aliases = kiara.alias_registry.find_aliases_for_value_id(
            value_id=value.value_id
        )
        if not aliases:
            return False

    return True