gemseo / core / grammars

Show inherited members

pydantic_grammar module

A grammar based on a pydantic model.

class gemseo.core.grammars.pydantic_grammar.PydanticGrammar(name, model=None, **kwargs)[source]

Bases: BaseGrammar

A grammar based on a pydantic model.

The pydantic model passed to the grammar is used to initialize the grammar defaults. Currently, changing the defaults will not update the model.

Initialize self. See help(type(self)) for accurate signature.

Parameters:
  • name (str) – The name of the grammar.

  • model (ModelType | None) – A pydantic model. If None, the model will be empty.

  • **kwargs (Any) – These arguments are not used.

Raises:

ValueError – If the name is empty.

is_array(name, numeric_only=False)[source]

Check if an element is an array.

Parameters:
  • name (str) – The name of the element.

  • numeric_only (bool) –

    Whether to check if the array elements are numbers.

    By default it is set to False.

Returns:

Whether the element is an array.

Raises:

KeyError – If the element is not in the grammar.

Return type:

bool

set_descriptions(descriptions)[source]

Set the properties descriptions.

Parameters:

descriptions (Mapping[str, str]) – The mapping from names to the description.

Return type:

None

DATA_CONVERTER_CLASS: ClassVar[str] = 'PydanticGrammarDataConverter'

The class or the class name of the data converter.

from_namespaced: NamespacesMapping

The mapping from element names with namespace prefix to element names without namespace prefix.

name: str

The name of the grammar.

property schema: dict[str, Schema]

The dictionary representation of the schema.

to_namespaced: NamespacesMapping

The mapping from element names without namespace prefix to element names with namespace prefix.

Examples using PydanticGrammar

Use a pydantic grammar

Use a pydantic grammar