CBR/Case/Compound.pm

filter: Statementstmt 78.9% 15 / 19 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod 100% 2 / 2 totaltotal 77.7% 21 / 27 CC 6 SCAR 17.9
CC
6
Cov
76%
set_values
12.0
new
4.0
BEGIN
1.0
CRAP 6.0
↑ Summary CBR/Retrieval.pm »
1 package AI::CBR::Case::Compound;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 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<AI::CBR::Case>.
48  
49 =cut
50  
51 1 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
52 1 my ($class, @definitions) = @_;
53
54 # set default weights if unspecified
55 1 foreach my $attributes (@definitions) {
56 2 foreach (keys %$attributes) {
57 5 ▶ $attributes->{$_}->{weight} = $DEFAULT_WEIGHT unless defined $attributes->{$_}->{weight};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attributes->{$_}{"weight"} 5 0 5
58 }
59 }
60
61 1 my $self = \@definitions;
62 1 bless $self, $class;
63 1 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 0 ▶sub set_values {
Subroutine set_values: not called CC=3 SCAR=24.8
Pod documented
77 0 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<AI::CBR> for an overview of the framework.
89  
90  
91 =head1 AUTHOR
92  
93 Darko Obradovic, C<< <dobradovic at gmx.de> >>
94  
95 =head1 BUGS
96  
97 Please report any bugs or feature requests to C<bug-ai-cbr at rt.cpan.org>, or through
98 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=AI-CBR>. 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<http://rt.cpan.org/NoAuth/Bugs.html?Dist=AI-CBR>
118  
119 =item * AnnoCPAN: Annotated CPAN documentation
120  
121 L<http://annocpan.org/dist/AI-CBR>
122  
123 =item * CPAN Ratings
124  
125 L<http://cpanratings.perl.org/d/AI-CBR>
126  
127 =item * Search CPAN
128  
129 L<http://search.cpan.org/dist/AI-CBR>
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 3 1; # End of AI::CBR::Case::Compound
↑ Summary CBR/Retrieval.pm »