Skip to content

Facet prefix

FacetPrefixExtract

Bases: ExtractionMethod

In some cases, you may wish add a prefix to some or all of the facets based on the vocabulary they're from.

Method name: facet_prefix

Example Configuration

.. code-block:: yaml

- method: facet_prefix
  inputs:
    prefix: cmip6
    keys:
    - start_time
    - model
Source code in extraction_methods/plugins/facet_prefix.py
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
class FacetPrefixExtract(ExtractionMethod):
    """
    In some cases, you may wish add a prefix to some or all of the facets
    based on the vocabulary they're from.

    **Method name:** ``facet_prefix``

    Example Configuration:
        .. code-block:: yaml

            - method: facet_prefix
              inputs:
                prefix: cmip6
                keys:
                - start_time
                - model
    """

    input_class = FacetPrefixInput

    @update_input
    def run(self, body: dict[str, Any]) -> dict[str, Any]:

        for term in self.input.keys:
            try:
                value = body.pop(term)
                body[f"{self.input.prefix}:{term}"] = value

            except KeyError:
                pass

        return body

FacetPrefixInput

Bases: Input

Model for Facet Prefix Input.

Parameters:

Name Type Description Default
prefix str

Prefix to be added.

required
keys list[str]

list of keys that require prefix.

required
Source code in extraction_methods/plugins/facet_prefix.py
23
24
25
26
27
28
29
30
31
32
33
class FacetPrefixInput(Input):
    """
    Model for Facet Prefix Input.
    """

    prefix: str = Field(
        description="Prefix to be added.",
    )
    keys: list[str] = Field(
        description="list of keys that require prefix.",
    )