| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Eliza::Chatbot; |
|
2
|
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
139138
|
use strict; |
|
|
9
|
|
|
|
|
68
|
|
|
|
9
|
|
|
|
|
262
|
|
|
4
|
9
|
|
|
9
|
|
48
|
use warnings; |
|
|
9
|
|
|
|
|
32
|
|
|
|
9
|
|
|
|
|
249
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
5217
|
use Moo; |
|
|
9
|
|
|
|
|
114548
|
|
|
|
9
|
|
|
|
|
39
|
|
|
7
|
9
|
|
|
9
|
|
17738
|
use MooX::LazierAttributes; |
|
|
9
|
|
|
|
|
177974
|
|
|
|
9
|
|
|
|
|
38
|
|
|
8
|
9
|
|
|
9
|
|
5644
|
use Eliza::Chatbot::Option; |
|
|
9
|
|
|
|
|
35
|
|
|
|
9
|
|
|
|
|
337
|
|
|
9
|
9
|
|
|
9
|
|
5291
|
use Eliza::Chatbot::Brain; |
|
|
9
|
|
|
|
|
33
|
|
|
|
9
|
|
|
|
|
5027
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @user_options = qw(name script_file debug prompts_on memory_on); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
attributes ( |
|
16
|
|
|
|
|
|
|
[@user_options] => [rw], |
|
17
|
|
|
|
|
|
|
brain => [rw, nan, { lzy, bld }], |
|
18
|
|
|
|
|
|
|
); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _build_brain { |
|
21
|
4
|
|
|
4
|
|
37
|
my $self = shift; |
|
22
|
4
|
|
|
|
|
51
|
my $options = Eliza::Chatbot::Option->new(); |
|
23
|
4
|
|
|
|
|
4399
|
foreach my $field (@user_options) { |
|
24
|
20
|
100
|
|
|
|
93
|
if (my $val = $self->$field) { |
|
25
|
3
|
|
|
|
|
53
|
$options->$field($val); |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
} |
|
28
|
4
|
|
|
|
|
56
|
return Eliza::Chatbot::Brain->new(options => $options); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub command_interface { |
|
32
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
33
|
0
|
|
|
|
|
0
|
my ($reply, $previous_user_input, $user_input) = ""; |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
my $options = $self->brain->options; |
|
36
|
0
|
|
|
|
|
0
|
$options->botprompt($options->name . ":\t"); |
|
37
|
0
|
|
|
|
|
0
|
$options->userprompt("you:\t"); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Seed the rand number generator. |
|
40
|
0
|
|
|
|
|
0
|
srand( time() ^ ($$ + ($$ << 15)) ); |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# print the Eliza prompt |
|
43
|
0
|
0
|
|
|
|
0
|
print $options->botprompt if $options->prompts_on; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# print an initial greeting |
|
46
|
0
|
|
|
|
|
0
|
print $options->welcome_message . "\n"; |
|
47
|
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
while (1) { |
|
49
|
0
|
0
|
|
|
|
0
|
print $options->userprompt if $options->prompts_on; |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
$previous_user_input = $user_input; |
|
52
|
0
|
|
|
|
|
0
|
chomp( $user_input = ); |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# If the user enters the work "debug", |
|
55
|
|
|
|
|
|
|
# the toggle on/off Eliza's debug output. |
|
56
|
0
|
0
|
|
|
|
0
|
if ($user_input eq "debug") { |
|
57
|
0
|
|
|
|
|
0
|
$options->debug( ! $options->debug ); |
|
58
|
0
|
|
|
|
|
0
|
$user_input = $previous_user_input; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# If the user enters the word "memory" |
|
62
|
|
|
|
|
|
|
# then use the _debug_memory method to dump out |
|
63
|
|
|
|
|
|
|
# the current contents of Eliza's memory |
|
64
|
0
|
0
|
|
|
|
0
|
if ($user_input =~ m{memory|debug memory}xms) { |
|
65
|
0
|
|
|
|
|
0
|
print $self->brain->_debug_memory(); |
|
66
|
0
|
|
|
|
|
0
|
redo; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# If the user enters the word "debug that" |
|
70
|
|
|
|
|
|
|
# the dump out the debugging of the most recent |
|
71
|
|
|
|
|
|
|
# call to transform |
|
72
|
0
|
0
|
|
|
|
0
|
if ($user_input eq "debug that") { |
|
73
|
0
|
|
|
|
|
0
|
print $options->debug_text; |
|
74
|
0
|
|
|
|
|
0
|
redo; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Invoke the transform method to generate a reply |
|
78
|
0
|
|
|
|
|
0
|
$reply = $self->brain->transform($user_input, ''); |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Print out the debugging text if debugging is set to on. |
|
81
|
|
|
|
|
|
|
# This variable should have been set by the transform method |
|
82
|
0
|
0
|
|
|
|
0
|
print $options->debug_text if $self->debug; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# print the actual reply |
|
85
|
0
|
0
|
|
|
|
0
|
print $options->botprompt if $options->prompts_on; |
|
86
|
0
|
|
|
|
|
0
|
print sprintf("%s\n", $reply); |
|
87
|
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
0
|
last if $self->brain->last; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub instance { |
|
93
|
8
|
|
|
8
|
1
|
9873
|
my ($self, $user_input) = @_; |
|
94
|
8
|
|
|
|
|
173
|
return $self->brain->transform($user_input, ''); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |