| 1 | package AI::CBR::Case; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 4 | our $DEFAULT_WEIGHT = 1; | |||||||||
| 7 | |||||||||||
| 8 | |||||||||||
| 9 | =head1 NAME | ||||||||||
| 10 | |||||||||||
| 11 | AI::CBR::Case - case definition and representation | ||||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||
| 15 | |||||||||||
| 16 | Define and initialise a case. | ||||||||||
| 17 | In a productive system, you will want to encapsulate this. | ||||||||||
| 18 | |||||||||||
| 19 | use AI::CBR::Case; | ||||||||||
| 20 | use AI::CBR::Sim qw(sim_frac sim_eq sim_set); | ||||||||||
| 21 | |||||||||||
| 22 | # assume we are a doctor and see a patient | ||||||||||
| 23 | # shortcut one-time generated case | ||||||||||
| 24 | my $case = AI::CBR::Case->new( | ||||||||||
| 25 | age => { value => 30, sim => \&sim_frac }, | ||||||||||
| 26 | gender => { value => 'male', sim => \&sim_eq }, | ||||||||||
| 27 | job => { value => 'programmer', sim => \&sim_eq }, | ||||||||||
| 28 | symptoms => { value => [qw(headache)], sim => \&sim_set }, | ||||||||||
| 29 | ); | ||||||||||
| 30 | |||||||||||
| 31 | # or case-specification with changing data | ||||||||||
| 32 | my $patient_case = AI::CBR::Case->new( | ||||||||||
| 33 | age => { sim => \&sim_frac }, | ||||||||||
| 34 | gender => { sim => \&sim_eq }, | ||||||||||
| 35 | job => { sim => \&sim_eq }, | ||||||||||
| 36 | symptoms => { sim => \&sim_set }, | ||||||||||
| 37 | ); | ||||||||||
| 38 | |||||||||||
| 39 | foreach my $patient (@waiting_queue) { | ||||||||||
| 40 | $patient_case->set_values( %$patient ); # assume $patient is a hashref with the right attributes | ||||||||||
| 41 | ... | ||||||||||
| 42 | } | ||||||||||
| 43 | ... | ||||||||||
| 44 | |||||||||||
| 45 | =head1 METHODS | ||||||||||
| 46 | |||||||||||
| 47 | =head2 new | ||||||||||
| 48 | |||||||||||
| 49 | Creates a new case specification. | ||||||||||
| 50 | Pass a hash of hash references as argument. | ||||||||||
| 51 | The hash keys identify the attributes of the case, | ||||||||||
| 52 | the hash reference specifies this attribute, | ||||||||||
| 53 | with the following values: | ||||||||||
| 54 | |||||||||||
| 55 | =over 4 | ||||||||||
| 56 | |||||||||||
| 57 | =item * B<sim>: a reference to the similarity function to use for this attribute | ||||||||||
| 58 | |||||||||||
| 59 | =item * B<param>: the parameter for the similarity function, if required | ||||||||||
| 60 | |||||||||||
| 61 | =item * B<weight>: the weight of the attribute in the comparison of the case. If you do not give a weight value for an attribute, the package's C<$DEFAULT_WEIGHT> will be used, which is 1 by default. | ||||||||||
| 62 | |||||||||||
| 63 | =item * B<value>: the value of the attribute, if you want to specify the complete case immediately. You can also do this later. | ||||||||||
| 64 | |||||||||||
| 65 | =back | ||||||||||
| 66 | |||||||||||
| 67 | =cut | ||||||||||
| 68 | |||||||||||
| 69 | 2 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 70 | 2 | my ($class, %attributes) = @_; | |||||||||
| 71 | |||||||||||
| 72 | # set default weights if unspecified | ||||||||||
| 73 | 2 | foreach (keys %attributes) { | |||||||||
| 74 | 8 | ▶ | $attributes{$_}->{weight} = $DEFAULT_WEIGHT unless defined $attributes{$_}->{weight}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 2 | my $self = \%attributes; | |||||||||
| 78 | 2 | bless $self, $class; | |||||||||
| 79 | 2 | return $self; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | |||||||||||
| 83 | =head2 set_values | ||||||||||
| 84 | |||||||||||
| 85 | Pass a hash of attribute keys and values. | ||||||||||
| 86 | This will overwrite existing values, and can thus be used as a faster method | ||||||||||
| 87 | for generating new cases with the same specification. | ||||||||||
| 88 | |||||||||||
| 89 | =cut | ||||||||||
| 90 | |||||||||||
| 91 | 0 | ▶ | sub set_values { | ||||||||
|
Subroutine
set_values: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 92 | 0 | my ($self, %values) = @_; | |||||||||
| 93 | 0 | foreach (keys %values) { | |||||||||
| 94 | 0 | $self->{$_}->{value} = $values{$_}; | |||||||||
| 95 | } | ||||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | |||||||||||
| 99 | =head1 SEE ALSO | ||||||||||
| 100 | |||||||||||
| 101 | See L<AI::CBR> for an overview of the framework. | ||||||||||
| 102 | |||||||||||
| 103 | |||||||||||
| 104 | =head1 AUTHOR | ||||||||||
| 105 | |||||||||||
| 106 | Darko Obradovic, C<< <dobradovic at gmx.de> >> | ||||||||||
| 107 | |||||||||||
| 108 | =head1 BUGS | ||||||||||
| 109 | |||||||||||
| 110 | Please report any bugs or feature requests to C<bug-ai-cbr at rt.cpan.org>, or through | ||||||||||
| 111 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=AI-CBR>. I will be notified, and then you'll | ||||||||||
| 112 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 113 | |||||||||||
| 114 | |||||||||||
| 115 | |||||||||||
| 116 | |||||||||||
| 117 | =head1 SUPPORT | ||||||||||
| 118 | |||||||||||
| 119 | You can find documentation for this module with the perldoc command. | ||||||||||
| 120 | |||||||||||
| 121 | perldoc AI::CBR::Case | ||||||||||
| 122 | |||||||||||
| 123 | |||||||||||
| 124 | You can also look for information at: | ||||||||||
| 125 | |||||||||||
| 126 | =over 4 | ||||||||||
| 127 | |||||||||||
| 128 | =item * RT: CPAN's request tracker | ||||||||||
| 129 | |||||||||||
| 130 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=AI-CBR> | ||||||||||
| 131 | |||||||||||
| 132 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 133 | |||||||||||
| 134 | L<http://annocpan.org/dist/AI-CBR> | ||||||||||
| 135 | |||||||||||
| 136 | =item * CPAN Ratings | ||||||||||
| 137 | |||||||||||
| 138 | L<http://cpanratings.perl.org/d/AI-CBR> | ||||||||||
| 139 | |||||||||||
| 140 | =item * Search CPAN | ||||||||||
| 141 | |||||||||||
| 142 | L<http://search.cpan.org/dist/AI-CBR> | ||||||||||
| 143 | |||||||||||
| 144 | =back | ||||||||||
| 145 | |||||||||||
| 146 | |||||||||||
| 147 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 148 | |||||||||||
| 149 | Copyright 2009 Darko Obradovic, all rights reserved. | ||||||||||
| 150 | |||||||||||
| 151 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 152 | under the same terms as Perl itself. | ||||||||||
| 153 | |||||||||||
| 154 | |||||||||||
| 155 | =cut | ||||||||||
| 156 | |||||||||||
| 157 | 4 | 1; # End of AI::CBR::Case | |||||||||