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

WeightedAndNode.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 // WeightedAndNode
00015 //
00016 // 26 January 2004 - tds
00017 //
00018 
00019 #ifndef INDRI_WEIGHTEDANDNODE_HPP
00020 #define INDRI_WEIGHTEDANDNODE_HPP
00021 
00022 #include <vector>
00023 #include "indri/BeliefNode.hpp"
00024 #include "indri/SkippingCapableNode.hpp"
00025 #include "indri/ScoredExtentResult.hpp"
00026 #include <math.h>
00027 namespace indri
00028 {
00029   namespace infnet
00030   {
00031     
00032     class WeightedAndNode : public SkippingCapableNode {
00033     private:
00034       struct child_type {
00035         struct maxscore_less {
00036         public:
00037           bool operator () ( const child_type& one, const child_type& two ) const {
00038             // think of these two elements as the only two elements in the
00039             // #wand.  What is the threshold of each ordering?  Sort by
00040             // the lowest threshold.
00041 
00042             return (one.backgroundWeightedScore) > 
00043               (two.backgroundWeightedScore);
00044           }
00045         };
00046 
00047         BeliefNode* node;
00048         double weight;
00049         double maximumWeightedScore;
00050         double backgroundWeightedScore;
00051       };
00052 
00053       std::vector<child_type> _children;
00054       indri::utility::greedy_vector<indri::api::ScoredExtentResult> _scores;
00055       indri::utility::greedy_vector<bool> _matches;
00056       std::string _name;
00057 
00058       indri::utility::greedy_vector<lemur::api::DOCID_T> _candidates;
00059       size_t _candidatesIndex;
00060 
00061       double _threshold;
00062       double _recomputeThreshold;
00063       int _quorumIndex;
00064       void _computeQuorum();
00065       double _computeMaxScore( unsigned int start );
00066 
00067     public:
00068       WeightedAndNode( const std::string& name ) : _name(name), _threshold(-DBL_MAX), _quorumIndex(0), _recomputeThreshold(-DBL_MAX) {}
00069 
00070       void addChild( double weight, BeliefNode* node );
00071       void doneAddingChildren();
00072 
00073       // override setSiblingsFlag for child node(s)
00074       void setSiblingsFlag(int f);
00075 
00076       // SkippingCapableNode
00077       void setThreshold( double threshold );
00078 
00079       // InferenceNetworkNode interface
00080       lemur::api::DOCID_T nextCandidateDocument();
00081       void indexChanged( indri::index::Index& index );
00082       double maximumScore();
00083       double maximumBackgroundScore();
00084       indri::utility::greedy_vector<indri::api::ScoredExtentResult>& score( lemur::api::DOCID_T documentID, indri::index::Extent &extent, int documentLength );
00085       void annotate( class Annotator& annotator, lemur::api::DOCID_T documentID, indri::index::Extent &extent );
00086       bool hasMatch( lemur::api::DOCID_T documentID );
00087       const indri::utility::greedy_vector<bool>& hasMatch( lemur::api::DOCID_T documentID, const indri::utility::greedy_vector<indri::index::Extent>& extents );
00088       const std::string& getName() const;
00089     };
00090   }
00091 }
00092 
00093 #endif // INDRI_WEIGHTEDANDNODE_HPP
00094 

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