示例#1
0
void Server::parseConfig(GetPot &config)
{
  // this variable is needed for setting up the partial loading part when the features
  // are loaded for the very first time at fire start up
  string partialLoadingString="empty";

  if(config.search(2,"-F","--filter"))
  {
    string unparsed = config.follow("empty",2,"-F","--filter");
    if (parseFilter(unparsed.c_str()))
    {
      retriever_.setFilterApply(true);
      DBG(10) << "Using filter " << unparsed << " for retrieval" << endl;
    }
    else
    {
      retriever_.setFilterApply(false);
      retriever_.clearFilter();
      DBG(10) << "Error in filter String " << unparsed << endl;
      DBG(10) << "Aborting filtering and using normal retrieval settings" << endl;
    }
  }

  if(config.search(2,"-q","--queryCombiner")) {
    retriever_.setQueryCombiner(config.follow("adding:POS=1.0:NEG=0.833",2,"-q","--queryCombiner"));
  }

  if(config.search("--reRanker")) {
    retriever_.setReranking(config.follow("cluster:CONS=100:RR=20:CLUSTERS=5","--reRanker"));
  } 
  if(config.search(2,"-U","--defdontload"))
  {
    partialLoadingString="default";
    retriever_.setPartialLoadingApply(true);
  }

  if(config.search(2,"-u","--dontload"))
  {
    string unparsed=config.follow("empty",2,"-u","--dontload");
    if(unparsed!="empty")
    {
      // the parsing is not possible here, because the amount of different features
      // is not known yet
      // but a sanity check is possible
      const char* str = unparsed.c_str();
      bool errformat = false;
      // note it is not checked if there are two or more : present in a row
      while(*str != '\0' && !errformat)
      {
        if(!isdigit(*str) && *str!=':')
        {
          errformat=true;
          DBG(10) << "Error in format string " << unparsed << " following -u/--dontload option" << endl;
          DBG(10) << "format string must start with a digit; aborting partial feature loading" << endl;
        }
        str++;
      }
      if(!errformat && retriever_.setPartialLoadingApply(true))
      {
        partialLoadingString=unparsed;
      }
      else
      {
        ERR << "-u/--dontload was used without -F/--filter option or there are illegal characters in the format string" << endl;
        ERR << "ignoring -u/--dontload option, loading all features" << endl;
      }
    }
    else
    {
      retriever_.setPartialLoadingApply(false);
      ERR << "Error after -u/--dontload option: No featureindexsequence given" << endl;
      //DBG(10) << "Aborting partial loading for filtered retrieval and loading all features" << endl;
    }
  }

  if(config.search(2,"-f","--filelist"))
  {
    string filelistname=config.follow("list.txt",2,"-f","--filelist");
    string result=retriever_.filelist(filelistname,partialLoadingString);
    if(result=="filelist FAILURE")
    {
      ERR << "Error in filelist. Please correct it and start again." << endl;
      exit(1);
    }
    DBG(10) << result << endl;
  }
  if(config.search(2,"-R","--relevancefile"))
  {
    relevanceFile_=config.follow("",2,"-R","--relevancefile");
  }

  retriever_.setScoring("linear");

  
  log_=LogFile(config.follow("",2,"-l","--logfile"));

  if(config.search(2,"-D","--defaultdists"))
  {
    for(uint i=0;i<retriever_.numberOfSuffices();++i)
    {
      retriever_.dist(i,distanceMaker_.getDefaultDistance(retriever_.featureType(i)));
      retriever_.weight(i,1.0);
      DBG(10) << "default dist[" << i << "]=" << retriever_.dist(i)->name() << endl;
    }
  }

  config.init_multiple_occurrence(); // can have multiple distances
  while(config.search(2,"-d","--dist"))
  {
    uint idx=config.follow(0,2,"-d","--dist");
    string distname=config.next("basedist");  // default distance measure (dummy!)
    retriever_.weight(idx,1.0); // set default weight for configured distances
    retriever_.dist(idx,distanceMaker_.makeDistance(distname));
    DBG(10) << "dist[" << idx << "]=" << retriever_.dist(idx)->name() << endl;
  }

  config.init_multiple_occurrence(); // can have multiple weights
  while(config.search(2,"-w","--weight"))
  {
    uint idx=config.follow(0,2,"-w","--weight");
    double w=config.next(1.0);
    retriever_.weight(idx,w);
    DBG(10) << "weight[" << idx << "]=" << w << endl;
  }

  retriever_.setScoring(config.follow("linear",2,"-C","--scoring"));
  
  if(config.search(2,"-I","--interactor"))
  {
    retriever_.setInteractor(config.follow("",2,"-I","--interactor"));
  }

  config.enable_loop(); // enable returning to the beginning of command line (was disabled for multiplicity before)
  if(config.search(2,"-S","--startAfterInit"))
  {
    startAfterInit_=config.follow("echo \"No program defined\"",2,"-S","--startAfterInit");
  }

  if(config.search(2,"-P","--proxy"))
  {
    proxyhost_=config.follow("localhost",2,"-P","--proxy");
    proxyport_=config.next(12963);
    DBG(10) << "Will notify proxy at " << proxyhost_ << ":"<<proxyport_ << " about my existence." << endl;
  }

  if(config.search(2,"-r","--results"))
  {
    retriever_.results(config.follow(9,2,"-r","--results"));
    DBG(10) << "results=" << retriever_.results() << endl;
  }

  if(config.search(2,"-l","--log"))
  {
    logfile_=config.follow("log.txt",2,"-l","--log");
    DBG(10) << "logfile="<< logfile_ << endl;
  }

  if(config.search(2,"-s","--server"))
  {
    port_=config.follow(12961,2,"-s","--server");
    DBG(10) << "port="<< port_ << endl;
  }

  if(config.search(2,"-B","--batch"))
  {
    batchfile_=config.follow("batch",2,"-B","--batch");
    DBG(10) << "batchfile="<< batchfile_ << endl;
  }
  
  if(config.search("--cache")) {
    retriever_.setCache(config.follow("cache.sqlite3.db","--cache"));
  }


  if(config.search(2,"-e","--expansion"))
  {
    retriever_.extensions(config.follow(2,2,"-e","--expansion"));
    DBG(10) << "expansions=" << config.follow(2,2,"-e","--expansion") << endl;
  }

  if(config.search(2,"-p","--password"))
  {
    password_=config.follow("",2,"-p","--password");
    DBG(10) << "password necessary for changing settings: " << password_ << endl;
  }

  if(config.search(2,"-t","--type2bin"))
  {
    t2bpath=config.follow("",2,"-t","--type2bin");
    DBG(10) << "type2bin-file has been reset to: " << t2bpath << endl;
  }
}