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

ContextInclusionAndNode.hpp

Go to the documentation of this file.
00001 /*==========================================================================
00002  * Copyright (c) 2006 Carnegie Mellon University.  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 below), and also available at
00007  * http://www.lemurproject.org/license.html
00008  *
00009  *==========================================================================
00010  */
00011 
00012 
00013 //
00014 // ContextInclusionAndNode
00015 //
00016 // 31 Aug 2005 -- pto
00017 //
00018 
00019 //
00020 // Behaves similary to a WeightedAndNode, but requires that one child be a 
00021 // special node that we wish to preserve the extents for during ranking.
00022 // Other nodes are considered the "context" nodes.
00023 //
00024 
00025 #ifndef INDRI_CONTEXTINCLUSIONANDNODE_HPP
00026 #define INDRI_CONTEXTINCLUSIONANDNODE_HPP
00027 
00028 #include <vector>
00029 #include "indri/BeliefNode.hpp"
00030 #include "indri/SkippingCapableNode.hpp"
00031 #include "indri/ScoredExtentResult.hpp"
00032 #include <math.h>
00033 namespace indri
00034 {
00035   namespace infnet
00036   {
00037     
00038     class ContextInclusionAndNode : public SkippingCapableNode {
00039     private:
00040       struct child_type {
00041         struct maxscore_less {
00042         public:
00043           bool operator () ( const child_type& one, const child_type& two ) const {
00044             // think of these two elements as the only two elements in the
00045             // #wand.  What is the threshold of each ordering?  Sort by
00046             // the lowest threshold.
00047 
00048             return (one.backgroundWeightedScore) > 
00049               (two.backgroundWeightedScore);
00050           }
00051         };
00052 
00053         BeliefNode* node;
00054         double weight;
00055         double maximumWeightedScore;
00056         double backgroundWeightedScore;
00057       };
00058 
00059       std::vector<child_type> _children;
00060       indri::utility::greedy_vector<indri::api::ScoredExtentResult> _scores;
00061       indri::utility::greedy_vector<bool> _matches;
00062       std::string _name;
00063 
00064       indri::utility::greedy_vector<lemur::api::DOCID_T> _candidates;
00065       size_t _candidatesIndex;
00066 
00067       double _threshold;
00068       double _recomputeThreshold;
00069       int _quorumIndex;
00070       void _computeQuorum();
00071       double _computeMaxScore( unsigned int start );
00072 
00073       BeliefNode * _preserveExtentsChild;
00074 
00075     public:
00076       ContextInclusionAndNode( const std::string& name ) : _name(name), _threshold(-DBL_MAX), _quorumIndex(0), _recomputeThreshold(-DBL_MAX), _preserveExtentsChild(0) {}
00077 
00078       void addChild( double weight, BeliefNode* node, bool preserveExtents = false );
00079       void doneAddingChildren();
00080 
00081       // SkippingCapableNode
00082       void setThreshold( double threshold );
00083 
00084       // InferenceNetworkNode interface
00085       lemur::api::DOCID_T nextCandidateDocument();
00086       void indexChanged( indri::index::Index& index );
00087       double maximumScore();
00088       double maximumBackgroundScore();
00089       indri::utility::greedy_vector<indri::api::ScoredExtentResult>& score( lemur::api::DOCID_T documentID, indri::index::Extent &extent, int documentLength );
00090       void annotate( class Annotator& annotator, lemur::api::DOCID_T documentID, indri::index::Extent &extent );
00091       bool hasMatch( lemur::api::DOCID_T documentID );
00092       const indri::utility::greedy_vector<bool>& hasMatch( lemur::api::DOCID_T documentID, const indri::utility::greedy_vector<indri::index::Extent>& extents );
00093       const std::string& getName() const;
00094     };
00095   }
00096 }
00097 
00098 #endif // INDRI_CONTEXTINCLUSIONANDNODE_HPP
00099 

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