// Runs the query, expanding it if necessary. Will print output as well if verbose is on. void _runQuery( std::stringstream& output, const std::string& query, const std::string &queryType, const std::vector<std::string> &workingSet, std::vector<std::string> relFBDocs ) { try { if( _printQuery ) output << "# query: " << query << std::endl; std::vector<lemur::api::DOCID_T> docids;; if (workingSet.size() > 0) docids = _environment.documentIDsFromMetadata("docno", workingSet); if (relFBDocs.size() == 0) { if( _printSnippets ) { if (workingSet.size() > 0) _annotation = _environment.runAnnotatedQuery( query, docids, _initialRequested, queryType ); else _annotation = _environment.runAnnotatedQuery( query, _initialRequested ); _results = _annotation->getResults(); } else { if (workingSet.size() > 0) _results = _environment.runQuery( query, docids, _initialRequested, queryType ); else _results = _environment.runQuery( query, _initialRequested, queryType ); } } if( _expander ) { std::vector<indri::api::ScoredExtentResult> fbDocs; if (relFBDocs.size() > 0) { docids = _environment.documentIDsFromMetadata("docno", relFBDocs); for (size_t i = 0; i < docids.size(); i++) { indri::api::ScoredExtentResult r(0.0, docids[i]); fbDocs.push_back(r); } } std::string expandedQuery; if (relFBDocs.size() != 0) expandedQuery = _expander->expand( query, fbDocs ); else expandedQuery = _expander->expand( query, _results ); if( _printQuery ) output << "# expanded: " << expandedQuery << std::endl; if (workingSet.size() > 0) { docids = _environment.documentIDsFromMetadata("docno", workingSet); _results = _environment.runQuery( expandedQuery, docids, _requested, queryType ); } else { _results = _environment.runQuery( expandedQuery, _requested, queryType ); } } } catch( lemur::api::Exception& e ) { _results.clear(); LEMUR_RETHROW(e, "QueryThread::_runQuery Exception"); } }
SEXP generateResults(string _qno, string _query, int _documentLimit, bool stats) { resultsData = resultsData_nullCopy; documentIDs.clear(); scores.clear(); extDocIDs.clear(); terms.clear(); _gramTable.clear(); results.clear(); qno = _qno; query = _query; documentLimit = _documentLimit; qa = environment.runAnnotatedQuery(query, _documentLimit); results = qa->getResults(); _logtoposterior(results); // Extract Documents for (size_t i = 0; i < results.size(); i++){ documentIDs.push_back(results[i].document); scores.push_back(results[i].score); } extDocIDs = environment.documentMetadata(documentIDs, "docno"); if(stats){ updateQueryDetails(environment, resultsData, query); countGrams(); buildStats(); } return Rcpp::wrap(true); }
SEXP runQuery(string _qno, string _query, int _documentLimit, string _runid="default"){ indri::api::QueryAnnotation* qa; qa = environment.runAnnotatedQuery(_query, _documentLimit); std::vector<indri::api::ScoredExtentResult> results = qa->getResults(); //_logtoposterior(results); // Extract Documents std::vector<lemur::api::DOCID_T> documentIDs; std::vector<double> scores; for (size_t i = 0; i < results.size(); i++){ documentIDs.push_back(results[i].document); scores.push_back(results[i].score); } vector<string> res_qno; vector<string> res_q0; vector<string> res_runid; int documentLimit = _documentLimit; for(int i=0; i < documentLimit; i++){ res_qno.push_back(qno); res_q0.push_back("Q0"); res_runid.push_back(_runid); } std::vector<string> extDocIDs = environment.documentMetadata(documentIDs, "docno"); return Rcpp::DataFrame::create( Named("topic")= _qno, Named("q0")= res_q0, Named("docID")= wrap(extDocIDs), Named("rank")= seq( 1, documentLimit ), Named("score")= wrap(scores), Named("runID")= res_runid); }
// Runs the query, expanding it if necessary. Will print output as well if verbose is on. void _runQuery( std::stringstream& output, const std::string& query, const std::string &queryType ) { try { if( _printQuery ) output << "# query: " << query << std::endl; if( _printSnippets ) { _annotation = _environment.runAnnotatedQuery( query, _initialRequested ); _results = _annotation->getResults(); } else { _results = _environment.runQuery( query, _initialRequested, queryType ); } if( _expander ) { std::string expandedQuery = _expander->expand( query, _results ); if( _printQuery ) output << "# expanded: " << expandedQuery << std::endl; _results = _environment.runQuery( expandedQuery, _requested, queryType ); } } catch( lemur::api::Exception& e ) { _results.clear(); LEMUR_RETHROW(e, "QueryThread::_runQuery Exception"); } }