forked from hailo/hailo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Storage.pm
113 lines (75 loc) · 2.08 KB
/
Storage.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package Hailo::Role::Storage;
use 5.10.0;
use MooseX::Role::Strict;
use MooseX::Types::Moose qw<Str Int>;
use List::Util qw<min>;
use namespace::clean -except => 'meta';
our $VERSION = '0.10';
has brain => (
isa => Str,
is => 'ro',
);
has order => (
isa => Int,
is => 'rw',
);
has repeat_limit => (
isa => Int,
is => 'rw',
lazy => 1,
default => sub {
my ($self) = @_;
my $order = $self->order;
return min(($order * 10), 50);
}
);
has token_separator => (
isa => Str,
is => 'rw',
);
requires 'save';
requires 'learn_tokens';
requires 'make_reply';
requires 'start_learning';
requires 'stop_learning';
requires 'start_training';
requires 'stop_training';
1;
=encoding utf8
=head1 NAME
Hailo::Role::Storage - A role representing a L<Hailo|Hailo> storage backend
=head1 ATTRIBUTES
=head2 C<order>
The Markov order (chain length) being used.
=head2 C<brain>
The name of the resource (file name, database name) to use as storage.
=head1 METHODS
=head2 C<new>
This is the constructor. It accept the attributes specified in
L</ATTRIBUTES>.
=head2 C<save>
Saves the current state.
=head2 C<learn_tokens>
Learns from a sequence of tokens. Takes an array ref of strings.
=head2 C<make_reply>
Takes an array reference of tokens and returns a reply (arrayref of tokens)
that might be relevant.
=head2 C<start_learning>
Takes no arguments. This method is called by C<Hailo|Hailo> right before learning
begins.
=head2 C<stop_learning>
Takes no arguments. This method is called by C<Hailo|Hailo> right after learning
finishes.
=head2 C<start_training>
Takes no arguments. This method is called by C<Hailo|Hailo> right before training
begins.
=head2 C<stop_training>
Takes no arguments. This method is called by C<Hailo|Hailo> right after training
finishes.
=head1 AUTHOR
Hinrik E<Ouml>rn SigurE<eth>sson, hinrik.sig@gmail.com
=head1 LICENSE AND COPYRIGHT
Copyright 2010 Hinrik E<Ouml>rn SigurE<eth>sson
This program is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut