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',
}
expression = '${conv.lang} == "fr" or ${conv.lang} == "de" and contains("aistudio", "studio")'
ddparser = ddc.DDParser(ddc.DDLexer(expression))
tree = ddparser.parse()
tree.traverse()
print(f"VARIABLES in the expression: {ddparser.get_variables()}")
print(f"INPUT: {expression}")
print(f"EVALUATION: {tree.evaluate(var_dict)}")
Expression Language
Visit AI Studio documentation to get list of supported constructs.
More Examples
Go through parser test file to see different examples of expressions.