Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class 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 #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         // making a copy of the heap here so the method can be const
00084         std::priority_queue<indri::api::ScoredExtentResult> heapCopy = _scores;
00085         std::vector<indri::api::ScoredExtentResult>& scoreVec = _results["scores"];
00086 
00087         // puts scores into the vector in descending order
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         // do nothing
00099       }
00100     };
00101   }
00102 }
00103 
00104 #endif // INDRI_SCOREDEXTENTACCUMULATOR_HPP
00105 

Generated on Tue Jun 15 11:02:55 2010 for Lemur by doxygen 1.3.4