Dialects

This section discusses the concepts of Parser, Compiler and Dialect

The OMI tool handles all metadata in an internal data structure that covers the relevant information needed to describe data. Different metadata formats (e.g. the OEP metadata format) can be parsed into this structure or compiled from it.

Therefore, OMI uses the notion of Parser and Compiler. A Dialect combines the functionalities of Parser, Compiler and adds some convenience methods to it. Each dialect has an id that can be used to call it via the command line interface

Available dialects are:
  • oep-v1.3
  • oep-v1.4
  • oep-rdf-v1.4
class omi.dialects.base.dialect.Parser[source]

A parser is used to transform to read a specific metadata format and transform it into the internal metadata representation.

is_file_valid(file: str, **kwargs)[source]

Verify whether the contents of the file under file is parsable by this parser

Parameters:
  • file (str) – Path to the file to validate
  • **kwargs
Returns:

bool – Returns True iff the file’s content is parsable

is_valid(inp: str) → bool[source]

Verify whether inp is a sting representation that is parsable by this parser

Parameters:inp (str) – String to verify
Returns:bool – Indicated whether this object is parsable or not
load_string(string: str, *args, **kwargs)[source]

Load a string into the structure represented by the dialect :Parameters: string (str)

Returns:Translates the passed string into the format used as input for this parser
parse(structure: T, *args, **kwargs) → omi.structure.OEPMetadata[source]

Transforms the input structure into metadata as used by the OpenEnergyPlatform

Parameters:inp (str) – The input string that should be parsed into OEP metadata
Returns:OEPMetadata – OEP metadata represented by inp
parse_from_string(string: str, load_args=None, parse_args=None, load_kwargs=None, parse_kwargs=None) → omi.structure.OEPMetadata[source]

Parse a string into OEPMetadata

Parameters:string
class omi.dialects.base.dialect.Compiler[source]

Compiles Compilable objects into the respective metadata format. Every omi compiler should inherit from this class

visit(obj, *args, **kwargs)[source]

Calls the respective compiler for Compilable objects respective to Compilable.__compiler_name__

Parameters:obj – Object to compile
Returns:Metadata representation of obj
class omi.dialects.base.dialect.Dialect[source]
compile(obj: omi.structure.OEPMetadata, *args, **kwargs)[source]

Compiles the passed OEPMetadata-object into the structure fitting for this dialect

Parameters:obj – The OEPMetadata-object to compile
compile_and_render(obj: omi.structure.OEPMetadata, *args, **kwargs)[source]

Combination of compile() and render().

parse(string: str, *args, **kwargs) → omi.structure.OEPMetadata[source]

Loads the passed string into an OEPMetadata-object.

Parameters:string – The string to parse
Returns:The OEPMetadata-object represented by string
render(structure, *args, **kwargs) → str[source]

Turns the structure used by this dialect into a string

Parameters:structure – The structure to stringify
Returns:A string representation of structure