nemoguardrails.colang.v1_0.lang.comd_parser
nemoguardrails.colang.v1_0.lang.comd_parser
Module Contents
Functions
Data
API
Helper to return the type of a parameter.
For now we use a simple heuristic:
-
If it’s a primitive type, we leave it as such.
-
If it already has some sort of prefix with ”:”, we leave it as such.
-
If it starts with lower case and it’s not one of the primitive types then we map it to “type:…”
-
If it starts with an upper case, then we map it to an “object:…”
Parameters:
A string representing the type.
Returns:
The actual type.
Helper to determine if a symbol is prefixed with its type.
:param sym: The name of the symbol.
Returns the symbol name prefixed with the type, if not already.
Helper to record an utterance in the .md parsing result.
It supports both string utterances and rich utterances.
Parameters:
The result to append the utterance to.
The current symbol e.g. “utterance:welcome”
Any additional symbol parameters. It is an array like [“$role=admin”, “channel.type=messenger”]
An additional contextual expression that must be evaluated to True/False.
Meta information for the symbol in general.
The data for the utterance, either string or something “rich”
Returns:
Parse a Markdown file for patterns.
The content can be also passed as a parameter to skip reading it.
Parameters:
A markdown file
The content of the file.
Returns:
A list of patterns.
Returns the language of the .md file.
The content can be also passed as a parameter to skip reading it.
It searches for lang: XX in a yaml code block.
By default it assumes the language is English.
Parses a pattern from the Markdown-friendly format to an internal format.
For example, a pattern with an implicit user assignment and a captured deal
status returns ("show me the deals I've {deal__status}", {"user": "CURRENT"}).
Assignment patterns are transformed into capture placeholders and record
an implicit mapping such as {"user=CURRENT": "me"}.
Parameters:
The pattern in Markdown-friendly format.
Returns:
A tuple (pattern, params) where pattern is a pattern containing only text and {capture} tokens, params is a dict of ‘implicit’ parameter values.