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 namespace lemur
00025 {
00026 namespace api
00027 {
00028
00029
00030
00031
00032
00034
00035 class QueryTerm {
00036 public:
00037 QueryTerm(TERMID_T termID, double weight) : ti(termID), w(weight) {
00038 }
00039 virtual ~QueryTerm() {}
00040 virtual TERMID_T id() const { return ti;}
00041 virtual double weight() const { return w;}
00042 protected:
00043 TERMID_T ti;
00044 double w;
00045 };
00046
00048
00049 class TextQueryRep : public QueryRep {
00050 public:
00051 virtual ~TextQueryRep() {}
00053 virtual void startIteration() const = 0;
00054 virtual bool hasMore() const = 0;
00055
00057 virtual QueryTerm *nextTerm() const = 0;
00058
00060 virtual double scoreConstant() const = 0;
00061
00062 };
00063 }
00064 }
00065 namespace lemur
00066 {
00067 namespace retrieval
00068 {
00069
00071
00072 class ArrayQueryRep : public lemur::api::TextQueryRep {
00073 public:
00075 ArrayQueryRep(int size) : ct(new lemur::utility::ArrayCounter<double>(size)), scConst(0) {
00076 }
00078 ArrayQueryRep(int size, const lemur::api::TermQuery &qry, const lemur::api::Index &dbIndex);
00080 ArrayQueryRep(int size, const lemur::utility::FreqVector &qryVec);
00081
00082 virtual ~ArrayQueryRep() { delete ct; }
00083
00084
00085 virtual void startIteration() const {
00086 ct->startIteration();
00087 }
00088
00089 virtual bool hasMore() const{
00090 return (ct->hasMore());
00091 }
00092
00093
00094 virtual lemur::api::QueryTerm *nextTerm() const;
00095
00096
00097 virtual void incCount(lemur::api::TERMID_T wdIndex, double count) {
00098 ct->incCount(wdIndex,count);
00099 }
00100
00101 virtual void setCount(lemur::api::TERMID_T wdIndex, double count) {
00102 ct->setCount(wdIndex,count);
00103 }
00104
00105 virtual double totalCount() const { return ct->sum();}
00106
00107 virtual double scoreConstant() const{ return scConst;}
00108
00109 virtual void setScoreConstant(double scoreConst) { scConst = scoreConst;}
00110
00111
00112 protected:
00113 virtual lemur::api::QueryTerm *makeQueryTerm(lemur::api::TERMID_T wdIndex, double wdCount) const {
00114 return (new lemur::api::QueryTerm(wdIndex, wdCount));
00115 }
00116 double scConst;
00117 lemur::utility::ArrayCounter<double> *ct;
00118 };
00119 }
00120 }
00121 namespace lemur
00122 {
00123 namespace api
00124 {
00125
00127
00128 class PseudoFBDocs : public DocIDSet {
00129 public:
00131 PseudoFBDocs(IndexedRealVector &results, int howManyDoc, bool ignoreWeight=true):
00132 res(&results), howMany(howManyDoc), noWeight(ignoreWeight) {
00133 }
00134 virtual ~PseudoFBDocs() {}
00135
00136 virtual void startIteration() const{
00137 it = res->begin();
00138 i=0;
00139 }
00140 virtual bool hasMore() const;
00141
00142 virtual void nextIDInfo(int &id, double &relProb) const;
00143
00144 private:
00145 mutable IndexedRealVector *res;
00146 int howMany;
00147 mutable int i;
00148 bool noWeight;
00149 mutable IndexedRealVector::iterator it;
00150 };
00151 }
00152 }
00153 #endif