00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef INDRI_SHRINKAGEBELIEFNODE_HPP
00020 #define INDRI_SHRINKAGEBELIEFNODE_HPP
00021
00022 #include "indri/BeliefNode.hpp"
00023 #include "indri/TermScoreFunction.hpp"
00024 #include "indri/greedy_vector"
00025 #include "indri/ScoredExtentResult.hpp"
00026 #include "indri/DocumentStructureHolderNode.hpp"
00027 #include <vector>
00028 #include <set>
00029 #include <map>
00030
00031 namespace indri
00032 {
00033 namespace infnet
00034 {
00035
00036 class ShrinkageBeliefNode : public BeliefNode {
00037 protected:
00038 ListIteratorNode& _list;
00039 DocumentStructureHolderNode& _docStructHolder;
00040 double _maximumScore;
00041 double _maximumBackgroundScore;
00042 indri::query::TermScoreFunction& _scoreFunction;
00043 indri::utility::greedy_vector<indri::api::ScoredExtentResult> _results;
00044 indri::utility::greedy_vector<bool> _matches;
00045 std::string _name;
00046
00047 indri::utility::greedy_vector<double> _down;
00048 indri::utility::greedy_vector<double> _up;
00049 indri::utility::greedy_vector<double> _base;
00050 indri::utility::greedy_vector<double> _counts;
00051 lemur::api::DOCID_T _documentID;
00052
00053
00054 typedef struct sr {
00055 std::string fieldName;
00056 double weight;
00057 bool lengthProportional;
00058 } smoothing_rule;
00059
00060 struct lt_rule {
00061 bool operator()( smoothing_rule r1, smoothing_rule r2 ) const {
00062 int cmpVal = strcmp( r1.fieldName.c_str(), r2.fieldName.c_str() );
00063 if ( cmpVal != 0 ) {
00064 return cmpVal < 0;
00065 }
00066 if ( r1.weight != r2.weight ) {
00067 return r1.weight < r2.weight;
00068 }
00069 if ( r1.lengthProportional != r2.lengthProportional) {
00070 return r1.lengthProportional;
00071 }
00072 return false;
00073 }
00074 };
00075
00076 std::set<smoothing_rule, lt_rule> _ruleSet;
00077 std::map<int, smoothing_rule> _ruleMap;
00078
00079 double _parentWeight;
00080 double _docWeight;
00081 double _otherWeight;
00082 bool _recursive;
00083 bool _queryLevelCombine;
00084 double _defaultScore;
00085
00086
00087 std::set<int> _roots;
00088 indri::utility::greedy_vector<int> _topDownOrder;
00089
00090 void _buildScoreCache( lemur::api::DOCID_T documentID );
00091
00092 public:
00093 ShrinkageBeliefNode( const std::string& name,
00094 ListIteratorNode& child,
00095 DocumentStructureHolderNode& documentStructureHolderNode,
00096 indri::query::TermScoreFunction& scoreFunction,
00097 double maximumBackgroundScore,
00098 double maximumScore );
00099
00100 lemur::api::DOCID_T nextCandidateDocument();
00101 void indexChanged( indri::index::Index& index );
00102 double maximumBackgroundScore();
00103 double maximumScore();
00104 const indri::utility::greedy_vector<indri::api::ScoredExtentResult>& score( lemur::api::DOCID_T documentID, indri::index::Extent &extent, int documentLength );
00105 void annotate( class Annotator& annotator, lemur::api::DOCID_T documentID, indri::index::Extent &extent );
00106 bool hasMatch( lemur::api::DOCID_T documentID );
00107 const indri::utility::greedy_vector<bool>& hasMatch( lemur::api::DOCID_T documentID, const indri::utility::greedy_vector<indri::index::Extent>& extents );
00108 const std::string& getName() const;
00109 void addShrinkageRule( std::string rule );
00110
00111 void setSmoothing( const std::string & stringSpec );
00112 };
00113 }
00114 }
00115
00116 #endif // INDRI_SHRINKAGEBELIEFNODE_HPP