-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbullshit_generator_lea.py
288 lines (254 loc) · 11.9 KB
/
bullshit_generator_lea.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
'''
======================================================================
Bullshit Generator
by Pierre Denis, 2009, 2014
======================================================================
'''
# --------------------------------------------------
# grammar engine
# --------------------------------------------------
from lea import Lea
class Node(object):
def setTermsChoices(self,*termsChoices):
self.termsChoices = Lea.fromValFreqs(*termsChoices)
def getWords(self):
terms = self.termsChoices.random()
for term in terms:
if isinstance(term,str):
yield term
else:
for word in term.getWords():
yield word
def getString(self):
res = " ".join(self.getWords())
res = ", ".join(w.strip() for w in res.split(",") if w.strip())
if res.endswith(", "):
res = res[:-2]
return res[0].upper() + res[1:] + "."
class TerminalNode(object):
def __init__(self,*words):
self.words = Lea.fromVals(*words)
def getWords(self):
yield self.words.random()
# --------------------------------------------------
# grammar
# --------------------------------------------------
verb = TerminalNode(
"accesses", "activates", "administrates", "aggregates", "builds",
"calculates", "checks", "competes with", "completes", "complies with",
"controls", "covers", "delivers", "dispatches", "eases", "encapsulates",
"encompasses", "executes", "extracts", "features",
"generates", "gets", "governs", "guides", "has", "increases",
"inherits from", "is", "keeps track of", "leverages", "makes",
"manages",
"manages", "maximizes", "mitigates", "monitors", "must have", "needs",
"offers", "opens", "operates on", "optimizes", "orchestrates",
"overwrites", "performs", "populates", "precludes", "provides",
"provides",
"provides an interface to", "reads", "receives", "reduces",
"reduces the need of", "registers", "regulates", "relies on",
"requires",
"resides on", "resides within", "retrieves", "retrieves the data in",
"runs on",
"schedules", "integrates with", "sends", "shall be",
"shall have", "should be", "should have", "starts", "stores",
"streamlines", "subscribes to", "subscribes to", "supersedes", "takes",
"targets", "triggers", "updates", "validates", "writes")
passiveVerb = TerminalNode(
"accessed by", "achieved by", "aggregated by", "applicable for",
"asserted by", "authorized by",
"based upon", "built from", "built upon", "collected by",
"controlled by",
"dedicated to", "deployed on", "derived from", "dispatched by",
"driven by", "eased by", "enabled by", "envisioned in",
"extracted from", "generated by", "in the scope of", "installed on",
"integrated in",
"located in", "managed by", "maximized by", "monitored by", "opened by",
"optimized by", "orchestrated by", "packaged in", "performed by",
"populated by", "processed by", "provided by", "provided by",
"received by", "refreshed by", "registered in", "related to",
"required by",
"responsible for", "scheduled by", "sent to", "serialized by",
"serialized in", "started in", "stored by", "stored in", "stored on",
"the interface of", "updated by", "validated by")
aSimpleName = TerminalNode(
"COTS", "GRID processing",
"Java program", "LDAP registry", "Portal", "RSS feed", "SAML token",
"SOAP message", "SSO", "TCP/IP", "UML model", "URL",
"W3C", "Web", "Web 2.0", "Web browser", "Web page",
"Web service", "back-end", "backbone", "bandwidth", "bean",
"bridge", "browser", "bus", "business", "business model", "call",
"catalogue", "class", "client", "cluster", "collection",
"communication", "component", "compression",
"concept", "conceptualization", "connexion", "console", "content",
"context", "cookie", "customization", "data", "database",
"datastore", "deployment",
"derivation rule", "design", "development", "device", "directory",
"discovery", "dispatcher", "document", "domain", "factory",
"fat client", "feature", "file", "form", "frame", "framework",
"function", "gateway", "genericity", "geomanagement", "goal",
"governance", "granularity", "guideline", "header", "key", "layer",
"leader", "library", "link", "list", "log file", "logic",
"look-and-feel",
"manager", "market", "mechanism", "message", "meta-model",
"metadata", "model", "modeling", "module", "network", "performance",
"persistence", "personalization", "plug-in", "policy", "port",
"portal", "practice",
"presentation layer", "privacy", "private key", "procedure",
"process", "processor", "processing", "product", "protocol",
"recommendation",
"registration", "registry", "relationship", "resource",
"responsibility", "role",
"rule", "scenario", "scenario", "scheduler", "schema", "security",
"server", "service", "service provider", "servlet", "session",
"skeleton", "software", "solution", "source", "space",
"specification", "standard", "state", "statement", "streaming",
"style sheet", "subscriber", "subsystem", "system", "system",
"table", "target", "task", "taxonomy", "technique", "technology",
"template", "thin client", "thread", "throughput", "timing", "tool",
"toolkit", "topic", "unit", "usage", "use case", "user",
"user experience", "validation", "value", "version", "vision", "work",
"workflow")
anSimpleName = TerminalNode(
"API", "IP address", "Internet", "UDDI", "XML", "XML file",
"abstraction", "access", "acknowledgment", "action", "actor",
"administrator", "aggregator", "algorithm", "application", "approach",
"architecture", "artifact", "aspect", "authentication", "availability",
"encapsulation", "end-point", "engine", "engine", "entity",
"entity", "environment", "event", "identifier", "information",
"integration", "interface", "interoperability", "issuer", "object",
"ontology", "operation", "operator", "operator", "opportunity",
"orchestration", "owner")
aAdjective = TerminalNode(
"BPEL", "DOM", "DTD", "GRID", "HTML", "J2EE",
"Java", "Java-based", "Java-based", "UML", "SAX", "WFS", "WSDL",
"basic", "broad", "bug-free",
"business-driven", "client-side", "coarse", "coherent", "compatible",
"complete", "compliant", "comprehensive", "conceptual", "consistent",
"control", "controller", "cost-effective",
"custom", "data-driven", "dedicated", "distributed",
"dynamic", "encrypted", "event-driven", "fine-grained", "first-class",
"free", "full",
"generic", "geo-referenced", "global", "global", "graphical",
"high-resolution", "high-level", "individual", "invulnerable",
"just-in-time", "key",
"layered", "leading", "lightweight", "logical", "main", "major",
"message-based",
"most important", "multi-tiers", "narrow", "native", "next",
"next-generation",
"normal", "password-protected", "operational", "peer-to-peer",
"performant", "physical",
"point-to-point", "polymorphic", "portable", "primary", "prime",
"private", "proven", "public", "raw", "real-time", "registered",
"reliable", "remote",
"respective", "right", "robust", "rule-based", "scalable", "seamless",
"secondary", "semantic",
"server-side", "service-based", "service-oriented", "simple", "sole",
"specific", "state-of-the-art", "stateless", "storage", "sufficient",
"technical", "thread-safe", "uniform", "unique", "used", "useful",
"user-friendly", "virtual", "visual", "web-based", "web-centric",
"well-documented", "wireless", "world-leading", "zero-default")
anAdjective = TerminalNode(
"AJAX", "OO", "XML-based", "abstract", "ancillary", "asynchronous",
"authenticated", "authorized", "auto-regulated", "available", "aware",
"efficient",
"international", "interoperable", "off-line", "official", "online",
"open", "operational",
"other", "own", "unaffected", "up-to-date")
adverb = TerminalNode(
"basically", "comprehensively", "conceptually", "consistently",
"definitely", "dramatically",
"dynamically", "expectedly", "fully", "generally", "generically",
"globally", "greatly", "individually", "locally", "logically",
"mainly", "mostly", "natively",
"officially", "physically", "practically", "primarily",
"repeatedly", "roughly", "sequentially", "simply", "specifically",
"surely", "technically", "undoubtly", "usefully", "virtually")
sentenceHead = TerminalNode(
"actually", "as a matter of fact", "as said before", "as stated before",
"basically", "before all", "besides this", "beyond that point",
"clearly",
"conversely", "despite these facts", "for this reason",
"generally speaking",
"if needed", "in essence", "in other words", "in our opinion",
"in the long term", "in the short term", "in this case", "incidentally",
"moreover", "nevertheless", "now", "otherwise", "periodically",
"roughly speaking", "that being said", "then", "therefore",
"to summarize", "up to here", "up to now", "when this happens")
(name, aName, anName, nameTail, adjective, nameGroup,
simpleNameGroup, verbalGroup, simpleVerbalGroup, sentence,
sentenceTail) = [Node() for i in range(11)]
aName.setTermsChoices(
(( aSimpleName, ), 50 ),
(( aSimpleName, name ), 5 ),
(( aSimpleName, name ), 8 ),
(( aName, nameTail ), 5 ))
anName.setTermsChoices(
(( anSimpleName, ), 50 ),
(( anSimpleName, name ), 8 ),
(( anName, nameTail ), 5 ))
nameTail.setTermsChoices(
(( "of", nameGroup ), 2 ),
(( "from", nameGroup ), 2 ),
(( "under", nameGroup ), 1 ),
(( "on top of", nameGroup ), 1 ))
name.setTermsChoices(
(( aName, ), 1 ),
(( anName, ), 1 ))
adjective.setTermsChoices(
(( aAdjective, ), 1 ),
(( anAdjective, ), 1 ))
nameGroup.setTermsChoices(
(( simpleNameGroup, ), 10 ),
(( simpleNameGroup, passiveVerb, nameGroup ), 1 ),
(( simpleNameGroup, "that", simpleVerbalGroup ), 1 ),
(( simpleNameGroup, ", which", simpleVerbalGroup, "," ), 1 ))
simpleNameGroup.setTermsChoices(
(( "the", name ), 40 ),
(( "the", adjective, name ), 20 ),
(( "a", aName ), 10 ),
(( "an", anName ), 10 ),
(( "a", aAdjective, name ), 5 ),
(( "an", anAdjective, name ), 5 ))
verbalGroup.setTermsChoices(
(( verb, nameGroup ), 10 ),
(( adverb, verb, nameGroup ), 1 ),
(( "is", passiveVerb, nameGroup ), 10 ),
(( "is", adverb, passiveVerb, nameGroup ), 1 ),
(( "is", adjective ), 1 ),
(( "is", adverb, adjective ), 1 ))
simpleVerbalGroup.setTermsChoices(
(( verb, simpleNameGroup ), 2 ),
(( "is", adjective ), 1 ))
sentence.setTermsChoices(
(( nameGroup, verbalGroup ), 20 ),
(( sentenceHead, "," , nameGroup, verbalGroup ), 4 ),
(( sentence, sentenceTail ), 4 ))
sentenceTail.setTermsChoices(
(( "in", nameGroup ), 12 ),
(( "within", nameGroup ), 5 ),
(( "where", nameGroup, verbalGroup ), 5 ),
(( "when", nameGroup, verbalGroup ), 5 ),
(( "because it", verbalGroup ), 2 ),
(( "; that's why it", verbalGroup ), 1 ))
# --------------------------------------------------
# main program
# --------------------------------------------------
try:
import win32com.client
voice = win32com.client.Dispatch("sapi.SPVoice")
except:
voice = None
print ("press <enter> to resume, 'q'+<enter> to quit\n")
while True:
print ('')
for i in range(8):
generatedSentence = sentence.getString()
print (generatedSentence,end='')
#print generatedSentence,
if voice:
voice.speak(generatedSentence)
cmd = input()
#cmd = raw_input()
if cmd.strip().lower() == "q":
break