00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef INDRI_SCOREDEXTENTACCUMULATOR_HPP
00020 #define INDRI_SCOREDEXTENTACCUMULATOR_HPP
00021
00022 #include "indri/SkippingCapableNode.hpp"
00023 #include <queue>
00024 namespace indri
00025 {
00026 namespace infnet
00027 {
00028
00029 class ScoredExtentAccumulator : public EvaluatorNode {
00030 private:
00031 BeliefNode* _belief;
00032 SkippingCapableNode* _skipping;
00033 std::priority_queue<indri::api::ScoredExtentResult> _scores;
00034 std::vector<indri::api::ScoredExtentResult> _finalScores;
00035 int _resultsRequested;
00036 std::string _name;
00037 EvaluatorNode::MResults _results;
00038
00039 public:
00040 ScoredExtentAccumulator( std::string name, BeliefNode* belief, int resultsRequested = -1 ) :
00041 _belief(belief),
00042 _resultsRequested(resultsRequested),
00043 _name(name),
00044 _skipping(0)
00045 {
00046 if( indri::api::Parameters::instance().get( "skipping", 1 ) )
00047 _skipping = dynamic_cast<SkippingCapableNode*>(belief);
00048 }
00049
00050 void evaluate( lemur::api::DOCID_T documentID, int documentLength ) {
00051 if( _belief->hasMatch( documentID ) ) {
00052 indri::index::Extent docExtent(0, documentLength);
00053 const indri::utility::greedy_vector<indri::api::ScoredExtentResult>& documentScores = _belief->score( documentID, docExtent, documentLength );
00054
00055 for( size_t i=0; i<documentScores.size(); i++ ) {
00056 _scores.push( documentScores[i] );
00057 }
00058
00059 while( int(_scores.size()) > _resultsRequested && _resultsRequested > 0 ) {
00060 _scores.pop();
00061 if( _skipping ) {
00062 double worstScore = _scores.top().score;
00063 _skipping->setThreshold( worstScore - DBL_MIN );
00064 }
00065 }
00066 }
00067 }
00068
00069 lemur::api::DOCID_T nextCandidateDocument() {
00070 return _belief->nextCandidateDocument();
00071 }
00072
00073 const std::string& getName() const {
00074 return _name;
00075 }
00076
00077 const EvaluatorNode::MResults& getResults() {
00078 _results.clear();
00079
00080 if( !_scores.size() )
00081 return _results;
00082
00083
00084 std::priority_queue<indri::api::ScoredExtentResult> heapCopy = _scores;
00085 std::vector<indri::api::ScoredExtentResult>& scoreVec = _results["scores"];
00086
00087
00088 scoreVec.reserve( heapCopy.size() );
00089 for( int i=heapCopy.size()-1; i>=0; i-- ) {
00090 scoreVec.push_back( heapCopy.top() );
00091 heapCopy.pop();
00092 }
00093
00094 return _results;
00095 }
00096
00097 void indexChanged( indri::index::Index& index ) {
00098
00099 }
00100 };
00101 }
00102 }
00103
00104 #endif // INDRI_SCOREDEXTENTACCUMULATOR_HPP
00105