-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvkgEnglishComment.lsp
136 lines (113 loc) · 5.89 KB
/
vkgEnglishComment.lsp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Paul Koop M.A. - Sequence Analysis of Empirically Validated ;;
;; Sales Conversations ;;
;; ;;
;; This program simulates sales conversations by modeling a ;;
;; context-free grammar (CFG) in Lisp. The goal is to analyze ;;
;; and generate dialog sequences based on a recursively ;;
;; structured, weighted grammar. ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Grammar Structure for Sales Conversations (VKG)
;; -------------------------------------------
;; Main node: VKG
;; Transitions and weights reflect the probabilities of sales
;; conversation sequences (e.g., Greeting → Need Assessment).
;;
;; VKG -> Greeting (BG) -> Sales Activity (VT) -> Farewell (AV)
;; The possible patterns are modeled and weighted based on empirical data.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Symbol Definitions for Conversation Components ;;
;; ;;
;; Sales Conversation := VKG ;;
;; Sales Activity := VT ;;
;; Greeting := BG ;;
;; Need := B ;;
;; Need Analysis := BA ;;
;; Objection Handling := AE ;;
;; Closing := AA ;;
;; Farewell := AV ;;
;; Customer := K (prefix for customer statements) ;;
;; Seller := V (prefix for seller statements) ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Main Structure of the Sales Conversation as CFG Rules ;;
;; VKG starts with a greeting and ends with a farewell ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq vkg
'(((bg) 100 (vt)) ;; Greeting → Sales Activity
((vt) 50 (vt)) ;; Repeated Sales Activity
((vt) 100 (av)))) ;; Sales Activity → Farewell
;; Greeting Rule - Customer and Seller exchange greetings
(setq bg
'((kbg 100 vbg)))
;; Need part of the conversation - Customer states need, Seller acknowledges
(setq bbd
'((kbbd 100 vbbd)))
;; Need Analysis - Both parties discuss the need
(setq ba
'((kba 100 vba)))
;; Objection Handling in Closing - Customer and Seller address objections
(setq ae
'((kae 100 vae)))
;; Closing the conversation - Customer and Seller close the deal
(setq aa
'((kaa 100 vaa)))
;; Final Farewell - Customer and Seller say goodbye
(setq av
'((kav 100 vav)))
;; Sales Activity, consisting of need and closing phases
(setq vt
'(((b) 50 (b)) ;; Need Part
((b) 100 (a)))) ;; Need → Closing
;; Structure of the Need Part in the Sales Conversation
(setq b
'(((bbd) 100 (ba)))) ;; Need Exchange → Need Analysis
;; Closing Structure - consisting of objections and closing
(setq a
'(((ae) 50 (ae)) ;; Repeated Objections
((ae) 100 (aa)))) ;; Objections → Closing
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Sequence Generation Based on Rules ;;
;; ;;
;; The following function generates dialog sequences according ;;
;; to the defined rules and weights. It simulates the dialogue ;;
;; flow according to the CFG. ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Main function to generate the sequence
(defun generate-sequence (state rules)
"Generates a sequence based on the current state and the rules."
(cond
;; Sequence end reached, return nil
((equal state nil) nil)
;; If state is terminal, return it directly and move to the next
((atom state) (cons state (generate-sequence (next-state state rules (random 101)) rules)))
;; Otherwise, expand the non-terminal state and proceed recursively
(t (cons (eval state) (generate-sequence (next-state state rules (random 101)) rules)))))
;; Function to select the next state
(defun next-state (state rules probability)
"Selects the next state based on rules and a random probability."
(cond
;; If no more rules, return nil
((equal rules nil) nil)
;; Checks if the rule matches the probability and returns the successor
((and (<= probability (car (cdr (car rules))))
(equal state (car (car rules))))
(car (reverse (car rules))))
;; Otherwise, continue searching the remaining rules
(t (next-state state (cdr rules) probability))))
;; Helper function to select the first sequence rule
(defun initial-rule (rules)
"Selects the first rule from the rule set."
(car (car rules)))
;; Starts the simulation for the scenario structure
(defun simulate (rules)
"Starts sequence generation based on the initial rules."
(generate-sequence (initial-rule rules) rules))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Start Simulation and Generate Sequences ;;
;; ;;
;; (simulate vkg) calls the simulation for the sales conversation;;
;; and returns the generated sequence. ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The simulation is started for World 3 (sales conversation structure)
(simulate vkg)