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