Bringing tree up to date.
[galago.git] / cpp / galago / appsrc / galago.cpp
blobc8b601fc533367ea699bb73a15b3e409be5a2aa7
2 //
3 // galago
4 //
5 // 5 January 2007 -- tds
6 //
7 // BSD License (http://galagosearch.org/license)
8 //
10 #include "indri/ScoredExtentResult.hpp"
11 #include "indri/Parameters.hpp"
12 #include "lemur/Exception.hpp"
13 #include "Retrieval.hpp"
14 #include <iostream>
15 #include <stdlib.h>
16 #include <fstream>
19 // usage
22 static void usage() {
23 std::cerr << "galago --query.text=hi --query.number=1 --count=10 --index=myindex" << std::endl;
24 exit(-1);
28 // require
31 static void require( indri::api::Parameters param, const std::string& p ) {
32 if( !param.exists(p) )
33 usage();
37 // command_line
40 static void command_line( Retrieval& retrieval, indri::api::Parameters& parameters ) {
41 // record results requested
42 int requested = parameters.get( "count", 1000 );
44 // for each query, run it, get the results, look up the docnos, print in TREC format
45 indri::api::Parameters queries = parameters["query"];
47 for( int i=0; i<queries.size(); i++ ) {
48 std::string queryText = queries[i]["text"];
49 std::string queryName = queries[i]["number"];
50 int threshold = (int)(INT64)queries[i].get( "threshold", -1 );
52 std::vector<indri::api::ScoredExtentResult> results;
53 std::vector<QueryTerm> terms = Query::parse( queryText );
54 results = retrieval.runQuery( terms, requested, threshold );
56 for( int i=0; i<results.size(); i++ ) {
57 std::string document = retrieval.getDocument(results[i].document);
58 int score = (int)results[i].score;
59 int rank = i+1;
61 printf( "%s Q0 %s %d %d galago\n", queryName.c_str(), document.c_str(), rank, score );
67 // main
70 int main( int argc, char** argv ) {
71 try {
72 // read in parameters
73 indri::api::Parameters::instance().loadCommandLine( argc, argv );
74 indri::api::Parameters& parameters = indri::api::Parameters::instance();
76 // open index
77 std::string indexPath = parameters["index"];
78 Retrieval* retrieval = Retrieval::open( indexPath );
80 command_line( *retrieval, parameters );
81 } catch( lemur::api::Exception& e ) {
82 LEMUR_ABORT(e);
85 return 0;