-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_faq.py
42 lines (30 loc) · 1.43 KB
/
process_faq.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import sys
import math
import pandas as pd
from anytree import Node, PreOrderIter
from chatdialogflow import BaseNode, ButtonCaseIdListNode, JumpToNode, LeafNode, DialogFlowForest, WorkspaceCaseId, NodeToDrlRulePrinterSingleton, isBlank, InputTableValidator
myValidator = InputTableValidator()
df = pd.read_excel('faq.xlsx') # or read_sql()
###############################################################################
# This is a demo/test of happy flow on a well formed input table
###############################################################################
# Validation pass
myValidator.preScanPass(df)
myValidator.validationPass(df)
###############################################################################
# main pass building tree
# loop through the rows using iterrows()
dialogFlowForest = DialogFlowForest()
dialogFlowForest.buildForrestFromInputTable(df)
# TODO: tree verifier
##############################################
# tree visualization dump
dialogFlowForest.printForest(sys.stdout)
dialogFlowForest.printMermaid(sys.stdout)
NodeToDrlRulePrinterSingleton().printHeader(sys.stdout)
#print(dialogFlowForest.getTreeRootsList())
for root in dialogFlowForest.getTreeRootsList():
for node in PreOrderIter(root):
NodeToDrlRulePrinterSingleton().printRuleCommentForNode(node, sys.stdout)
NodeToDrlRulePrinterSingleton().printRuleForNode(node, sys.stdout)
print("##############", file=sys.stdout)