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

TextQueryRep.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.cs.cmu.edu/~lemur/license.html
00008  *
00009  *==========================================================================
00010 */
00011 
00012 
00013 #ifndef _TEXTQUERYREP_HPP
00014 #define _TEXTQUERYREP_HPP
00015 
00016 #include "RetrievalMethod.hpp"
00017 #include "Document.hpp"
00018 #include "IndexedReal.hpp"
00019 #include "Index.hpp"
00020 #include "Counter.hpp"
00021 #include "WeightedIDSet.hpp"
00022 #include "FreqVector.hpp"
00023 
00024 //------------------------------------------------------------
00025 //      Abstract Interface for Text Query 
00026 //------------------------------------------------------------
00027 
00029 class TextQuery : public Query {
00030 public:
00031   TextQuery(Document &doc) : d(doc) {}
00032   virtual ~TextQuery() {}
00033 
00034   virtual char *id() { return d.getID();}
00035   virtual void startTermIteration() { d.startTermIteration();}
00036   virtual bool hasMore() { return d.hasMore();}
00037   virtual TokenTerm *nextTerm() { return d.nextTerm();}
00038 protected:
00039   Document &d;
00040 };
00041 
00042 
00043 
00044 //------------------------------------------------------------
00045 //      Abstract Interface for Text Query Representation 
00046 //------------------------------------------------------------
00047 
00049 
00050 class QueryTerm {
00051 public:
00052   QueryTerm(int termID, double weight) : ti(termID), w(weight) {
00053   } 
00054   ~QueryTerm() {}
00055   virtual int id() { return ti;}
00056   virtual double weight() { return w;}
00057 protected:
00058   int ti;
00059   double w;
00060 };
00061 
00063 
00064 class TextQueryRep : public QueryRep {
00065 public:
00066   virtual ~TextQueryRep() {}
00068   virtual void startIteration() = 0;
00069   virtual bool hasMore() = 0;
00070 
00072   virtual QueryTerm *nextTerm() = 0;
00073 
00075   virtual double scoreConstant() = 0;
00076 
00077 };
00078 
00079 
00080 
00081 
00083 
00084 class ArrayQueryRep : public TextQueryRep {
00085 public:
00087   ArrayQueryRep(int size) : ct(new ArrayCounter<double>(size)), scConst(0) {
00088   }
00090   ArrayQueryRep(int size, TextQuery &qry, Index &dbIndex);
00092   ArrayQueryRep(int size, FreqVector &qryVec);
00093 
00094   virtual ~ArrayQueryRep() { delete ct; }
00095 
00096 
00097   virtual void startIteration() {
00098     ct->startIteration();
00099   }
00100 
00101   virtual bool hasMore() {
00102     return (ct->hasMore());
00103   }
00104 
00105 
00106   virtual QueryTerm *nextTerm();
00107 
00108 
00109   virtual void incCount(int wdIndex, double count) {
00110     ct->incCount(wdIndex,count);
00111   }
00112 
00113   virtual void setCount(int wdIndex, double count) {
00114     ct->setCount(wdIndex,count);
00115   }
00116 
00117   virtual double totalCount() { return ct->sum();}
00118 
00119   virtual double scoreConstant() { return scConst;}
00120 
00121   virtual void setScoreConstant(double scoreConst) { scConst = scoreConst;}
00122 
00123 
00124 protected:
00125   virtual QueryTerm *makeQueryTerm(int wdIndex, double wdCount) {
00126     return (new QueryTerm(wdIndex, wdCount));
00127   }
00128   double scConst;
00129   ArrayCounter<double> *ct;
00130 };
00131 
00133 
00134 class PseudoFBDocs : public DocIDSet {
00135 public:
00137   PseudoFBDocs(IndexedRealVector &results, int howManyDoc):
00138     res(&results), howMany(howManyDoc) {
00139   }
00140   virtual ~PseudoFBDocs() {}
00141 
00142   virtual void startIteration() {
00143     it = res->begin();
00144     i=0;
00145   }  
00146   virtual bool hasMore() ;
00147 
00148   virtual void nextIDInfo(int &id, double &relProb);
00149 
00150 private:
00151   IndexedRealVector *res;
00152   int howMany;
00153   int i;
00154   IndexedRealVector::iterator it;
00155 };
00156 
00157 
00158 
00159 #endif /* _TEXTQUERYREP_HPP */
00160 
00161 
00162 
00163 
00164 

Generated at Fri Jul 26 18:22:27 2002 for LEMUR by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000