line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
|
|
|
|
|
|
package hailo; |
3
|
8
|
|
|
|
|
30
|
our $AUTHORITY = 'cpan:AVAR'; |
4
|
8
|
|
|
|
|
19
|
$hailo::VERSION = '0.75'; |
5
|
8
|
|
|
8
|
|
97
|
use v5.10.0; |
|
8
|
|
|
|
|
59
|
|
6
|
8
|
|
|
8
|
|
2981
|
use open qw< :encoding(utf8) :std >; |
|
8
|
|
|
|
|
7886
|
|
|
8
|
|
|
|
|
32
|
|
7
|
8
|
|
|
8
|
|
102207
|
use Dir::Self; |
|
8
|
|
|
|
|
2919
|
|
|
8
|
|
|
|
|
37
|
|
8
|
8
|
|
|
8
|
|
3836
|
use Moose; |
|
8
|
|
|
|
|
3158353
|
|
|
8
|
|
|
|
|
47
|
|
9
|
8
|
|
|
8
|
|
49670
|
use Encode qw(decode); |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
766
|
|
10
|
8
|
|
|
8
|
|
4194
|
use Hailo::Command; |
|
8
|
|
|
|
|
3661
|
|
|
8
|
|
|
|
|
399
|
|
11
|
8
|
|
|
8
|
|
60
|
use namespace::clean -except => 'meta'; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
50
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Nothing to see here |
14
|
8
|
|
|
|
|
61
|
__PACKAGE__->meta->make_immutable; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# use utf8 everywhere |
17
|
8
|
|
|
|
|
2884
|
$_ = decode('utf8', $_) for @ARGV; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Set programname |
20
|
8
|
|
|
|
|
636
|
$0 = 'hailo'; |
21
|
|
|
|
|
|
|
|
22
|
8
|
50
|
33
|
|
|
53
|
if ($] < 5.013000 and $^O eq 'linux') { |
23
|
0
|
|
|
|
|
0
|
local $@; |
24
|
0
|
|
|
|
|
0
|
eval { |
25
|
0
|
|
|
|
|
0
|
require Sys::Prctl; |
26
|
0
|
|
|
|
|
0
|
Sys::Prctl::prctl_name('hailo'); |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# I want my mommy! |
31
|
8
|
|
|
|
|
39
|
$Hailo::Command::HERE_MOMMY = __DIR__; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Show help if run without arguments |
34
|
8
|
100
|
|
|
|
402
|
@ARGV = qw(--help) unless @ARGV; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Hailing frequencies open |
37
|
8
|
|
|
|
|
67
|
Hailo::Command->new_with_options->run; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=encoding utf8 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 NAME |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
hailo - Command-line interface to the L<Hailo|Hailo> Markov bot |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 USAGE |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
usage: hailo [-abEfhLlopRrSsTtuv] [long options...] |
48
|
|
|
|
|
|
|
usage: hailo [-abEfhLlopRrSsTtuv] [long options...] |
49
|
|
|
|
|
|
|
-v --version Print version and exit |
50
|
|
|
|
|
|
|
-u --ui Use UI CLASS |
51
|
|
|
|
|
|
|
-t --train Learn from all the lines in FILE, use - for STDIN |
52
|
|
|
|
|
|
|
-s --stats Print statistics about the brain |
53
|
|
|
|
|
|
|
-r --reply Reply to STRING |
54
|
|
|
|
|
|
|
-p --progress Display progress during the import |
55
|
|
|
|
|
|
|
-o --order Markov order; How deep the rabbit hole goes |
56
|
|
|
|
|
|
|
-l --learn Learn from STRING |
57
|
|
|
|
|
|
|
-h --help You're soaking it in |
58
|
|
|
|
|
|
|
-f --train-fast Train with aggressive caching (memory-hungry!) |
59
|
|
|
|
|
|
|
-b --brain Load/save brain to/from FILE |
60
|
|
|
|
|
|
|
-a --autosave Save the brain on exit (on by default) |
61
|
|
|
|
|
|
|
-T --tokenizer Use tokenizer CLASS |
62
|
|
|
|
|
|
|
-S --storage Use storage CLASS |
63
|
|
|
|
|
|
|
-R --random-reply Like --reply but takes no STRING; Babble at random |
64
|
|
|
|
|
|
|
-L --learn-reply Learn from STRING and reply to it |
65
|
|
|
|
|
|
|
-E --engine Use engine CLASS |
66
|
|
|
|
|
|
|
--ui-args Arguments for the UI class |
67
|
|
|
|
|
|
|
--tokenizer-args Arguments for the Tokenizer class |
68
|
|
|
|
|
|
|
--storage-args Arguments for the Storage class |
69
|
|
|
|
|
|
|
--examples Print examples along with the help message |
70
|
|
|
|
|
|
|
--engine-args Arguments for the Engine class |
71
|
|
|
|
|
|
|
--brain-resource Alias for `brain' for backwards compatibility |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Note: All input/output and files are assumed to be UTF-8 encoded. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 SYNOPSIS |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Train in-memory using L<bot-training|Bot::Training>'s F<megahal.trn> |
78
|
|
|
|
|
|
|
and reply: |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
bot-training -f megahal | hailo --brain :memory: --train - --random-reply |
81
|
|
|
|
|
|
|
# ==> Time flies like a banana. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Create an on-disk brain for later use: |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
bot-training -f megahal > megahal.trn |
86
|
|
|
|
|
|
|
hailo --brain hailo.sqlite --train megahal.trn |
87
|
|
|
|
|
|
|
hailo --brain hailo.sqlite --reply 'Reply to this, silly robot!' |
88
|
|
|
|
|
|
|
# ==> No way! I don't want to think. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Interact with the brain using readline: |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
hailo --brain hailo.sqlite |
93
|
|
|
|
|
|
|
Welcome to the Hailo interactive shell! |
94
|
|
|
|
|
|
|
Enter ".help" to show the built-in commands. |
95
|
|
|
|
|
|
|
Input that's not a command will be passed to Hailo to learn, and it'll |
96
|
|
|
|
|
|
|
reply back. |
97
|
|
|
|
|
|
|
Hailo> Hello there |
98
|
|
|
|
|
|
|
# ==> Wife asked "what have you got there?" replied he, "just my cup of fur". |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 DESCRIPTION |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
See the documentation for L<Hailo|Hailo> for more information. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 AUTHOR |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@cpan.org> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Copyright 2010 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@cpan.org> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify |
113
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |