nemoguardrails.colang.v1_0.lang.colang_parser
nemoguardrails.colang.v1_0.lang.colang_parser
Module Contents
Classes
Functions
Data
API
create a namespace.
Helper to extract the indentation levels higher than the current line.
Helper to extract the indented lines, relative to the current line.
It also needs to take into account if the params should be indented one level or two.
Helper to extract markdown content.
The self.symbol_type and self.symbol_name must be set correctly before calling this.
It will start with the next line, and use it as a reference for the indentation level. As long as the indentation is higher, it will keep parsing the lines as markdown.
Helper to parse additional parameters for an element.
We transform the indented lines into valid YAML format. It should end up being a dict and not a list.
:param param_lines: If provided, these lines will be used to extract the params.
Helper to extract the name of a snippet. Also updates self.text.
Returns true if the current flow is a sample one.
NOTE: This will not work correctly if the current position is nested inside another branch like an “if”. But currently, it is meant for test flows, which should be linear.
Returns true if the current flow is a test one.
NOTE: This will not work correctly if the current position is nested inside another branch like an “if”. But currently, it is meant for test flows, which should be linear.
Applies a series of normalizations for a line of colang.
Parser for the bot X syntax.
The syntax is quite flexible, see example_45.co for various ways.
A meta syntax is the following:
bot <utterance_id>? “sample_utterance”? (with/for ?param (:|=) value
“sample_utterance_1”? “sample_utterance_2”?
When id and sample utterance is included, an utterance definition is also generated as markdown content.
Supports parsing labels, with or without a value.
e.g. label bla label speech hints $hints
Parses just the snippets and imports from the file.
The data is returned in the format { “snippet_name”: { “name”: “snippet_name”, “params”: [“T”, “A”], “lines”: <numbered lines> } }, [“skill_1”, …]
Parses a file in .co format to a YAML flows format.
Parameters:
- filename (str): The name of the file.
- content (str): The content of the file.
- include_source_mapping (bool): Whether to include source mapping into the flow elements.
- snippets (Optional[dict]): Snippets to use when parsing the file.
Returns: The parsed YAML flows.
Example:
Note:
- The function uses the ColangParser to convert .co format to YAML flows.
Parses snippets and imports from a file.
Parameters:
- filename (str): The name of the file.
- content (str): The content of the file.
Returns: A dictionary of snippets and a list of skill names.
Example:
Note:
- The function uses the ColangParser to extract snippets and imports.