00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef INDRI_WEIGHTEDANDNODE_HPP
00020 #define INDRI_WEIGHTEDANDNODE_HPP
00021
00022 #include <vector>
00023 #include "indri/BeliefNode.hpp"
00024 #include "indri/SkippingCapableNode.hpp"
00025 #include "indri/ScoredExtentResult.hpp"
00026 #include <math.h>
00027 namespace indri
00028 {
00029 namespace infnet
00030 {
00031
00032 class WeightedAndNode : public SkippingCapableNode {
00033 private:
00034 struct child_type {
00035 struct maxscore_less {
00036 public:
00037 bool operator () ( const child_type& one, const child_type& two ) const {
00038
00039
00040
00041
00042 return (one.backgroundWeightedScore) >
00043 (two.backgroundWeightedScore);
00044 }
00045 };
00046
00047 BeliefNode* node;
00048 double weight;
00049 double maximumWeightedScore;
00050 double backgroundWeightedScore;
00051 };
00052
00053 std::vector<child_type> _children;
00054 indri::utility::greedy_vector<indri::api::ScoredExtentResult> _scores;
00055 indri::utility::greedy_vector<bool> _matches;
00056 std::string _name;
00057
00058 indri::utility::greedy_vector<lemur::api::DOCID_T> _candidates;
00059 size_t _candidatesIndex;
00060
00061 double _threshold;
00062 double _recomputeThreshold;
00063 int _quorumIndex;
00064 void _computeQuorum();
00065 double _computeMaxScore( unsigned int start );
00066
00067 public:
00068 WeightedAndNode( const std::string& name ) : _name(name), _threshold(-DBL_MAX), _quorumIndex(0), _recomputeThreshold(-DBL_MAX) {}
00069
00070 void addChild( double weight, BeliefNode* node );
00071 void doneAddingChildren();
00072
00073
00074 void setSiblingsFlag(int f);
00075
00076
00077 void setThreshold( double threshold );
00078
00079
00080 lemur::api::DOCID_T nextCandidateDocument();
00081 void indexChanged( indri::index::Index& index );
00082 double maximumScore();
00083 double maximumBackgroundScore();
00084 indri::utility::greedy_vector<indri::api::ScoredExtentResult>& score( lemur::api::DOCID_T documentID, indri::index::Extent &extent, int documentLength );
00085 void annotate( class Annotator& annotator, lemur::api::DOCID_T documentID, indri::index::Extent &extent );
00086 bool hasMatch( lemur::api::DOCID_T documentID );
00087 const indri::utility::greedy_vector<bool>& hasMatch( lemur::api::DOCID_T documentID, const indri::utility::greedy_vector<indri::index::Extent>& extents );
00088 const std::string& getName() const;
00089 };
00090 }
00091 }
00092
00093 #endif // INDRI_WEIGHTEDANDNODE_HPP
00094