gemseo / core / grammars

Show inherited members

simple_grammar module

A basic grammar based on names and types.

class gemseo.core.grammars.simple_grammar.SimpleGrammar(name, names_to_types=None, required_names=None, **kwargs)[source]

Bases: BaseGrammar

A grammar based on names and types with a dictionary-like interface.

The types are pure Python types, type annotations are not supported.

The grammar could be empty, in that case the data validation always pass. If the type bound to a name is None then the type of the corresponding data name is always valid.

Warning

This grammar cannot merge elements. Merging will raise an error.

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

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

  • names_to_types (SimpleGrammarTypes | None) – The mapping defining the data names as keys, and data types as values. If None, the grammar is empty.

  • required_names (Iterable[str] | None) – The names of the required elements. If None, all the elements are required.

  • **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

to_simple_grammar()[source]

Convert the grammar to a SimpleGrammar.

Returns:

A SimpleGrammar version of the current grammar.

Return type:

Self

DATA_CONVERTER_CLASS: ClassVar[str] = 'SimpleGrammarDataConverter'

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.

to_namespaced: NamespacesMapping

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