megahal 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +100 -0
- data/README.md +187 -0
- data/Rakefile +44 -0
- data/UNLICENSE +24 -0
- data/VERSION +1 -0
- data/bin/megahal +196 -0
- data/lib/megahal.rb +3 -0
- data/lib/megahal/keyword.rb +485 -0
- data/lib/megahal/megahal.rb +482 -0
- data/lib/megahal/personalities.rb +12 -0
- data/lib/megahal/personalities/aliens.rb +837 -0
- data/lib/megahal/personalities/bill.rb +163 -0
- data/lib/megahal/personalities/caitsith.rb +289 -0
- data/lib/megahal/personalities/default.rb +351 -0
- data/lib/megahal/personalities/ferris.rb +1080 -0
- data/lib/megahal/personalities/manson.rb +291 -0
- data/lib/megahal/personalities/pepys.rb +2 -0
- data/lib/megahal/personalities/pulp.rb +1527 -0
- data/lib/megahal/personalities/scream.rb +1083 -0
- data/lib/megahal/personalities/sherlock.rb +254 -0
- data/lib/megahal/personalities/startrek.rb +273 -0
- data/lib/megahal/personalities/starwars.rb +1158 -0
- data/megahal.gemspec +101 -0
- metadata +251 -0
data/lib/megahal.rb
ADDED
@@ -0,0 +1,485 @@
|
|
1
|
+
class MegaHAL
|
2
|
+
# This takes an array of capitalised (normalised) words, and returns an array
|
3
|
+
# of keywords (which simply remove banned words, and switch some words with
|
4
|
+
# their antonyms). This exists purely to emulate the original MegaHAL. It
|
5
|
+
# would be better if keywords were learned by observing question-answer pairs.
|
6
|
+
def self.extract(words)
|
7
|
+
return GREETING if words.nil?
|
8
|
+
words
|
9
|
+
.map do |word|
|
10
|
+
if word =~ /^[0-9]/
|
11
|
+
nil
|
12
|
+
elsif BANNED.include?(word)
|
13
|
+
nil
|
14
|
+
elsif SWAP.key?(word)
|
15
|
+
SWAP[word]
|
16
|
+
else
|
17
|
+
word
|
18
|
+
end
|
19
|
+
end
|
20
|
+
.compact
|
21
|
+
.uniq
|
22
|
+
end
|
23
|
+
|
24
|
+
GREETING = ["G'DAY", "GREETINGS", "HELLO", "HULLO", "HI", "HOWDY", "WELCOME"]
|
25
|
+
|
26
|
+
ANTONYMS = [
|
27
|
+
["DISLIKE", "LIKE"],
|
28
|
+
["HATE", "LOVE"],
|
29
|
+
["I", "YOU"],
|
30
|
+
["I'D", "YOU'D"],
|
31
|
+
["I'LL", "YOU'LL"],
|
32
|
+
["I'M", "YOU'RE"],
|
33
|
+
["I'VE", "YOU'VE"],
|
34
|
+
["LIKE", "DISLIKE"],
|
35
|
+
["LOVE", "HATE"],
|
36
|
+
["ME", "YOU"],
|
37
|
+
["MINE", "YOURS"],
|
38
|
+
["MY", "YOUR"],
|
39
|
+
["MYSELF", "YOURSELF"],
|
40
|
+
["NO", "YES"],
|
41
|
+
["WHY", "BECAUSE"],
|
42
|
+
["YES", "NO"],
|
43
|
+
["YOU", "I"],
|
44
|
+
["YOU", "ME"],
|
45
|
+
["YOU'D", "I'D"],
|
46
|
+
["YOU'LL", "I'LL"],
|
47
|
+
["YOU'RE", "I'M"],
|
48
|
+
["YOU'VE", "I'VE"],
|
49
|
+
["YOUR", "MY"],
|
50
|
+
["YOURS", "MINE"],
|
51
|
+
["YOURSELF", "MYSELF"],
|
52
|
+
["HOLMES", "WATSON"],
|
53
|
+
["FRIEND", "ENEMY"],
|
54
|
+
["ALIVE", "DEAD"],
|
55
|
+
["QUESTION", "ANSWER"],
|
56
|
+
["BLACK", "WHITE"],
|
57
|
+
["COLD", "HOT"],
|
58
|
+
["HAPPY", "SAD"],
|
59
|
+
["FALSE", "TRUE"],
|
60
|
+
["HEAVEN", "HELL"],
|
61
|
+
["GOD", "DEVIL"],
|
62
|
+
["NOISY", "QUIET"],
|
63
|
+
["WAR", "PEACE"],
|
64
|
+
["SORRY", "APOLOGY"]
|
65
|
+
]
|
66
|
+
SWAP = Hash[ANTONYMS + ANTONYMS.map(&:reverse)]
|
67
|
+
|
68
|
+
AUXILIARY = <<-EOS.each_line.to_a.map(&:strip)
|
69
|
+
DISLIKE
|
70
|
+
HE
|
71
|
+
HER
|
72
|
+
HERS
|
73
|
+
HIM
|
74
|
+
HIS
|
75
|
+
I
|
76
|
+
I'D
|
77
|
+
I'LL
|
78
|
+
I'M
|
79
|
+
I'VE
|
80
|
+
LIKE
|
81
|
+
ME
|
82
|
+
MINE
|
83
|
+
MY
|
84
|
+
MYSELF
|
85
|
+
ONE
|
86
|
+
SHE
|
87
|
+
THREE
|
88
|
+
TWO
|
89
|
+
YOU
|
90
|
+
YOU'D
|
91
|
+
YOU'LL
|
92
|
+
YOU'RE
|
93
|
+
YOU'VE
|
94
|
+
YOUR
|
95
|
+
YOURS
|
96
|
+
YOURSELF
|
97
|
+
EOS
|
98
|
+
|
99
|
+
BANNED = <<-EOS.each_line.to_a.map(&:strip)
|
100
|
+
A
|
101
|
+
ABILITY
|
102
|
+
ABLE
|
103
|
+
ABOUT
|
104
|
+
ABSOLUTE
|
105
|
+
ABSOLUTELY
|
106
|
+
ACROSS
|
107
|
+
ACTUAL
|
108
|
+
ACTUALLY
|
109
|
+
AFTER
|
110
|
+
AFTERNOON
|
111
|
+
AGAIN
|
112
|
+
AGAINST
|
113
|
+
AGO
|
114
|
+
AGREE
|
115
|
+
ALL
|
116
|
+
ALMOST
|
117
|
+
ALONG
|
118
|
+
ALREADY
|
119
|
+
ALTHOUGH
|
120
|
+
ALWAYS
|
121
|
+
AM
|
122
|
+
AN
|
123
|
+
AND
|
124
|
+
ANOTHER
|
125
|
+
ANY
|
126
|
+
ANYHOW
|
127
|
+
ANYTHING
|
128
|
+
ANYWAY
|
129
|
+
ARE
|
130
|
+
AREN'T
|
131
|
+
AROUND
|
132
|
+
AS
|
133
|
+
AT
|
134
|
+
AWAY
|
135
|
+
BACK
|
136
|
+
BAD
|
137
|
+
BE
|
138
|
+
BEEN
|
139
|
+
BEFORE
|
140
|
+
BEHIND
|
141
|
+
BEING
|
142
|
+
BELIEVE
|
143
|
+
BELONG
|
144
|
+
BEST
|
145
|
+
BETTER
|
146
|
+
BETWEEN
|
147
|
+
BIG
|
148
|
+
BIGGER
|
149
|
+
BIGGEST
|
150
|
+
BIT
|
151
|
+
BOTH
|
152
|
+
BUDDY
|
153
|
+
BUT
|
154
|
+
BY
|
155
|
+
CALL
|
156
|
+
CALLED
|
157
|
+
CALLING
|
158
|
+
CAME
|
159
|
+
CAN
|
160
|
+
CAN'T
|
161
|
+
CANNOT
|
162
|
+
CARE
|
163
|
+
CARING
|
164
|
+
CASE
|
165
|
+
CATCH
|
166
|
+
CAUGHT
|
167
|
+
CERTAIN
|
168
|
+
CERTAINLY
|
169
|
+
CHANGE
|
170
|
+
CLOSE
|
171
|
+
CLOSER
|
172
|
+
COME
|
173
|
+
COMING
|
174
|
+
COMMON
|
175
|
+
CONSTANT
|
176
|
+
CONSTANTLY
|
177
|
+
COULD
|
178
|
+
CURRENT
|
179
|
+
DAY
|
180
|
+
DAYS
|
181
|
+
DERIVED
|
182
|
+
DESCRIBE
|
183
|
+
DESCRIBES
|
184
|
+
DETERMINE
|
185
|
+
DETERMINES
|
186
|
+
DID
|
187
|
+
DIDN'T
|
188
|
+
DO
|
189
|
+
DOES
|
190
|
+
DOESN'T
|
191
|
+
DOING
|
192
|
+
DON'T
|
193
|
+
DONE
|
194
|
+
DOUBT
|
195
|
+
DOWN
|
196
|
+
EACH
|
197
|
+
EARLIER
|
198
|
+
EARLY
|
199
|
+
ELSE
|
200
|
+
ENJOY
|
201
|
+
ESPECIALLY
|
202
|
+
EVEN
|
203
|
+
EVER
|
204
|
+
EVERY
|
205
|
+
EVERYBODY
|
206
|
+
EVERYONE
|
207
|
+
EVERYTHING
|
208
|
+
FACT
|
209
|
+
FAIR
|
210
|
+
FAIRLY
|
211
|
+
FAR
|
212
|
+
FELLOW
|
213
|
+
FEW
|
214
|
+
FIND
|
215
|
+
FINE
|
216
|
+
FOR
|
217
|
+
FORM
|
218
|
+
FOUND
|
219
|
+
FROM
|
220
|
+
FULL
|
221
|
+
FURTHER
|
222
|
+
GAVE
|
223
|
+
GET
|
224
|
+
GETTING
|
225
|
+
GIVE
|
226
|
+
GIVEN
|
227
|
+
GIVING
|
228
|
+
GO
|
229
|
+
GOING
|
230
|
+
GONE
|
231
|
+
GOOD
|
232
|
+
GOT
|
233
|
+
GOTTEN
|
234
|
+
GREAT
|
235
|
+
HAD
|
236
|
+
HAS
|
237
|
+
HASN'T
|
238
|
+
HAVE
|
239
|
+
HAVEN'T
|
240
|
+
HAVING
|
241
|
+
HELD
|
242
|
+
HERE
|
243
|
+
HIGH
|
244
|
+
HOLD
|
245
|
+
HOLDING
|
246
|
+
HOW
|
247
|
+
IF
|
248
|
+
IN
|
249
|
+
INDEED
|
250
|
+
INSIDE
|
251
|
+
INSTEAD
|
252
|
+
INTO
|
253
|
+
IS
|
254
|
+
ISN'T
|
255
|
+
IT
|
256
|
+
IT'S
|
257
|
+
ITS
|
258
|
+
JUST
|
259
|
+
KEEP
|
260
|
+
KIND
|
261
|
+
KNEW
|
262
|
+
KNOW
|
263
|
+
KNOWN
|
264
|
+
LARGE
|
265
|
+
LARGER
|
266
|
+
LARGETS
|
267
|
+
LAST
|
268
|
+
LATE
|
269
|
+
LATER
|
270
|
+
LEAST
|
271
|
+
LESS
|
272
|
+
LET
|
273
|
+
LET'S
|
274
|
+
LEVEL
|
275
|
+
LIKES
|
276
|
+
LITTLE
|
277
|
+
LONG
|
278
|
+
LONGER
|
279
|
+
LOOK
|
280
|
+
LOOKED
|
281
|
+
LOOKING
|
282
|
+
LOOKS
|
283
|
+
LOW
|
284
|
+
MADE
|
285
|
+
MAKE
|
286
|
+
MAKING
|
287
|
+
MANY
|
288
|
+
MATE
|
289
|
+
MAY
|
290
|
+
MAYBE
|
291
|
+
MEAN
|
292
|
+
MEET
|
293
|
+
MENTION
|
294
|
+
MERE
|
295
|
+
MIGHT
|
296
|
+
MOMENT
|
297
|
+
MORE
|
298
|
+
MORNING
|
299
|
+
MOST
|
300
|
+
MOVE
|
301
|
+
MUCH
|
302
|
+
MUST
|
303
|
+
NEAR
|
304
|
+
NEARER
|
305
|
+
NEVER
|
306
|
+
NEXT
|
307
|
+
NICE
|
308
|
+
NOBODY
|
309
|
+
NONE
|
310
|
+
NOON
|
311
|
+
NOONE
|
312
|
+
NOT
|
313
|
+
NOTE
|
314
|
+
NOTHING
|
315
|
+
NOW
|
316
|
+
OBVIOUS
|
317
|
+
OF
|
318
|
+
OFF
|
319
|
+
ON
|
320
|
+
ONCE
|
321
|
+
ONLY
|
322
|
+
ONTO
|
323
|
+
OPINION
|
324
|
+
OR
|
325
|
+
OTHER
|
326
|
+
OUR
|
327
|
+
OUT
|
328
|
+
OVER
|
329
|
+
OWN
|
330
|
+
PART
|
331
|
+
PARTICULAR
|
332
|
+
PARTICULARLY
|
333
|
+
PERHAPS
|
334
|
+
PERSON
|
335
|
+
PIECE
|
336
|
+
PLACE
|
337
|
+
PLEASANT
|
338
|
+
PLEASE
|
339
|
+
POPULAR
|
340
|
+
PREFER
|
341
|
+
PRETTY
|
342
|
+
PUT
|
343
|
+
QUITE
|
344
|
+
REAL
|
345
|
+
REALLY
|
346
|
+
RECEIVE
|
347
|
+
RECEIVED
|
348
|
+
RECENT
|
349
|
+
RECENTLY
|
350
|
+
RELATED
|
351
|
+
RESULT
|
352
|
+
RESULTING
|
353
|
+
RESULTS
|
354
|
+
SAID
|
355
|
+
SAME
|
356
|
+
SAW
|
357
|
+
SAY
|
358
|
+
SAYING
|
359
|
+
SEE
|
360
|
+
SEEM
|
361
|
+
SEEMED
|
362
|
+
SEEMS
|
363
|
+
SEEN
|
364
|
+
SELDOM
|
365
|
+
SENSE
|
366
|
+
SET
|
367
|
+
SEVERAL
|
368
|
+
SHALL
|
369
|
+
SHORT
|
370
|
+
SHORTER
|
371
|
+
SHOULD
|
372
|
+
SHOW
|
373
|
+
SHOWS
|
374
|
+
SIMPLE
|
375
|
+
SIMPLY
|
376
|
+
SMALL
|
377
|
+
SO
|
378
|
+
SOME
|
379
|
+
SOMEONE
|
380
|
+
SOMETHING
|
381
|
+
SOMETIME
|
382
|
+
SOMETIMES
|
383
|
+
SOMEWHERE
|
384
|
+
SORT
|
385
|
+
SORTS
|
386
|
+
SPEND
|
387
|
+
SPENT
|
388
|
+
STILL
|
389
|
+
STUFF
|
390
|
+
SUCH
|
391
|
+
SUGGEST
|
392
|
+
SUGGESTION
|
393
|
+
SUPPOSE
|
394
|
+
SURE
|
395
|
+
SURELY
|
396
|
+
SURROUND
|
397
|
+
SURROUNDS
|
398
|
+
TAKE
|
399
|
+
TAKEN
|
400
|
+
TAKING
|
401
|
+
TELL
|
402
|
+
THAN
|
403
|
+
THANK
|
404
|
+
THANKS
|
405
|
+
THAT
|
406
|
+
THAT'S
|
407
|
+
THATS
|
408
|
+
THE
|
409
|
+
THEIR
|
410
|
+
THEM
|
411
|
+
THEN
|
412
|
+
THERE
|
413
|
+
THEREFORE
|
414
|
+
THESE
|
415
|
+
THEY
|
416
|
+
THING
|
417
|
+
THINGS
|
418
|
+
THIS
|
419
|
+
THOSE
|
420
|
+
THOUGH
|
421
|
+
THOUGHTS
|
422
|
+
THOUROUGHLY
|
423
|
+
THROUGH
|
424
|
+
TINY
|
425
|
+
TO
|
426
|
+
TODAY
|
427
|
+
TOGETHER
|
428
|
+
TOLD
|
429
|
+
TOMORROW
|
430
|
+
TOO
|
431
|
+
TOTAL
|
432
|
+
TOTALLY
|
433
|
+
TOUCH
|
434
|
+
TRY
|
435
|
+
TWICE
|
436
|
+
UNDER
|
437
|
+
UNDERSTAND
|
438
|
+
UNDERSTOOD
|
439
|
+
UNTIL
|
440
|
+
UP
|
441
|
+
US
|
442
|
+
USED
|
443
|
+
USING
|
444
|
+
USUALLY
|
445
|
+
VARIOUS
|
446
|
+
VERY
|
447
|
+
WANT
|
448
|
+
WANTED
|
449
|
+
WANTS
|
450
|
+
WAS
|
451
|
+
WATCH
|
452
|
+
WAY
|
453
|
+
WAYS
|
454
|
+
WE
|
455
|
+
WE'RE
|
456
|
+
WELL
|
457
|
+
WENT
|
458
|
+
WERE
|
459
|
+
WHAT
|
460
|
+
WHAT'S
|
461
|
+
WHATEVER
|
462
|
+
WHATS
|
463
|
+
WHEN
|
464
|
+
WHERE
|
465
|
+
WHERE'S
|
466
|
+
WHICH
|
467
|
+
WHILE
|
468
|
+
WHILST
|
469
|
+
WHO
|
470
|
+
WHO'S
|
471
|
+
WHOM
|
472
|
+
WILL
|
473
|
+
WISH
|
474
|
+
WITH
|
475
|
+
WITHIN
|
476
|
+
WONDER
|
477
|
+
WONDERFUL
|
478
|
+
WORSE
|
479
|
+
WORST
|
480
|
+
WOULD
|
481
|
+
WRONG
|
482
|
+
YESTERDAY
|
483
|
+
YET
|
484
|
+
EOS
|
485
|
+
end
|