Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

ScoredExtentAccumulator.hpp

Go to the documentation of this file.
00001 /*==========================================================================
00002  * Copyright (c) 2004 University of Massachusetts.  All Rights Reserved.
00003  *
00004  * Use of the Lemur Toolkit for Language Modeling and Information Retrieval
00005  * is subject to the terms of the software license set forth in the LICENSE
00006  * file included with this software, and also available at
00007  * http://www.lemurproject.org/license.html
00008  *
00009  *==========================================================================
00010 */
00011 
00012 
00013 //
00014 // ScoredExtentAccumulator
00015 //
00016 // 24 February 2004 -- tds
00017 //
00018 
00019 #ifndef INDRI_SCOREDEXTENTACCUMULATOR_HPP
00020 #define INDRI_SCOREDEXTENTACCUMULATOR_HPP
00021 
00022 #include "indri/SkippingCapableNode.hpp"
00023 
00024 class ScoredExtentAccumulator : public EvaluatorNode {
00025 private:
00026   BeliefNode* _belief;
00027   SkippingCapableNode* _skipping;
00028   std::priority_queue<ScoredExtentResult> _scores;
00029   std::vector<ScoredExtentResult> _finalScores;
00030   int _resultsRequested;
00031   std::string _name;
00032   EvaluatorNode::MResults _results;
00033 
00034 public:
00035   ScoredExtentAccumulator( std::string name, BeliefNode* belief, int resultsRequested = -1 ) :
00036     _belief(belief),
00037     _resultsRequested(resultsRequested),
00038     _name(name),
00039     _skipping(0)
00040   {
00041     _skipping = dynamic_cast<SkippingCapableNode*>(belief);
00042   }
00043 
00044   void evaluate( int documentID, int documentLength ) {
00045     if( _belief->hasMatch( documentID ) ) {
00046       const greedy_vector<ScoredExtentResult>& documentScores = _belief->score( documentID, 0, documentLength, documentLength );
00047 
00048       for( unsigned int i=0; i<documentScores.size(); i++ ) {
00049         _scores.push( documentScores[i] );
00050       }
00051 
00052       while( int(_scores.size()) > _resultsRequested && _resultsRequested > 0 ) {
00053         _scores.pop();
00054         if( _skipping ) {
00055           double worstScore = _scores.top().score;
00056           _skipping->setThreshold( worstScore - DBL_MIN );
00057         }
00058       }
00059     }
00060   }
00061   
00062   int nextCandidateDocument() {
00063     return _belief->nextCandidateDocument();
00064   }
00065 
00066   const std::string& getName() const {
00067     return _name;
00068   }
00069 
00070   const EvaluatorNode::MResults& getResults() {
00071     _results.clear();
00072 
00073     if( !_scores.size() )
00074       return _results;
00075     
00076     // making a copy of the heap here so the method can be const
00077     std::priority_queue<ScoredExtentResult> heapCopy = _scores;
00078     std::vector<ScoredExtentResult>& scoreVec = _results["scores"];
00079 
00080     // puts scores into the vector in descending order
00081     scoreVec.reserve( heapCopy.size() );
00082     for( int i=(int)heapCopy.size()-1; i>=0; i-- ) {
00083       scoreVec.push_back( heapCopy.top() );
00084       heapCopy.pop();
00085     }
00086 
00087     return _results;
00088   }
00089 };
00090 
00091 #endif // INDRI_SCOREDEXTENTACCUMULATOR_HPP
00092 

Generated on Wed Nov 3 12:59:03 2004 for Lemur Toolkit by doxygen1.2.18