markov_chain_chat_bot 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +1 -0
- data/lib/markov_chain.rb +4 -3
- data/lib/markov_chain_chat_bot.rb +72 -62
- metadata +2 -2
data/README
CHANGED
data/lib/markov_chain.rb
CHANGED
@@ -22,7 +22,7 @@ class MarkovChain
|
|
22
22
|
#
|
23
23
|
# appends +states+ to the end of this MarkovChain.
|
24
24
|
#
|
25
|
-
# +states+
|
25
|
+
# +states+ is an array of arbitrary objects.
|
26
26
|
#
|
27
27
|
# It returns this (modified) MarkovChain.
|
28
28
|
#
|
@@ -38,7 +38,8 @@ class MarkovChain
|
|
38
38
|
end
|
39
39
|
|
40
40
|
#
|
41
|
-
# returns Enumerable of predicted states. The
|
41
|
+
# returns Enumerable of predicted states. The states are predicted by
|
42
|
+
# states passed to #append!(). The result may contain nils if
|
42
43
|
# the MarkovChain can not predict a state.
|
43
44
|
#
|
44
45
|
def predict()
|
@@ -46,7 +47,7 @@ class MarkovChain
|
|
46
47
|
end
|
47
48
|
|
48
49
|
#
|
49
|
-
# +data+ passed to
|
50
|
+
# +data+ passed to MarkovChain.new() or MarkovChain.from().
|
50
51
|
#
|
51
52
|
def data
|
52
53
|
@data
|
@@ -28,7 +28,7 @@ class MarkovChainChatBot
|
|
28
28
|
@answer_limit = answer_limit
|
29
29
|
end
|
30
30
|
|
31
|
-
# +data+ passed to
|
31
|
+
# +data+ passed to MarkovChainChatBot.from().
|
32
32
|
def data
|
33
33
|
@markov_chain.data
|
34
34
|
end
|
@@ -243,7 +243,7 @@ class MarkovChainChatBot
|
|
243
243
|
# :nodoc:
|
244
244
|
def yy_begin?(context)
|
245
245
|
#
|
246
|
-
if not
|
246
|
+
if not(context.input.pos == 0)
|
247
247
|
context << YY_SyntaxExpectationError.new("the beginning", context.input.pos)
|
248
248
|
return nil
|
249
249
|
end
|
@@ -344,7 +344,11 @@ class MarkovChainChatBot
|
|
344
344
|
|
345
345
|
def message
|
346
346
|
expectations = self.expectations.uniq
|
347
|
-
|
347
|
+
(
|
348
|
+
if expectations.size == 1 then expectations.first
|
349
|
+
else [expectations[0...-1].join(", "), expectations[-1]].join(" or ")
|
350
|
+
end
|
351
|
+
) + " is expected"
|
348
352
|
end
|
349
353
|
|
350
354
|
protected
|
@@ -356,13 +360,13 @@ class MarkovChainChatBot
|
|
356
360
|
|
357
361
|
# :nodoc:
|
358
362
|
def yy_nonterm1(yy_context)
|
359
|
-
val =
|
363
|
+
val = nil
|
360
364
|
(begin
|
361
365
|
val = []
|
362
366
|
true
|
363
367
|
end and while true
|
364
368
|
yy_vare = yy_context.input.pos
|
365
|
-
if not
|
369
|
+
if not(begin; yy_var9 = yy_context.input.pos; (begin
|
366
370
|
yy_vara = yy_nontermf(yy_context)
|
367
371
|
if yy_vara then
|
368
372
|
w = yy_from_pcv(yy_vara)
|
@@ -380,13 +384,13 @@ class MarkovChainChatBot
|
|
380
384
|
end and begin
|
381
385
|
val << PunctuationMark.new(p)
|
382
386
|
true
|
383
|
-
end)) or (yy_context.input.pos = yy_var9;
|
387
|
+
end)) or (yy_context.input.pos = yy_var9; yy_nonterm24(yy_context) and while true
|
384
388
|
yy_vard = yy_context.input.pos
|
385
|
-
if not
|
389
|
+
if not(yy_nonterm24(yy_context)) then
|
386
390
|
yy_context.input.pos = yy_vard
|
387
391
|
break true
|
388
392
|
end
|
389
|
-
end); end then
|
393
|
+
end); end) then
|
390
394
|
yy_context.input.pos = yy_vare
|
391
395
|
break true
|
392
396
|
end
|
@@ -395,7 +399,7 @@ class MarkovChainChatBot
|
|
395
399
|
|
396
400
|
# :nodoc:
|
397
401
|
def yy_nontermf(yy_context)
|
398
|
-
val =
|
402
|
+
val = nil
|
399
403
|
(begin
|
400
404
|
val = ""
|
401
405
|
true
|
@@ -421,7 +425,7 @@ class MarkovChainChatBot
|
|
421
425
|
true
|
422
426
|
end)); end and while true
|
423
427
|
yy_varw = yy_context.input.pos
|
424
|
-
if not
|
428
|
+
if not(begin; yy_varp = yy_context.input.pos; begin
|
425
429
|
yy_varq = yy_nontermx(yy_context)
|
426
430
|
if yy_varq then
|
427
431
|
val << yy_from_pcv(yy_varq)
|
@@ -441,7 +445,7 @@ class MarkovChainChatBot
|
|
441
445
|
end and begin
|
442
446
|
val << h
|
443
447
|
true
|
444
|
-
end)); end then
|
448
|
+
end)); end) then
|
445
449
|
yy_context.input.pos = yy_varw
|
446
450
|
break true
|
447
451
|
end
|
@@ -450,7 +454,7 @@ class MarkovChainChatBot
|
|
450
454
|
|
451
455
|
# :nodoc:
|
452
456
|
def yy_nontermx(yy_context)
|
453
|
-
val =
|
457
|
+
val = nil
|
454
458
|
begin; yy_vary = yy_context.input.pos; begin
|
455
459
|
yy_varz = yy_char_range(yy_context, "a", "z")
|
456
460
|
if yy_varz then
|
@@ -486,83 +490,89 @@ class MarkovChainChatBot
|
|
486
490
|
|
487
491
|
# :nodoc:
|
488
492
|
def yy_nonterm14(yy_context)
|
489
|
-
val =
|
493
|
+
val = nil
|
490
494
|
(begin
|
491
495
|
val = ""
|
492
496
|
true
|
493
497
|
end and while true
|
494
498
|
yy_var1b = yy_context.input.pos
|
495
|
-
if not
|
496
|
-
yy_var1a =
|
499
|
+
if not(begin
|
500
|
+
yy_var1a = yy_nonterm24(yy_context)
|
497
501
|
if yy_var1a then
|
498
502
|
val << yy_from_pcv(yy_var1a)
|
499
503
|
end
|
500
504
|
yy_var1a
|
501
|
-
end then
|
505
|
+
end) then
|
502
506
|
yy_context.input.pos = yy_var1b
|
503
507
|
break true
|
504
508
|
end
|
505
509
|
end and (begin
|
506
|
-
|
507
|
-
begin
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
510
|
+
yy_var1s = yy_context.worst_error
|
511
|
+
yy_var1t = not(begin
|
512
|
+
yy_var1u = yy_context.input.pos
|
513
|
+
yy_var1v = yy_nontermx(yy_context)
|
514
|
+
yy_context.input.pos = yy_var1u
|
515
|
+
yy_var1v
|
516
|
+
end)
|
517
|
+
if yy_var1t
|
518
|
+
yy_context.worst_error = yy_var1s
|
519
|
+
else
|
520
|
+
# NOTE: No errors were added into context but the error is still there.
|
521
|
+
yy_context << YY_SyntaxExpectationError.new("different expression", yy_context.input.pos)
|
522
|
+
end
|
523
|
+
yy_var1t
|
517
524
|
end and begin
|
518
|
-
|
519
|
-
if
|
520
|
-
val << yy_from_pcv(
|
525
|
+
yy_var1w = yy_char(yy_context)
|
526
|
+
if yy_var1w then
|
527
|
+
val << yy_from_pcv(yy_var1w)
|
521
528
|
end
|
522
|
-
|
529
|
+
yy_var1w
|
523
530
|
end) and while true
|
524
|
-
|
525
|
-
if not
|
526
|
-
|
527
|
-
begin
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
531
|
+
yy_var1x = yy_context.input.pos
|
532
|
+
if not((begin
|
533
|
+
yy_var1s = yy_context.worst_error
|
534
|
+
yy_var1t = not(begin
|
535
|
+
yy_var1u = yy_context.input.pos
|
536
|
+
yy_var1v = yy_nontermx(yy_context)
|
537
|
+
yy_context.input.pos = yy_var1u
|
538
|
+
yy_var1v
|
539
|
+
end)
|
540
|
+
if yy_var1t
|
541
|
+
yy_context.worst_error = yy_var1s
|
542
|
+
else
|
543
|
+
# NOTE: No errors were added into context but the error is still there.
|
544
|
+
yy_context << YY_SyntaxExpectationError.new("different expression", yy_context.input.pos)
|
545
|
+
end
|
546
|
+
yy_var1t
|
537
547
|
end and begin
|
538
|
-
|
539
|
-
if
|
540
|
-
val << yy_from_pcv(
|
548
|
+
yy_var1w = yy_char(yy_context)
|
549
|
+
if yy_var1w then
|
550
|
+
val << yy_from_pcv(yy_var1w)
|
541
551
|
end
|
542
|
-
|
543
|
-
end) then
|
544
|
-
yy_context.input.pos =
|
552
|
+
yy_var1w
|
553
|
+
end)) then
|
554
|
+
yy_context.input.pos = yy_var1x
|
545
555
|
break true
|
546
556
|
end
|
547
557
|
end and while true
|
548
|
-
|
549
|
-
if not
|
550
|
-
|
551
|
-
if
|
552
|
-
val << yy_from_pcv(
|
553
|
-
end
|
554
|
-
|
555
|
-
end then
|
556
|
-
yy_context.input.pos =
|
558
|
+
yy_var23 = yy_context.input.pos
|
559
|
+
if not(begin
|
560
|
+
yy_var22 = yy_nonterm24(yy_context)
|
561
|
+
if yy_var22 then
|
562
|
+
val << yy_from_pcv(yy_var22)
|
563
|
+
end
|
564
|
+
yy_var22
|
565
|
+
end) then
|
566
|
+
yy_context.input.pos = yy_var23
|
557
567
|
break true
|
558
568
|
end
|
559
569
|
end) and yy_to_pcv(val)
|
560
570
|
end
|
561
571
|
|
562
572
|
# :nodoc:
|
563
|
-
def
|
564
|
-
val =
|
565
|
-
(begin;
|
573
|
+
def yy_nonterm24(yy_context)
|
574
|
+
val = nil
|
575
|
+
(begin; yy_var27 = yy_context.input.pos; yy_char_range(yy_context, "\t", "\r") or (yy_context.input.pos = yy_var27; yy_string(yy_context, " ")) or (yy_context.input.pos = yy_var27; yy_string(yy_context, "\u{85}")) or (yy_context.input.pos = yy_var27; yy_string(yy_context, "\u{a0}")) or (yy_context.input.pos = yy_var27; yy_string(yy_context, "\u{1680}")) or (yy_context.input.pos = yy_var27; yy_string(yy_context, "\u{180e}")) or (yy_context.input.pos = yy_var27; yy_char_range(yy_context, "\u{2000}", "\u{200a}")) or (yy_context.input.pos = yy_var27; yy_string(yy_context, "\u{2028}")) or (yy_context.input.pos = yy_var27; yy_string(yy_context, "\u{2029}")) or (yy_context.input.pos = yy_var27; yy_string(yy_context, "\u{202f}")) or (yy_context.input.pos = yy_var27; yy_string(yy_context, "\u{205f}")) or (yy_context.input.pos = yy_var27; yy_string(yy_context, "\u{3000}")); end and begin
|
566
576
|
val = " "
|
567
577
|
true
|
568
578
|
end) and yy_to_pcv(val)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: markov_chain_chat_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-03-17 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A chat bot utilizing Markov chains. It speaks Russian and English.
|
15
15
|
email: Lavir.th.Whiolet@gmail.com
|