Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

FilterNode.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 // FilterNode
00015 //
00016 // 21 July 2004 -- tds
00017 //
00018 // Restricts evaluation to only a subset of the documents
00019 // in the collection.
00020 //
00021 
00022 #ifndef INDRI_FILTERNODE_HPP
00023 #define INDRI_FILTERNODE_HPP
00024 
00025 namespace indri
00026 {
00027   namespace infnet
00028   {
00029     
00030     class FilterNode : public BeliefNode {
00031     private:
00032       BeliefNode* _belief;
00033       std::vector<lemur::api::DOCID_T> _documents;
00034       std::string _name;
00035       int  _index;
00036       indri::utility::greedy_vector<bool> _matches;
00037       
00038     public:
00039       FilterNode( const std::string& name, BeliefNode* child, const std::vector<lemur::api::DOCID_T>& documents )
00040         :
00041         _documents(documents)
00042       {
00043         _name = name;
00044         _belief = child;
00045         _index = -1;
00046         std::sort( _documents.begin(), _documents.end() );
00047       }
00048 
00049       virtual void setSiblingsFlag(int f) {
00050         bSiblings=f; // need to set the flag for the current node itself.
00051         if (_belief) {  _belief->setSiblingsFlag(f); }
00052       }
00053 
00054       lemur::api::DOCID_T nextCandidateDocument() {
00055           _index++;
00056     
00057         if( _index >= _documents.size() )
00058           return MAX_INT32;
00059 
00060         return _documents[_index];
00061       }
00062 
00063       void annotate( Annotator& annotator, lemur::api::DOCID_T documentID, indri::index::Extent &extent ) {
00064         return _belief->annotate( annotator, documentID, extent );
00065       }
00066 
00067       const indri::utility::greedy_vector<indri::api::ScoredExtentResult>& score( lemur::api::DOCID_T documentID, indri::index::Extent &extent, int documentLength ) {
00068         return _belief->score( documentID, extent, documentLength );
00069       }
00070 
00071       double maximumScore() {
00072         return _belief->maximumScore();
00073       }
00074 
00075       double maximumBackgroundScore() {
00076         return _belief->maximumBackgroundScore();
00077       }
00078 
00079       bool hasMatch( lemur::api::DOCID_T documentID ) {
00080         return _documents[_index] == documentID;
00081       }
00082 
00083       const indri::utility::greedy_vector<bool>& hasMatch( lemur::api::DOCID_T documentID, const indri::utility::greedy_vector<indri::index::Extent>& extents ) {
00084         _matches.clear();
00085         _matches.resize( extents.size(),  _documents[_index] == documentID);
00086         return _matches;
00087     }
00088 
00089       void indexChanged( indri::index::Index& index ) {
00090         // reset the _index to make sure we see newly added documents
00091         _index = -1;
00092       }
00093 
00094       const std::string& getName() const {
00095         return _name;
00096       }
00097     };
00098   }
00099 }
00100 
00101 #endif // INDRI_FILTERNODE_HPP
00102 

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