Revision dee505b8236452abc0055253f2c44df7152c7ef0 authored by hieuhoang1972 on 16 November 2007, 00:09:21 UTC, committed by hieuhoang1972 on 16 November 2007, 00:09:21 UTC
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@1513 1f5c12ca-751b-0410-a591-d2e778427230
1 parent e2d8dfb
Raw File
queryLexicalTable.cpp
#include <iostream>
#include <string>

#include "Phrase.h"
#include "FactorCollection.h"
#include "Timer.h"
#include "InputFileStream.h"
#include "LexicalReorderingTable.h"

Timer timer;

void printHelp(){
  std::cerr << "Usage:\n"
	"options: \n"
	"\t-table file   -- input table file name\n"
	"\t-f     string -- f query phrase\n"
	"\t-e     string -- e query phrase\n"
	"\t-c     string -- context query phrase\n"
	"\n"; 
}

std::ostream& operator<<(std::ostream& o, Score s){
  for(int i = 0; i < s.size(); ++i){
	o << s[i] << "  ";
  }
  //o << std::endln;
  return o;
};

int main(int argc, char** argv){
  std::cerr << "queryLexicalTable v0.2 by Konrad Rawlik\n";
  std::string inFilePath;
  std::string outFilePath("out");
  bool cache = false;
  std::string query_e, query_f, query_c;
  bool use_context = false;
  bool use_e       = false;
  if(1 >= argc){
	printHelp();
	return 1;
  }
  for(int i = 1; i < argc; ++i){
    std::string arg(argv[i]);
    if("-table" == arg && i+1 < argc){
	  //std::cerr << "Table is " << argv[i];
      ++i;
      inFilePath = argv[i];
    } else if("-f" == arg && i+1 < argc){
	  ++i;
	  //std::cerr << "F is " << argv[i];
	  query_f = argv[i];
    } else if("-e" == arg && i+1 < argc){
	  ++i;
	  query_e = argv[i];
	  use_e = true;
    } else if("-c" == arg){
	  if(i+1 < argc && '-' != argv[i+1][0]){
		++i;
		query_c = argv[i];
		use_context = true;
	  } else {
		use_context = false;
	  }
	} else if("-cache" == arg){
	  ++i;
	  cache = true; 
    } else {
      //somethings wrong... print help
	  printHelp();
      return 1;
    }
  }

  FactorList f_mask;
  FactorList e_mask;
  FactorList c_mask;
  f_mask.push_back(0);
  if(use_e){
	e_mask.push_back(0);
  }
  if(use_context){
	c_mask.push_back(0);
  }
  Phrase e(Output),f(Input),c(Output);
  e.CreateFromString(e_mask, query_e, "|");
  f.CreateFromString(f_mask, query_f, "|");
  c.CreateFromString(c_mask,  query_c,"|");
  LexicalReorderingTable* table;
  if(FileExists(inFilePath+".binlexr.idx")){
	std::cerr << "Loading binary table...\n";
	table = new LexicalReorderingTableTree(inFilePath, f_mask, e_mask, c_mask);
  } else {
	std::cerr << "Loading ordinary table...\n";
	table = new LexicalReorderingTableMemory(inFilePath, f_mask, e_mask, c_mask);
  }
  //table->DbgDump(&std::cerr);
  if(cache){
	std::cerr << "Caching for f\n";
	table->InitializeForInputPhrase(f);
  }
  std::cerr << "Querying: f='" << f.GetStringRep(f_mask) << "' e='" << e.GetStringRep(e_mask) << "' c='" << c.GetStringRep(c_mask) << "'\n";
  std::cerr << table->GetScore(f,e,c) << "\n";
  //table->DbgDump(&std::cerr);
  delete table;
  return 0;
}


back to top