Esempio n. 1
0
  // 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");
    }
  }
Esempio n. 2
0
double indri::query::ConceptSelectorFuns::findConceptScorePrf(string conceptSty, string conceptStr, string qId, std::vector<lemur::api::DOCID_T> topDocIds,
        indri::api::QueryEnvironment & env,
        indri::query::QueryReformulator * queryReformulator,
        vector<string> resourceNames_)
{
    // runQuery the new query text on these workset of top-ranked documents
    vector<pair<string, vector<pair<string, string> > > > candConcepts_;
    vector<pair<string, string> > tmp = {make_pair(conceptSty, conceptStr)};
    candConcepts_ = {make_pair(qId, tmp )};
    oneResourceConceptsParams.oneResourceConcepts = candConcepts_;

    vector<pair<string, string> > queriesText = queryReformulator->testOneConceptAddition2OneQuery(conceptSty, conceptStr, qId, resourceNames_);

    std::vector< indri::api::ScoredExtentResult > results_;
    if(wsuIr::expander::Utility::runQuery_results_isExist(queriesText, topDocIds))
    {
        results_ = wsuIr::expander::Utility::runQuery_results_get(queriesText, topDocIds);
    }
    else
    {
        results_ = env.runQuery(queriesText.front().second, topDocIds, topDocIds.size());
        wsuIr::expander::Utility::runQuery_results_store(queriesText, topDocIds, results_);
    }

    if(results_.size() != topDocIds.size())
        throw runtime_error("RunQUery.cpp: some of top-ranked documents are not scored");

    double conceptScore = 0;
    for(auto r: results_)
    {
        conceptScore += r.score;
    }

    return conceptScore;
}
Esempio n. 3
0
  // 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");
    }
  }