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

CosSimRetMethod.hpp

Go to the documentation of this file.
00001 /*==========================================================================
00002  * Copyright (c) 2002 University of Massachusetts.  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   Author: dmf 9/2002
00013 */
00014 
00015 #ifndef _COSSIMRETMETHOD_HPP
00016 #define _COSSIMRETMETHOD_HPP
00017 
00018 #include "TextQueryRetMethod.hpp"
00019 
00021 namespace CosSimParameter {
00022   struct FeedbackParam {
00023     int howManyTerms;
00024     double posCoeff;
00025   };    
00026   static int defaultHowManyTerms = 50;
00027   static double defaultPosCoeff = 0.5;
00028   static const string defaultL2File = "cos.L2";
00029 }
00030 namespace lemur
00031 {
00032   namespace retrieval 
00033   {
00034     
00036     class CosSimQueryRep : public ArrayQueryRep {
00037     public:
00039       CosSimQueryRep(const lemur::api::TermQuery &qry, const lemur::api::Index &dbIndex, 
00040                      double *idfValue);
00042       CosSimQueryRep(lemur::api::DOCID_T docId, const lemur::api::Index &dbIndex, double *idfValue);
00043       virtual ~CosSimQueryRep() {}
00044     protected:
00045       double *idf;
00046       const lemur::api::Index &ind;
00047     };
00048 
00050     class CosSimDocRep : public lemur::api::DocumentRep {
00051     public:
00052       CosSimDocRep(lemur::api::DOCID_T docID, double *idfValue, double norm, int dl) : 
00053         lemur::api::DocumentRep(docID, dl), idf(idfValue), dNorm(norm) {
00054       }
00055       virtual ~CosSimDocRep() { }
00057       virtual double termWeight(lemur::api::TERMID_T termID, const lemur::api::DocInfo *info) const { 
00058         return (idf[termID]*info->termCount()); 
00059       }
00061       virtual double scoreConstant() const { return dNorm;}
00062 
00063     private:
00065       double *idf;
00067       double dNorm; 
00068     };
00069 
00071     class CosSimScoreFunc : public lemur::api::ScoreFunction {
00072     public:
00073       CosSimScoreFunc(const lemur::api::Index &dbIndex): ind(dbIndex) {}
00075       virtual double adjustedScore(double origScore, const lemur::api::TextQueryRep *qRep, 
00076                                    const lemur::api::DocumentRep *dRep) const {
00077         return origScore/dRep->scoreConstant();
00078       }
00079     protected:
00080       const lemur::api::Index &ind;
00081     };
00082 
00084     class CosSimRetMethod : public lemur::api::TextQueryRetMethod {
00085     public:
00087       CosSimRetMethod(const lemur::api::Index &dbIndex, lemur::api::ScoreAccumulator &accumulator);
00092       CosSimRetMethod(const lemur::api::Index &dbIndex, const string &L2file,
00093                       lemur::api::ScoreAccumulator &accumulator);
00094 
00095       virtual ~CosSimRetMethod();
00096 
00097       virtual lemur::api::TextQueryRep *computeTextQueryRep(const lemur::api::TermQuery &qry) {
00098         return (new CosSimQueryRep(qry, ind, idfV));
00099       }
00100 
00101       virtual lemur::api::TextQueryRep *computeTextQueryRep(lemur::api::DOCID_T docid) {
00102         return (new CosSimQueryRep(docid, ind, idfV));
00103       }
00104 
00105       virtual lemur::api::DocumentRep *computeDocRep(lemur::api::DOCID_T docID) { 
00106         return (new CosSimDocRep(docID, idfV, docNorm(docID), 
00107                                  ind.docLength(docID)));
00108       }
00109       virtual lemur::api::ScoreFunction *scoreFunc() {
00110         return (scFunc);
00111       }
00112       virtual void updateTextQuery(lemur::api::TextQueryRep &qryRep, 
00113                                    const lemur::api::DocIDSet &relDocs);
00114       void setFeedbackParam(CosSimParameter::FeedbackParam &feedbackParam);
00115     protected:
00116   
00117       double *idfV;
00118       lemur::api::ScoreFunction *scFunc;
00119       double * docNorms;
00120       int numDocs, numTerms;
00121 
00123 
00124       CosSimParameter::FeedbackParam fbParam;
00126       const string &L2FileName;
00128 
00130       double docNorm(lemur::api::DOCID_T docID);
00132       void loadDocNorms();
00133     };
00134 
00135     inline void CosSimRetMethod::setFeedbackParam(CosSimParameter::FeedbackParam 
00136                                                   &feedbackParam) {
00137       fbParam = feedbackParam;
00138     }
00139   }
00140 }
00141 
00142 #endif /* _COSSIMRETMETHOD_HPP */

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