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

ScoreAccumulator.hpp

Go to the documentation of this file.
00001 /*==========================================================================
00002  * Copyright (c) 2001 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 also available at
00007  * http://www.lemurproject.org/license.html
00008  *
00009  *==========================================================================
00010 */
00011 
00012 
00013 #ifndef _SCOREACCUMULATOR_HPP
00014 #define _SCOREACCUMULATOR_HPP
00015 
00016 
00017 //------------------------------------------------------------
00018 //      Abstract Interface for A Score Accumulator
00019 //------------------------------------------------------------
00020 
00022 class ScoreAccumulator {
00023 public:
00025   virtual void reset()=0;
00027   virtual bool findScore(int id, double &score)const =0;
00029   virtual void setScore(int id, double score)=0;
00031   virtual void incScore(int id, double score)=0;
00032   
00034   virtual void startIteration()const =0;
00035   virtual bool hasMore() const = 0;
00036   virtual void nextScore(int &id, double &score) const =0;
00037 
00038 };
00039 
00040 
00041 //------------------------------------------------------------
00042 //      An Array Score Accumulator
00043 //------------------------------------------------------------
00044 
00046 class ArrayAccumulator : public ScoreAccumulator {
00047 public:
00048   ArrayAccumulator(int maxID);
00049 
00050   virtual ~ArrayAccumulator() { delete [] acc; delete [] status;}
00051 
00053   virtual void reset();
00054   
00056   virtual bool findScore(int id, double &score) const ;
00057 
00059   virtual void setScore(int id, double score) { 
00060     acc[id-1] = score;
00061     status[id-1] =1;
00062   }
00063 
00065   virtual void incScore(int id, double score) {
00066     acc[id-1] += score;
00067     status[id-1] =1;
00068   }
00069   
00071   virtual void startIteration() const { p = 0; }
00072   bool hasMore()const ;
00073   
00074   void nextScore(int &id, double &score)const ; 
00075 
00076 protected:
00077   mutable int p;
00078   int sz;
00079   double *acc;
00080   short *status;
00081 };
00082 
00083 
00084 // ============== inlines ==============================
00085 
00086 inline ArrayAccumulator::ArrayAccumulator(int maxID) : sz(maxID) 
00087 { 
00088   acc = new double[maxID]; // index 0 refers to docid 1.
00089   status = new short[maxID]; // using integer making the test faster
00090 }
00091 
00092 
00093 #endif /* _SCOREACCUMULATOR_HPP */
00094 
00095 
00096 
00097 
00098 
00099 
00100 
00101 

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