File Coverage

blib/lib/Chorus/Expert.pm
Criterion Covered Total %
statement 13 25 52.0
branch 0 2 0.0
condition n/a
subroutine 5 8 62.5
pod 2 3 66.6
total 20 38 52.6


line stmt bran cond sub pod time code
1             package Chorus::Expert;
2              
3 1     1   42283 use 5.006;
  1         4  
  1         38  
4 1     1   6 use strict;
  1         2  
  1         43  
5 1     1   6 use warnings;
  1         7  
  1         58  
6              
7             our $VERSION = '1.02';
8              
9             =head1 NAME
10              
11             Chorus::Expert - A simple skeleton of application using one or more Chorus::Engine objects (inference engines)
12             working together on a common task.
13              
14             =head1 VERSION
15              
16             Version 1.02
17              
18             =cut
19              
20             =head1 SYNOPSIS
21              
22             Chorus::Expert does 3 simple things :
23              
24             1 - Registers one or more Chorus::Engine objects
25             2 - Provides to each of them a shared working area ($SELF->BOARD)
26             3 - Enter an infinite loop on each inference engine until one of them declares the system as SOLVED.
27              
28             package A;
29            
30             use Chorus::Engine;
31             our $agent = Chorus::Engine->new();
32             $agent->addrule(...);
33              
34             # --
35            
36             package B;
37             use Chorus::Engine;
38             our $agent = Chorus::Engine->new();
39             $agent->addrule(...);
40            
41             # --
42            
43             use Chorus::Expert;
44             use A;
45             use B;
46            
47             my $xprt = Chorus::Expert->new();
48             $xprt->register($A::agent);
49             $xprt->register($B::agent);
50            
51             $xprt->process();
52              
53             =cut
54              
55 1     1   1015 use Chorus::Frame;
  1         4  
  1         405  
56              
57             my @agents = ();
58             my $board = Chorus::Frame->new();
59              
60             sub new {
61 0     0 0   my $class = shift;
62 0           return bless {}, $class;
63             }
64              
65             =head1 SUBROUTINES/METHODS
66              
67             =head2 register
68              
69             use Chorus::Expert;
70             use Chorus::Engine;
71            
72             my $xprt = Chorus::Expert->new();
73              
74             my $e1 = Chorus::Engine->new(); # inference engine 1
75             my $e2 = Chorus::Engine->new(); # inference engine 2
76              
77             $xprt->register($e1,$e2); # $e1 and $2 added to the list of agents
78             # providing to all of them a shared attribute named BOARD
79            
80             =cut
81              
82             sub register {
83 0     0 1   my $this = shift;
84 0           $_->set('BOARD', $board) for @_;
85 0           push @agents, @_;
86 0           return $this;
87             }
88              
89             =head2 process
90              
91             Tells the Chorus::Expert object to enter in an infinite loop until one of the engines
92             set the attribute $SELF->BOARD->{SOLVED} to something true.
93             The Chorus::Expert object will ask its agents, one after one, to test all its rules with all
94             possible combinations of its _SCOPE attributes. An agent never ends while at least one of its rules
95             returns a true value in the same loop (see Chorus::Engine documentation).
96            
97             $xprt->process(); # without argument
98             $xprt->process($something); # this argument will become $SELF->BOARD->INPUT for all agents
99            
100             =cut
101              
102             sub process {
103 0     0 1   my ($this, $input) = @_;
104 0           $board->set('INPUT', $input);
105 0           do {
106 0           for (@agents) {
107 0 0         $_->loop() unless $board->{SOLVED};
108             }
109             } until ($board->{SOLVED});
110 0           $board->delete('SOLVED');
111             }
112              
113             =head1 AUTHOR
114              
115             Christophe Ivorra, C<< >>
116              
117             =head1 BUGS
118              
119             Please report any bugs or feature requests to C, or through
120             the web interface at L. I will be notified, and then you'll
121             automatically be notified of progress on your bug as I make changes.
122              
123             =head1 SUPPORT
124              
125             You can find documentation for this module with the perldoc command.
126              
127             perldoc Chorus::Expert
128              
129              
130             You can also look for information at:
131              
132             =over 4
133              
134             =item * RT: CPAN's request tracker (report bugs here)
135              
136             L
137              
138             =item * AnnoCPAN: Annotated CPAN documentation
139              
140             L
141              
142             =item * CPAN Ratings
143              
144             L
145              
146             =item * Search CPAN
147              
148             L
149              
150             =back
151              
152              
153             =head1 ACKNOWLEDGEMENTS
154              
155              
156             =head1 LICENSE AND COPYRIGHT
157              
158             Copyright 2013 Christophe Ivorra.
159              
160             This program is free software; you can redistribute it and/or modify it
161             under the terms of either: the GNU General Public License as published
162             by the Free Software Foundation; or the Artistic License.
163              
164             See http://dev.perl.org/licenses/ for more information.
165              
166              
167             =cut
168              
169 1     1   516 END { }
170              
171             1; # End of Chorus::Expert