00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00039
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
00052 lemur::api::TERMID_T id = 0;
00053
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