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

MaxNode.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 // MaxNode
00015 //
00016 // 1 April 2004 -- tds
00017 //
00018 
00019 #ifndef INDRI_MAXNODE_HPP
00020 #define INDRI_MAXNODE_HPP
00021 
00022 #include "indri/BeliefNode.hpp"
00023 #include "indri/ScoredExtentResult.hpp"
00024 #include "indri/Annotator.hpp"
00025 
00026 class MaxNode : public BeliefNode {
00027 private:
00028   std::vector<BeliefNode*> _children;
00029   greedy_vector<ScoredExtentResult> _scores;
00030   std::string _name;
00031 
00032 public:
00033   MaxNode( const std::string& name ) : _name(name) {}
00034   MaxNode( const std::string& name, const std::vector<BeliefNode*>& children ) :
00035     _children( children ),
00036     _name( name )
00037   {
00038   }
00039 
00040   int nextCandidateDocument() {
00041     int candidate = MAX_INT32;
00042 
00043     for( unsigned int i=0; i<_children.size(); i++ ) {
00044       candidate = lemur_compat::min<int>( candidate, _children[i]->nextCandidateDocument() );
00045     }
00046 
00047     return candidate;
00048   }
00049 
00050   greedy_vector<ScoredExtentResult>& score( int documentID, int begin, int end, int documentLength ) {
00051     double maxScore = INDRI_TINY_SCORE;
00052 
00053     for( unsigned int i=0; i<_children.size(); i++ ) {
00054       const greedy_vector<ScoredExtentResult>& childResults = _children[i]->score( documentID, begin, end, documentLength );
00055 
00056       for( unsigned int j=0; j<childResults.size(); j++ ) {
00057         maxScore = lemur_compat::max<double>( maxScore, childResults[j].score );
00058       }
00059     }
00060 
00061     _scores.clear();
00062     _scores.push_back( ScoredExtentResult( maxScore, documentID, begin, end ) );
00063 
00064     return _scores;
00065   }
00066 
00067   void annotate( class Annotator& annotator, int documentID, int begin, int end ) {
00068     annotator.add( this, documentID, begin, end );
00069 
00070     // find the maximum score here, then descend only into that one
00071     double maxScore = INDRI_TINY_SCORE;
00072     int maxI = -1;
00073     int maxJ = -1;
00074     int maxBegin = -1;
00075     int maxEnd = -1;
00076 
00077     for( unsigned int i=0; i<_children.size(); i++ ) {
00078       const greedy_vector<ScoredExtentResult>& childResults = _children[i]->score( documentID, begin, end, end );
00079 
00080       for( unsigned int j=0; j<childResults.size(); j++ ) {
00081         maxScore = lemur_compat::max<double>( maxScore, childResults[j].score );
00082         maxI = i;
00083         maxJ = j;
00084         maxBegin = childResults[j].begin;
00085         maxEnd = childResults[j].end;
00086       }
00087     }
00088 
00089     _children[maxI]->annotate( annotator, documentID, maxBegin, maxEnd );
00090   }
00091 
00092   double maximumScore() {
00093     double maxScore = INDRI_TINY_SCORE;
00094 
00095     for( unsigned int i=0; i<_children.size(); i++ ) {
00096       maxScore = lemur_compat::max<double>( maxScore, _children[i]->maximumScore() );  
00097     }
00098 
00099     return maxScore;
00100   }
00101 
00102   double maximumBackgroundScore() {
00103     double maxScore = INDRI_TINY_SCORE;
00104 
00105     for( unsigned int i=0; i<_children.size(); i++ ) {
00106       maxScore = lemur_compat::max<double>( maxScore, _children[i]->maximumBackgroundScore() );  
00107     }
00108 
00109     return maxScore;
00110   }
00111 
00112   bool hasMatch( int documentID ) {
00113     for( unsigned int i=0; i<_children.size(); i++ ) {
00114       if( _children[i]->hasMatch( documentID ) )
00115         return true;
00116     }
00117 
00118     return false;
00119   }
00120 
00121   const std::string& getName() const {
00122     return _name;
00123   }
00124 };
00125 
00126 #endif // INDRI_MAXNODE_HPP
00127 

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