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

QueryTFWalker.hpp

Go to the documentation of this file.
00001 /*==========================================================================
00002  * Copyright (c) 2009 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 
00013 //
00014 // QueryTFWalker
00015 //
00016 // 07 August 2009 -- dmf
00017 //
00018 
00019 #ifndef INDRI_QUERYTFWALKER_HPP
00020 #define INDRI_QUERYTFWALKER_HPP
00021 
00022 #include <string>
00023 #include <map>
00024 #include <vector>
00025 #include <iostream>
00026 
00027 #include "indri/QuerySpec.hpp"
00028 #include "indri/Walker.hpp"
00029 #include "indri/QueryServer.hpp"
00030 
00031 namespace indri
00032 {
00033   namespace lang
00034   {
00035     
00036     class QueryTFWalker : public indri::lang::Walker {
00037     private:
00038       // map query term -> RawScorerNode list
00039       // qTF is the length of the list
00040       std::map< lemur::api::TERMID_T, std::vector<indri::lang::RawScorerNode*> > _nodeMap;
00041       std::vector<indri::server::QueryServer*> &_servers;      
00042 
00043     public:
00044       QueryTFWalker( std::vector<indri::server::QueryServer*> & servers ) : _servers(servers) {
00045       }
00046 
00047       ~QueryTFWalker( ) {
00048       }
00049 
00050       void after( indri::lang::RawScorerNode* scorer ) {
00051         // have to stem the term to get the counts right.
00052         lemur::api::TERMID_T id = 0;
00053         // take the first id returned
00054         for (int i = 0; (id == 0) && (i < _servers.size()); i++)
00055           id = _servers[i]->termID(scorer->queryText());
00056         _nodeMap[id].push_back(scorer);
00057       }
00058       void after( indri::lang::PlusNode *plus) {
00059         std::map< lemur::api::TERMID_T, std::vector<indri::lang::RawScorerNode*> >::iterator iter;
00060         for (iter = _nodeMap.begin(); iter != _nodeMap.end(); iter++) {
00061           std::vector<indri::lang::RawScorerNode *> & nodes = iter->second;
00062           for (int i = 0; i < nodes.size(); i++) {
00063             std::string smoothing = nodes[i]->getSmoothing();
00064             int qTF = nodes.size();
00065             std::stringstream smooth;
00066             smooth << smoothing << ",qtf:" << qTF;
00067             nodes[i]->setSmoothing( smooth.str() );
00068           }
00069         }
00070       }
00071       void after( indri::lang::WPlusNode *plus) {
00072         const std::vector< std::pair<double, ScoredExtentNode*> >& children = plus->getChildren();
00073         for( size_t i=0; i<children.size(); i++ ) {
00074           double weight = children[i].first;
00075           indri::lang::RawScorerNode * raw = dynamic_cast<indri::lang::RawScorerNode *>( children[i].second );
00076           std::string smoothing = raw->getSmoothing();
00077           std::stringstream smooth;
00078           smooth << smoothing << ",qtw:" << weight;
00079           raw->setSmoothing( smooth.str() );
00080         }
00081       }
00082     };
00083   }
00084 }
00085 
00086 #endif // INDRI_QUERYTFWALKER_HPP
00087 

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