line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Eliza::Chatbot; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
136848
|
use strict; |
|
9
|
|
|
|
|
67
|
|
|
9
|
|
|
|
|
266
|
|
4
|
9
|
|
|
9
|
|
50
|
use warnings; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
235
|
|
5
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
5042
|
use Moo; |
|
9
|
|
|
|
|
112990
|
|
|
9
|
|
|
|
|
43
|
|
7
|
9
|
|
|
9
|
|
17688
|
use MooX::LazierAttributes; |
|
9
|
|
|
|
|
178348
|
|
|
9
|
|
|
|
|
52
|
|
8
|
9
|
|
|
9
|
|
5649
|
use Eliza::Chatbot::Option; |
|
9
|
|
|
|
|
31
|
|
|
9
|
|
|
|
|
324
|
|
9
|
9
|
|
|
9
|
|
5169
|
use Eliza::Chatbot::Brain; |
|
9
|
|
|
|
|
29
|
|
|
9
|
|
|
|
|
4929
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.09'; |
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
|
|
35
|
my $self = shift; |
22
|
4
|
|
|
|
|
49
|
my $options = Eliza::Chatbot::Option->new(); |
23
|
4
|
|
|
|
|
4336
|
foreach my $field (@user_options) { |
24
|
20
|
100
|
|
|
|
97
|
if (my $val = $self->$field) { |
25
|
3
|
|
|
|
|
53
|
$options->$field($val); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
4
|
|
|
|
|
52
|
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
|
9474
|
my ($self, $user_input) = @_; |
94
|
8
|
|
|
|
|
177
|
return $self->brain->transform($user_input, ''); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |