line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AI::CBR::Case::Compound; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1627
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
53
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
583
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $DEFAULT_WEIGHT = 1; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
AI::CBR::Case::Compound - compound case definition and representation |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Define and initialise a compound (or object-oriented) case. |
17
|
|
|
|
|
|
|
This is a case consisting of multiple object definitions related in some way. |
18
|
|
|
|
|
|
|
In a productive system, you will want to encapsulate this. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use AI::CBR::Case::Compound; |
21
|
|
|
|
|
|
|
use AI::CBR::Sim qw(sim_eq sim_dist); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# assume we sell travels with flight and hotel |
24
|
|
|
|
|
|
|
# shortcut one-time generated case |
25
|
|
|
|
|
|
|
my $case = AI::CBR::Case::Compound->new( |
26
|
|
|
|
|
|
|
# flight object |
27
|
|
|
|
|
|
|
{ |
28
|
|
|
|
|
|
|
flight_start => { value => 'FRA', sim => \&sim_eq }, |
29
|
|
|
|
|
|
|
flight_target => { value => 'LIS', sim => \&sim_eq }, |
30
|
|
|
|
|
|
|
price => { value => 300, sim => \&sim_dist, param => 200 }, |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
# hotel object |
33
|
|
|
|
|
|
|
{ |
34
|
|
|
|
|
|
|
stars => { value => 3, sim => \&sim_dist, param => 2 }, |
35
|
|
|
|
|
|
|
rate => { value => 60, sim => \&sim_dist, param => 200 }, |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
... |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 METHODS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 new |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Creates a new compound case specification. |
46
|
|
|
|
|
|
|
Pass a list of hash references as argument. |
47
|
|
|
|
|
|
|
Each hash reference is the same specification as passed to L. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub new { |
52
|
1
|
|
|
1
|
1
|
30
|
my ($class, @definitions) = @_; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# set default weights if unspecified |
55
|
1
|
|
|
|
|
3
|
foreach my $attributes (@definitions) { |
56
|
2
|
|
|
|
|
8
|
foreach (keys %$attributes) { |
57
|
5
|
50
|
|
|
|
78
|
$attributes->{$_}->{weight} = $DEFAULT_WEIGHT unless defined $attributes->{$_}->{weight}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
4
|
my $self = \@definitions; |
62
|
1
|
|
|
|
|
5
|
bless $self, $class; |
63
|
1
|
|
|
|
|
5
|
return $self; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 set_values |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Pass a flat hash of attribute keys and values. |
70
|
|
|
|
|
|
|
This will overwrite existing values, and can thus be used as a faster method |
71
|
|
|
|
|
|
|
for generating new cases with the same specification. |
72
|
|
|
|
|
|
|
Notice that keys in the different specifications of the compound object may not have the same name! |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub set_values { |
77
|
0
|
|
|
0
|
1
|
|
my ($self, %values) = @_; |
78
|
0
|
|
|
|
|
|
foreach my $spec (@$self) { |
79
|
0
|
|
|
|
|
|
foreach (keys %$spec) { |
80
|
0
|
|
|
|
|
|
$spec->{$_}->{value} = $values{$_}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SEE ALSO |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
See L for an overview of the framework. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 AUTHOR |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Darko Obradovic, C<< >> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 BUGS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
98
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
99
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 SUPPORT |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
perldoc AI::CBR::Case::Compound |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
You can also look for information at: |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=over 4 |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
L |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
L |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item * CPAN Ratings |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
L |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item * Search CPAN |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
L |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=back |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Copyright 2009 Darko Obradovic, all rights reserved. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
140
|
|
|
|
|
|
|
under the same terms as Perl itself. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; # End of AI::CBR::Case::Compound |