-
Notifications
You must be signed in to change notification settings - Fork 0
/
nlg_build_commentary.py
172 lines (145 loc) · 5.87 KB
/
nlg_build_commentary.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import random
from nlglib.microplanning import *
from nlglib.realisation.simplenlg.realisation import Realiser
realise = Realiser(host='nlg.kutlak.info')
def build_cluases_style1():
"""positive verbs"""
verbs_p = ["increse", "rise", "surge"]
chosen_p_verb = random.choice(verbs_p)
"""negative verbs"""
verbs_n = ["fall", "drop"]
chosen_n_verb = random.choice(verbs_n)
adverbs = ["steeply", "sharply"]
chosen_adverb = random.choice(adverbs)
return chosen_p_verb,chosen_n_verb, chosen_adverb
def build_commentary_sytle1(account_code, total_variance):
chosen_p_verb, chosen_n_verb, chosen_adverb = build_cluases_style1()
if total_variance > 0:
chosen_verb = chosen_p_verb
elif total_variance < 0:
chosen_verb = chosen_n_verb
subject = NP(account_code)
verb = VP(chosen_verb)
verb += Adverb(chosen_adverb)
report_statement = Clause()
report_statement.subject = subject
report_statement.predicate = verb
report_statement.predicate.complements += PP('by')
object = NP(total_variance)
report_statement.object = object
report_statement['TENSE'] = 'PAST'
A = (realise(report_statement))
return A
def build_clauses_substyle1():
"""positive verbs"""
verbs_p = ["increse in", "rise in", "surge in"]
chosen_p_verb = random.choice(verbs_p)
"""negative verbs"""
verbs_n = ["fall in", "drop in", "decrease in"]
chosen_n_verb = random.choice(verbs_n)
predicate_verbs = ["attribute", "due"]
chosen_pred_verbs = random.choice(predicate_verbs)
return chosen_p_verb, chosen_n_verb, chosen_pred_verbs
def build_commentary_substyle1():
chosen_p_verb, chosen_n_verb, chosen_pred_verbs = build_cluases_style1()
reasons1 = Clause()
reasons1.subject = NP("the variance is")
reasons1.predicate = VP(chosen_pred_verbs)
resons1['TeNSe'] = 'PAST'
reasons1.predicate.complements += PP('to')
B = realise(reasons1)
B = B[:-1]
return B
def build_commentary_substyle1A(flag, variance_format_rollup):
chosen_p_verb, chosen_n_verb, chosen_pred_verbs = build_clauses_substyle1()
parameter = ""
if flag == "P":
parameter = chosen_p_verb
elif flag == "N":
parameter == chosen_n_verb
else:
parameter = ""
reasons1 = Clause()
reasons1.subject += NP(parameter)
reasons1.object = NP(variance_format_rollup)
B = realise(reasons1)
B = B[0].lower() + b[1:]
return B
def build_clauses_style2():
"""positive verbs"""
verbs_p = ["increse", "rise", "surge"]
chosen_p_verb = random.choice(verbs_p)
"""negative verbs"""
verbs_n = ["fall", "drop"]
chosen_n_verb = random.choice(verbs_n)
adverbs = ["steep", "sharp"]
chosen_adverb = random.choice(adverbs)
return chosen_p_verb, chosen_n_verb, chosen_adverb
def build_commentary_style2(account_code, total_variance):
chosen_p_verb, chosen_n_verb, chosen_adverb = build_cluases_style2()
if total_variance > 0:
chosen_verb = chosen_p_verb
elif total_variance < 0:
chosen_verb = chosen_n_verb
subject = NP(account_code)
verb = NP(chosen_verb)
verb += Adverb(chosen_adverb)
report_statement = Clause()
report_statement.subject = subject
report_statement.predicate = verb
report_statement.predicate.complements += PP('in')
object = NP(account_code), NP(str("by")), NP(str(total_variance))
report_statement.predicate.complements += object
report_statement['TENSE'] = 'PAST'
A = (realise(report_statement))
return A
def build_clauses_substyle2():
"""positive verbs"""
verbs_p = ["increse in", "rise in", "surge in"]
chosen_p_verb = random.choice(verbs_p)
"""negative verbs"""
verbs_n = ["fall in", "drop in", "decrease in"]
chosen_n_verb = random.choice(verbs_n)
predicate_verbs = ["is attributed", "is due"]
chosen_pred_verbs = random.choice(predicate_verbs)
return chosen_p_verb, chosen_n_verb, chosen_pred_verbs
def build_commentary_substyle2():
chosen_p_verb, chosen_n_verb, chosen_pred_verbs = build_cluases_substyle2()
reasons1 = Clause()
reasons1.subject = NP(random.choice([("the reason behind"),("the cause of")]))
reasons1.subject.complements += NP("variance")
reasons1.subject.complements += VP(chosen_pred_verbs)
reasons1['TENSE'] = 'PAST'
reasons1.subject.complements += PP('to')
B = realise(reasons1)
B = B[:-1] + " "
return B
def build_commendatry_substyle2A(flag, variance_format_rollup):
chosen_p_verb, chosen_n_verb, chosen_pred_verbs = build_clauses_substyle2()
parameter = ""
if flag == "P":
parameter = chosen_p_verb
elif flag == "N":
parameter == chosen_n_verb
else:
parameter = ""
reasons1 = Clause()
reasons1.subject += NP(parameter)
reasons1.object = NP(variance_format_rollup)
B = realise(reasons1)
B = B[0].lower() + B[1:]
return B
def build_comments(account_code, flag, total_variance, variance_format_rollup):
styles = ["1","2"]
chosen_style = random.choice(styles)
if chosen_style == "1":
commentary_main = build_commentary_sytle1(account_code, total_variance)
commentary_causal1 = build_clauses_substyle1()
commentary_causal2 = build_commentary_substyle1A(flag, variance_format_rollup)
else:
commentary_main = build_commentary_style2(account_code, total_variance)
commentary_causal1 = build_clauses_substyle2()
commentary_causal2 = build_commendatry_substyle2A(flag, variance_format_rollup)
return commentary_main, commentary_causal1, commentary_causal2
if __name__ == '__main__':
commentary_main, commentary_causal1, commentary_causal2 = build_comments(account_code, flag, total_variance, variance_format_rollup)