Interpreter for the expression language used in AutomationEdge AIStudio dialog designer
Project description
ddcompiler
ddcompiler is the parser used by AutomationEdge AI Studio dialog designer. In dialog designer, conditions can be used either in an action dialog element or a branch dialog element. A condition is an expression which evaluates either to True or False. ddcompiler has a lexer and a parser which respectively tokenizes and parses the given expression.
Installation
pip install ddcompiler will install the library. It has been tested with Python 3.9.6, but should work with any Python 3.* version.
Basic Usage
import ddcompiler as ddc
var_dict = {
'conv.lang': 'fr',
}
# Variables used in the expression of the form ${var_name} should be present in the var_dict.
expression = '${conv.lang} == "fr" or ${conv.lang} == "de" and contains("aistudio", "studio")'
# Instantiate parser and lexer, pass expression to the lexer.
ddparser = ddc.DDParser(ddc.DDLexer(expression))
tree = ddparser.parse()
# Prints parse tree
tree.traverse()
# Get list of variables used in the expression in form of a set
print(f"VARIABLES in the expression: {ddparser.get_variables()}")
tree.set_var_dict(var_dict)
print(f"INPUT: {expression}")
print(f"EVALUATION: {tree.evaluate()}")
Expression Language
Visit AI Studio documentation to get list of supported constructs.
More Examples
Go through test_parser.py to see different examples of expressions.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ddcompiler-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 245d790f4b610b0b9c8c8629d3bdfef452ba8cbeb1f9293f1d9239d9a3447c93 |
|
MD5 | 4b49f4f015b44093b43343dd282f593d |
|
BLAKE2b-256 | 8715a03b8abca2fcc414b8dcae7d98a90915338619a1797b71347500424ffdc4 |