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

StructQueryRetMethod.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: fff
00013 */
00014 
00015 
00016 #ifndef _STRUCTQUERYRETMETHOD_HPP
00017 #define _STRUCTQUERYRETMETHOD_HPP
00018 
00019 #include "RetrievalMethod.hpp"
00020 #include "StructQueryRep.hpp"
00021 #include "DocumentRep.hpp"
00022 #include "ScoreFunction.hpp"
00023 #include "ScoreAccumulator.hpp"
00024 #include "FreqVector.hpp"
00025 
00026 namespace lemur 
00027 {
00028   namespace api
00029   {
00030     
00032 
00049     class StructQueryRetMethod : public RetrievalMethod {
00050     public:
00051       StructQueryRetMethod(const Index &ind) : RetrievalMethod(ind) {}
00052       virtual ~StructQueryRetMethod() {}
00054       //(caller responsible for deleting the memory of the generated new instance)
00055       virtual lemur::retrieval::StructQueryRep *computeStructQueryRep(const TermQuery &qry) = 0;
00056 
00058       virtual QueryRep *computeQueryRep(const Query &qry); 
00060       virtual double scoreDoc(const QueryRep &qry, DOCID_T docID);
00062       virtual void scoreCollection(const QueryRep &qry, IndexedRealVector &results);
00063 
00066       virtual DocumentRep *computeDocRep(DOCID_T docID) = 0;
00068       virtual ScoreFunction *scoreFunc() = 0;
00070       virtual void updateQuery(QueryRep &qryRep, const DocIDSet &relDocs) {
00071         updateStructQuery(*((lemur::retrieval::StructQueryRep *)(&qryRep)), relDocs);
00072       }
00073 
00076       virtual void updateStructQuery(lemur::retrieval::StructQueryRep &qryRep, 
00077                                      const DocIDSet &relDocs) = 0;
00078 
00080       virtual void scoreInvertedIndex(const QueryRep &qryRep, 
00081                                       IndexedRealVector &scores, 
00082                                       bool scoreAll=false);
00083     };
00084 
00086     class StructQueryScoreFunc : public ScoreFunction {
00087     public:
00089       virtual double evalQuery(const lemur::retrieval::QueryNode *qn, const DocumentRep *dRep) {
00090         return qn->eval(dRep);
00091       }
00093       virtual double adjustedScore(double w, const lemur::retrieval::QueryNode *qn) {
00094         return w;
00095       }  
00096     };
00097 
00098     //=============== inlines ========================================
00099 
00100     inline QueryRep *StructQueryRetMethod::computeQueryRep(const Query &qry) { 
00101       if (const TermQuery *q = dynamic_cast<const TermQuery *>(&qry))
00102         return (computeStructQueryRep(*q));
00103       else LEMUR_THROW(LEMUR_RUNTIME_ERROR,"StructQueryRetMethod expects query of type TermQuery");
00104     }
00105   }
00106 }
00107 
00108 #endif /* _STRUCTQUERYRETMETHOD_HPP */

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