Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class 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 namespace lemur 
00018 {
00019   namespace api 
00020   {
00021     
00022     //------------------------------------------------------------
00023     //      Abstract Interface for A Score Accumulator
00024     //------------------------------------------------------------
00025 
00027     class ScoreAccumulator {
00028     public:
00029       virtual ~ScoreAccumulator(){}
00030       
00032       virtual void reset()=0;
00034       virtual bool findScore(int id, double &score)const =0;
00036       virtual void setScore(int id, double score)=0;
00038       virtual void incScore(int id, double score)=0;
00039   
00041       virtual void startIteration()const =0;
00042       virtual bool hasMore() const = 0;
00043       virtual void nextScore(int &id, double &score) const =0;
00044 
00045     };
00046   }
00047 }
00048 
00049 namespace lemur 
00050 {
00051   namespace retrieval 
00052   {
00053     
00054     //------------------------------------------------------------
00055     //      An Array Score Accumulator
00056     //------------------------------------------------------------
00057 
00059     class ArrayAccumulator : public lemur::api::ScoreAccumulator {
00060     public:
00061       ArrayAccumulator(int maxID);
00062 
00063       virtual ~ArrayAccumulator() { delete [] acc; delete [] status;}
00064 
00066       virtual void reset();
00067   
00069       virtual bool findScore(int id, double &score) const ;
00070 
00072       virtual void setScore(int id, double score) { 
00073         acc[id-1] = score;
00074         status[id-1] =1;
00075       }
00076 
00078       virtual void incScore(int id, double score) {
00079         acc[id-1] += score;
00080         status[id-1] =1;
00081       }
00082   
00084       virtual void startIteration() const { p = 0; }
00085       bool hasMore()const ;
00086   
00087       void nextScore(int &id, double &score)const ; 
00088 
00089     protected:
00090       mutable int p;
00091       int sz;
00092       double *acc;
00093       short *status;
00094     };
00095 
00096 
00097     // ============== inlines ==============================
00098 
00099     inline ArrayAccumulator::ArrayAccumulator(int maxID) : sz(maxID) 
00100     { 
00101       acc = new double[maxID]; // index 0 refers to docid 1.
00102       status = new short[maxID]; // using integer making the test faster
00103     }
00104   }
00105 }
00106 
00107 
00108 #endif /* _SCOREACCUMULATOR_HPP */

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