line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AI::ExpertSystem::Simple::Goal; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
817
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
402
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.0'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
6
|
|
|
6
|
1
|
4632
|
my ($class, $name, $message) = @_; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Check the input |
12
|
|
|
|
|
|
|
|
13
|
6
|
100
|
|
|
|
65
|
die "Goal->new() takes 2 arguments" if scalar(@_) != 3; |
14
|
3
|
100
|
|
|
|
21
|
die "Goal->new() argument 1 (NAME) is undefined" if ! defined($name); |
15
|
2
|
100
|
|
|
|
18
|
die "Goal->new() argument 2 (MESSAGE) is undefined" if ! defined($message); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# All OK, create the object |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
3
|
my $self = {}; |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
6
|
$self->{_name} = $name; |
22
|
1
|
|
|
|
|
5
|
$self->{_message} = $message; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
9
|
return bless $self, $class; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub is_goal { |
28
|
5
|
|
|
5
|
1
|
1647
|
my ($self, $name) = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Check the input |
31
|
|
|
|
|
|
|
|
32
|
5
|
100
|
|
|
|
39
|
die "Goal->is_goal() takes 1 argument" if scalar(@_) != 2; |
33
|
3
|
100
|
|
|
|
21
|
die "Goal->is_goal() argument 1 (NAME) is undefined" if ! defined($name); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# All OK, do the stuff |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
17
|
return $self->{_name} eq $name; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub name { |
41
|
2
|
|
|
2
|
1
|
1156
|
my ($self) = @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Check the input |
44
|
|
|
|
|
|
|
|
45
|
2
|
100
|
|
|
|
20
|
die "Goal->name() takes no arguments" if scalar(@_) != 1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# All OK, do the stuff |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
12
|
return $self->{_name}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub answer { |
53
|
4
|
|
|
4
|
1
|
1585
|
my ($self, $value) = @_; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Check the input |
56
|
|
|
|
|
|
|
|
57
|
4
|
100
|
|
|
|
38
|
die "Goal->answer() takes 1 argument" if scalar(@_) != 2; |
58
|
2
|
100
|
|
|
|
23
|
die "Goal->answer() argument 1 (VALUE) is undefined" if ! defined($value); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# All OK, do the stuff |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
4
|
my @text = (); |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
13
|
foreach my $word (split('\s', $self->{_message})) { |
65
|
4
|
100
|
|
|
|
22
|
if($word eq $self->{_name}) { |
66
|
1
|
|
|
|
|
6
|
push(@text, $value); |
67
|
|
|
|
|
|
|
} else { |
68
|
3
|
|
|
|
|
11
|
push(@text, $word); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
10
|
return join(' ', @text); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 NAME |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
AI::ExpertSystem::Simple::Goal - Utility class for a simple expert system |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 VERSION |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This document refers to verion 1.00 of AI::ExpertSystem::Simple::Goal, released April 25, 2003 |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 SYNOPSIS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This class handles the goal in the expert system and returns the answer when the goal is matched. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 DESCRIPTION |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 Overview |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This is a utility class for AI::ExpertSystem::Simple |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 Constructors and initialisation |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=over 4 |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item new( NAME, MESSAGE ) |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
The constructor takes two arguments. The first, NAME, is the name of the attribute that when set will |
102
|
|
|
|
|
|
|
trigger the end of the consoltation. The second argument, MESSAGE, is the text that will be interpolated |
103
|
|
|
|
|
|
|
as the answer for the consoltation. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=back |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 Public methods |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=over 4 |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item is_goal( NAME ) |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This method compares the given NAME with that of the attribute name given when the object was constructed and |
114
|
|
|
|
|
|
|
returns true if they are the same or false if not. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item name( ) |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This method return the value of the NAME argument that was set when the object was constructed. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item answer( VALUE ) |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This method take VALUE to be the value of the goal attribute and will use it to interpolate and return the MESSAGE that was given |
123
|
|
|
|
|
|
|
when the object was constructed. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=back |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 Private methods |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
None |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 ENVIRONMENT |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
None |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=over 4 |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item Goal->new() takes 2 arguments |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
When the constructor is initialised it requires two arguments. This message is given if more or less arguments were supplied. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item Goal->new() argument 1 (NAME) is undefined |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
The correct number of arguments were supplied to the constructor, however the first argument, NAME, was undefined. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item Goal->new() argument 2 (MESSAGE) is undefined |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
The correct number of arguments were supplied to the constructor, however the second argument, MESSAGE, was undefined. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item Goal->is_goal() takes 1 argument |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
When the method is called it requires one argument. This message is given if more or less arguments were supplied. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item Goal->is_goal() argument 1 (NAME) is undefined |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
The correct number of arguments were supplied with the method call, however the first argument, NAME, was undefined. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item Goal->name() takes no arguments |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
When the method is called it takes no arguments. This message is given if some were supplied. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item Goal->answer() takes 1 argument |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
When the method is called it requires one argument. This message is given if more or less arguments were supplied. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item Goal->answer() argument 1 (VALUE) is undefined |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
The correct number of arguments were supplied with the method call, however the first argument, VALUE, was undefined. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=back |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 BUGS |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
None to date |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 FILES |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
See Goal.t in the test directory |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 SEE ALSO |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
AI::ExpertSystem::Simple - The base class for the expert system shell |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
AI::ExpertSystem::Simple::Knowledge - A utility class |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
AI::ExpertSystem::Simple::Rules - A utility class |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 AUTHORS |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Peter Hickman (peterhi@ntlworld.com) |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 COPYRIGHT |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Copyright (c) 2003, Peter Hickman. All rights reserved. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
This module is free software. It may be used, redistributed and/or |
198
|
|
|
|
|
|
|
modified under the same terms as Perl itself. |