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:…”
:param type_str: A string representing the type. :return: 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.
:param result: The result to append the utterance to. :param sym: The current symbol e.g. “utterance:welcome” :param symbol_params: Any additional symbol parameters. It is an array like [“$role=admin”, “channel.type=messenger”] :param symbol_context: An additional contextual expression that must be evaluated to True/False. :param symbol_meta: Meta information for the symbol in general. :param symbol_meta: Meta information for the symbol in this context. :param data: The data for the utterance, either string or something “rich” :return:
Parse a Markdown file for patterns.
The content can be also passed as a parameter to skip reading it.
:param file_name: A markdown file :param content: The content of the file. :return: 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. E.g. parse_pattern(“show me the deals I’ve won”) = (show me the deals I’ve {deal__status}, {‘user’: ‘CURRENT’}).
For patters with “assignment patterns” like “show me the deals” we transform it into: “show {user=CURRENT} the deals” with the mapping: { “user=CURRENT”: “me” }
:param pattern: The pattern in Markdown-friendly format. :return: A tuple (pattern, params) where pattern is a pattern containing only text and {capture} tokens, params is a dict of ‘implicit’ parameter values.