00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _TEXTQUERYREP_HPP
00014 #define _TEXTQUERYREP_HPP
00015
00016 #include "RetrievalMethod.hpp"
00017 #include "TextQuery.hpp"
00018 #include "IndexedReal.hpp"
00019 #include "Index.hpp"
00020 #include "Counter.hpp"
00021 #include "WeightedIDSet.hpp"
00022 #include "FreqVector.hpp"
00023
00024
00025
00026
00027
00029
00030 class QueryTerm {
00031 public:
00032 QueryTerm(TERMID_T termID, double weight) : ti(termID), w(weight) {
00033 }
00034 virtual ~QueryTerm() {}
00035 virtual TERMID_T id() const { return ti;}
00036 virtual double weight() const { return w;}
00037 protected:
00038 TERMID_T ti;
00039 double w;
00040 };
00041
00043
00044 class TextQueryRep : public QueryRep {
00045 public:
00046 virtual ~TextQueryRep() {}
00048 virtual void startIteration() const = 0;
00049 virtual bool hasMore() const = 0;
00050
00052 virtual QueryTerm *nextTerm() const = 0;
00053
00055 virtual double scoreConstant() const = 0;
00056
00057 };
00058
00059
00060
00061
00063
00064 class ArrayQueryRep : public TextQueryRep {
00065 public:
00067 ArrayQueryRep(int size) : ct(new ArrayCounter<double>(size)), scConst(0) {
00068 }
00070 ArrayQueryRep(int size, const TermQuery &qry, const Index &dbIndex);
00072 ArrayQueryRep(int size, const FreqVector &qryVec);
00073
00074 virtual ~ArrayQueryRep() { delete ct; }
00075
00076
00077 virtual void startIteration() const {
00078 ct->startIteration();
00079 }
00080
00081 virtual bool hasMore() const{
00082 return (ct->hasMore());
00083 }
00084
00085
00086 virtual QueryTerm *nextTerm() const;
00087
00088
00089 virtual void incCount(TERMID_T wdIndex, double count) {
00090 ct->incCount(wdIndex,count);
00091 }
00092
00093 virtual void setCount(TERMID_T wdIndex, double count) {
00094 ct->setCount(wdIndex,count);
00095 }
00096
00097 virtual double totalCount() const { return ct->sum();}
00098
00099 virtual double scoreConstant() const{ return scConst;}
00100
00101 virtual void setScoreConstant(double scoreConst) { scConst = scoreConst;}
00102
00103
00104 protected:
00105 virtual QueryTerm *makeQueryTerm(TERMID_T wdIndex, double wdCount) const {
00106 return (new QueryTerm(wdIndex, wdCount));
00107 }
00108 double scConst;
00109 ArrayCounter<double> *ct;
00110 };
00111
00113
00114 class PseudoFBDocs : public DocIDSet {
00115 public:
00117 PseudoFBDocs(IndexedRealVector &results, int howManyDoc, bool ignoreWeight=true):
00118 res(&results), howMany(howManyDoc), noWeight(ignoreWeight) {
00119 }
00120 virtual ~PseudoFBDocs() {}
00121
00122 virtual void startIteration() const{
00123 it = res->begin();
00124 i=0;
00125 }
00126 virtual bool hasMore() const;
00127
00128 virtual void nextIDInfo(int &id, double &relProb) const;
00129
00130 private:
00131 mutable IndexedRealVector *res;
00132 int howMany;
00133 mutable int i;
00134 bool noWeight;
00135 mutable IndexedRealVector::iterator it;
00136 };
00137
00138
00139
00140 #endif
00141
00142
00143
00144
00145