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

SumNode.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 // SumNode
00015 //
00016 // 3 February 2004 -- tds
00017 //
00018 // True sum of belief inputs (not a weighted or
00019 // normalized sum).
00020 //
00021 
00022 #ifndef INDRI_SUMNODE_HPP
00023 #define INDRI_SUMNODE_HPP
00024 
00025 #include <vector>
00026 #include "lemur-platform.h"
00027 namespace indri
00028 {
00029   namespace lang
00030   {
00031     class SumNode : public BeliefNode {
00032     private:
00033       std::vector<BeliefNode*> _children;
00034       double _threshold;
00035 
00036     public:
00037 
00038       virtual void setSiblingsFlag(int f){
00039         bSiblings=f; // need to set the flag for the current node itself.
00040         if (_child) {  _child->setSiblingsFlag(f); }
00041       }
00042 
00043       void addChild( BeliefNode* beliefNode ) {
00044         // set sibling flag is more than 1 child to speedup
00045         if (_children.size() > 1) {
00046           beliefNode->setSiblingsFlag(1);
00047         }
00048 
00049         _children.push_back( beliefNode );
00050 
00051         // if this is the second child, ensure we have set the sibling flag
00052         // for the first and second ones (it will skip without this!)
00053         if (_children.size()==2) {
00054           for (int i=0; i < _children.size(); i++) {
00055             _children[i]->setSiblingsFlag(1);
00056           }
00057         }
00058 
00059       }
00060 
00061       lemur::api::DOCID_T nextCandidateDocument() {
00062         std::vector<BeliefNode*>::iterator iter;
00063         lemur::api::DOCID_T next = MAX_INT32;
00064 
00065         for( iter = _children.begin(); iter != _children.end(); iter++ ) {
00066           next = lemur_compat::min( next, (*iter)->nextCandidateDocument() );
00067         }
00068 
00069         return next;
00070       }
00071 
00072       double maximumScore() {
00073         std::vector<BeliefNode*>::iterator iter;
00074         double score = 0;
00075 
00076         for( iter = _children.begin(); iter != _children.end(); iter++ ) {
00077           score += (*iter)->maximumScore();
00078         }
00079 
00080         return score;
00081       }
00082 
00083       double score( lemur::api::DOCID_T documentID, int documentLength ) {
00084         std::vector<BeliefNode*>::iterator iter;
00085         double score = 0;
00086 
00087         for( iter = _children.begin(); iter != _children.end(); iter++ ) {
00088           score += (*iter)->score( documentID, documentLength );
00089         }
00090 
00091         return score;
00092       }
00093     };
00094   }
00095 }
00096 
00097 #endif // INDRI_SUMNODE_HPP
00098 
00099 

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