**Dialog Flow Script Parser** is python module add-on for [Dialog Flow Framework](https://github.com/deepmipt/dialog_flow_framework), a free and open-source software stack for creating chatbots, released under the terms of Apache License 2.0.
Project description
Dialog Flow Script Parser
Dialog Flow Script Parser is python module add-on for Dialog Flow Framework, a free and open-source software stack for creating chatbots, released under the terms of Apache License 2.0.
Dialog Flow Script Parser allows you to parse python files in order to extract inputs and dictionaries.
Quick Start
Installation
pip install df_script_parser
py2yaml
df_script_parser.py2yaml --help
usage: df_script_parser.py2yaml [-h] INPUT_FILE OUTPUT_DIR
Parse python script INPUT_FILE into import.yaml containing information about imports used in the script,
script.yaml containing a dictionary found inside the file.
If the file contains an instance of df_engine.Actor class its arguments will be parsed and special labels will be placed in script.yaml.
All the files are stored in OUTPUT_DIR.
positional arguments:
INPUT_FILE Python script to parse.
OUTPUT_DIR Directory to store parser output in.
optional arguments:
-h, --help show this help message and exit
NOTE: Use py2yaml
parser in the same python environment that is used to launch the script otherwise site packages will not be found.
File formats
File INPUT_FILE
should be a .py
file with the following structure:
- It may have any import statements except for star imports (
from . import *
). - It may have one
dict
declaration. - It may have one
df_engine.core.Actor
call.
The OUTPUT_DIR
will contain:
- File
import.yaml
containing information about modules imported in the script. The file has 3 keys: (pypi
,system
,local
). Each value is a dictionary with additional package information as key and code that imports that module as value. - Modules installed via pip are placed under the
pypi
key. The additional information for such modules is a string that goes afterpip install
in order to install the package. - System modules are placed under the
system
key. The additional information for such modules is the module's name. - Local modules are placed under the
local
key. The additional information for such modules is the path to the file. The path is relative if possible. - File
script.yaml
containing the dictionary's structure. Any objects in the dictionary except for other dictionaries and lists are replaced with their string representation. If given imports it is unclear whether a string is a python code or just a string tag!str
is applied.
- If the
INPUT_FILE
has adf_engine.core.Actor
call its argumentsstart_label
andfallback_label
are marked in thescript.yaml
with the!start
,!start:str
,!fallback
or!fallback:str
tags.
yaml2py
df_script_parser.yaml2py --help
usage: df_script_parser.yaml2py [-h] INPUT_DIR OUTPUT_FILE
Generate a python script OUTPUT_FILE from import.yaml and script.yaml inside the INPUT_DIR.
Generation rules:
* If a string inside the script.yaml is a correct python code within the context of imports it will be displayed in the OUTPUT_FILE without quotations.
If you want to specify how the string should be displayed use !str tag for strings and !py tag for lines of code.
* If a {dictionary {key / value} / list value} has a !start or !start:str or !start:py tag the path to that element will be stored in a start_label variable.
* If a {dictionary {key / value} / list value} has a tag !fallback or !fallback:str or !fallback:py tag the path to that key will be stored in a fallback_label variable.
positional arguments:
INPUT_DIR Directory with yaml files.
OUTPUT_FILE Python file, output.
optional arguments:
-h, --help show this help message and exit
File formats
File OUTPUT_FILE
contains a python script with a df_engine.core.Actor
call the arguments of which are extracted from the INPUT_DIR/script.yaml
file.
All the imports from INPUT_DIR/import.yaml
are imported in the OUTPUT_FILE
.
If a script has a string instance inside of it, it is displayed in the OUTPUT_FILE
without quotations if the string is a valid python expression in the context of imports. If it is not a valid python expression it is displayed with quotations. If a string should be displayed with quotations even though it is a valid python expression use the !str
tag. If a string should be displayed without the quotations use the !py
tag.
If a script has a tag !start
or !start:str
or !start:py
the path to that tag is stored inside the start_label
variable. Tag !start
is used to let the program decide whether to use quotations. This behavior may be specified using the !start:str
and !start:py
tags.
If a script has a tag !fallback
or !fallback:str
or !fallback:py
the path to that tag is stored inside the fallback_label
variable. Tag !fallback
is used to let the program decide whether to use quotations. This behavior may be specified using the !fallback:str
and !fallback:py
tags.
To get more advanced examples, take a look at examples on GitHub.
Contributing to the Dialog Flow Script Parser
Please refer to CONTRIBUTING.md.
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 df_script_parser-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f318dbdaa572247a4d93e75d34bbfe7d2a8d67b848c5a49ca09fb38257a27a4 |
|
MD5 | 034c612f66e2c9c010f2004b4d89a38a |
|
BLAKE2b-256 | 0557f517343a7d7e42a4758b984f2a2004f2dc625038209923ee77dcd6b7ca16 |