Skip to navigation

nemoguardrails.colang.v1_0.lang.comd_parser

View as MarkdownOpen in Claude

Module Contents

Functions

NameDescription
_get_param_typeHelper to return the type of a parameter.
_get_symbol_typeHelper to determine if a symbol is prefixed with its type.
_get_typed_symbol_nameReturns the symbol name prefixed with the type, if not already.
_record_utteranceHelper to record an utterance in the .md parsing result.
parse_md_fileParse a Markdown file for patterns.
parse_md_langReturns the language of the .md file.
parse_patternParses a pattern from the Markdown-friendly format to an internal format.

Data

SYMBOL_TYPES

API

nemoguardrails.colang.v1_0.lang.comd_parser._get_param_type(
type_str
)

Helper to return the type of a parameter.

For now we use a simple heuristic:

  1. If it’s a primitive type, we leave it as such.

  2. If it already has some sort of prefix with ”:”, we leave it as such.

  3. If it starts with lower case and it’s not one of the primitive types then we map it to “type:…”

  4. If it starts with an upper case, then we map it to an “object:…”

Parameters:

type_str

A string representing the type.

Returns:

The actual type.

nemoguardrails.colang.v1_0.lang.comd_parser._get_symbol_type(
sym
)

Helper to determine if a symbol is prefixed with its type.

:param sym: The name of the symbol.

nemoguardrails.colang.v1_0.lang.comd_parser._get_typed_symbol_name(
sym: str,
symbol_type: str
)

Returns the symbol name prefixed with the type, if not already.

nemoguardrails.colang.v1_0.lang.comd_parser._record_utterance(
result: dict,
sym: str,
symbol_params: list,
symbol_context: typing.Optional[str],
symbol_meta: dict,
symbol_context_meta: dict,
data: typing.Union[str, dict]
)

Helper to record an utterance in the .md parsing result.

It supports both string utterances and rich utterances.

Parameters:

result
dict

The result to append the utterance to.

sym
str

The current symbol e.g. “utterance:welcome”

symbol_params
list

Any additional symbol parameters. It is an array like [“$role=admin”, “channel.type=messenger”]

symbol_context
Optional[str]

An additional contextual expression that must be evaluated to True/False.

symbol_meta
dict

Meta information for the symbol in general.

data
Union[str, dict]

The data for the utterance, either string or something “rich”

Returns:

nemoguardrails.colang.v1_0.lang.comd_parser.parse_md_file(
file_name,
content = None
)

Parse a Markdown file for patterns.

The content can be also passed as a parameter to skip reading it.

Parameters:

file_name

A markdown file

content
Defaults to None

The content of the file.

Returns:

A list of patterns.

nemoguardrails.colang.v1_0.lang.comd_parser.parse_md_lang(
file_name,
content = None
)

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.

nemoguardrails.colang.v1_0.lang.comd_parser.parse_pattern(
pattern
)

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:

pattern

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.

nemoguardrails.colang.v1_0.lang.comd_parser.SYMBOL_TYPES = ['intent', 'object', 'type', 'property', 'utterance', 'sym', 'lookup']