Esempio n. 1
0
void printDecoderConfigFile()
{
  string decoder_config_file = Prefix + ".Decoder.config" ;
  cerr << "writing decoder configuration file to " <<  decoder_config_file.c_str() <<'\n';
  ofstream decoder(decoder_config_file.c_str());
  if(!decoder){
    cerr << "\nCannot write to " << decoder_config_file <<'\n';
    exit(1);
  }
  decoder << "# Template for Configuration File for the Rewrite Decoder\n# Syntax:\n" 
	  << "#         <Variable> = <value>\n#         '#' is the comment character\n"
	  << "#================================================================\n"
	  << "#================================================================\n"
	  << "# LANGUAGE MODEL FILE\n# The full path and file name of the language model file:\n";
  decoder << "LanguageModelFile =\n";
  decoder << "#================================================================\n"
	  << "#================================================================\n"
	  << "# TRANSLATION MODEL FILES\n# The directory where the translation model tables as created\n"
	  << "# by Giza are located:\n#\n"
	  << "# Notes: - All translation model \"source\" files are assumed to be in\n"
	  << "#          TM_RawDataDir, the binaries will be put in TM_BinDataDir\n"
	  << "#\n#        - Attention: RELATIVE PATH NAMES DO NOT WORK!!!\n"
	  << "#\n#        - Absolute paths (file name starts with /) will override\n"
	  << "#          the default directory.\n\n";
  // strip file prefix info and leave only the path name in Prefix
  string path = Prefix.substr(0, Prefix.find_last_of("/")+1);
  if( path=="" )
    path=".";
  decoder << "TM_RawDataDir = " << path << '\n';
  decoder << "TM_BinDataDir = " << path << '\n' << '\n';
  decoder << "# file names of the TM tables\n# Notes:\n"
	  << "# 1. TTable and InversTTable are expected to use word IDs not\n"
	  << "#    strings (Giza produces both, whereby the *.actual.* files\n"
	  << "#    use strings and are THE WRONG CHOICE.\n"
	  << "# 2. FZeroWords, on the other hand, is a simple list of strings\n"
	  << "#    with one word per line. This file is typically edited\n"
	  << "#    manually. Hoeever, this one listed here is generated by GIZA\n\n";
  
  int lastmodel;
  if (Model5_Iterations>0)
    lastmodel = 5 ;
  else if (Model4_Iterations>0)
    lastmodel = 4 ;
  else if (Model3_Iterations>0)
    lastmodel = 3 ;
  else if (Model2_Iterations>0)
    lastmodel = 2 ;
  else lastmodel = 1 ;
  string lastModelName = str2Num(lastmodel);
  string p=Prefix + ".t" + /*lastModelName*/"3" +".final";
  decoder << "TTable = " << stripPath(p.c_str()) << '\n';
  p = Prefix + ".ti.final" ;
  decoder << "InverseTTable = " << stripPath(p.c_str()) << '\n';
  p=Prefix + ".n" + /*lastModelName*/"3" + ".final";
  decoder << "NTable = " << stripPath(p.c_str())  << '\n';
  p=Prefix + ".d" + /*lastModelName*/"3" + ".final";
  decoder << "D3Table = " << stripPath(p.c_str())  << '\n';
  p=Prefix + ".D4.final";
  decoder << "D4Table = " << stripPath(p.c_str()) << '\n';
  p=Prefix + ".p0_"+ /*lastModelName*/"3" + ".final";
  decoder << "PZero = " << stripPath(p.c_str()) << '\n';
  decoder << "Source.vcb = " << SourceVocabFilename << '\n';
  decoder << "Target.vcb = " << TargetVocabFilename << '\n';
  //  decoder << "Source.classes = " << SourceVocabFilename + ".classes" << '\n';
  //  decoder << "Target.classes = " << TargetVocabFilename + ".classes" <<'\n';
  decoder << "Source.classes = " << SourceVocabFilename+".classes" << '\n';
  decoder << "Target.classes = " << TargetVocabFilename + ".classes" <<'\n';
  p=Prefix + ".fe0_"+ /*lastModelName*/"3" + ".final";
  decoder << "FZeroWords       = " <<stripPath(p.c_str()) << '\n' ;

  /*  decoder << "# Translation Parameters\n"
      << "# Note: TranslationModel and LanguageModelMode must have NUMBERS as\n"
      << "# values, not words\n"
      << "# CORRECT: LanguageModelMode = 2\n"
      << "# WRONG:   LanguageModelMode = bigrams # WRONG, WRONG, WRONG!!!\n";
      decoder << "TMWeight          = 0.6 # weight of TM for calculating alignment probability\n";
      decoder << "TranslationModel  = "<<lastmodel<<"   # which model to use (3 or 4)\n";
      decoder << "LanguageModelMode = 2   # (2 (bigrams) or 3 (trigrams)\n\n";
      decoder << "# Output Options\n"
      << "TellWhatYouAreDoing = TRUE # print diagnostic messages to stderr\n"
      << "PrintOriginal       = TRUE # repeat original sentence in the output\n"
      << "TopTranslations     = 3    # number of n best translations to be returned\n"
      << "PrintProbabilities  = TRUE # give the probabilities for the translations\n\n";
      
      decoder << "# LOGGING OPTIONS\n"
      << "LogFile = - # empty means: no log, dash means: STDOUT\n"
      << "LogLM = true # log language model lookups\n"
      << "LogTM = true # log translation model lookups\n";
      */
}
Esempio n. 2
0
void
TUIGame::handleTestSuite(const std::string& cmd) {
    std::ifstream fr;
    int lineNo = -1;
    try {
        size_t idx = cmd.find_first_of(' ');
        if (idx == cmd.npos)
            return;
        std::string filename(cmd.substr(0, idx));
        std::string timeStr(cmd.substr(idx + 1));
        int timeLimit;
        if (!str2Num(timeStr, timeLimit)) {
            std::cout << "Error parsing number: " << timeStr << std::endl;
            return;
        }
//        std::cout << "file:" << filename << " time:" << timeStr << " (" << timeLimit << ")" << std::endl;
        fr.open(filename.c_str());
        Player& pl = whitePlayer->isHumanPlayer() ? *blackPlayer : *whitePlayer;
        if (pl.isHumanPlayer()) {
            std::cout << "No computer player available" << std::endl;
            return;
        }
        ComputerPlayer& cp = static_cast<ComputerPlayer&>(pl);
        int numRight = 0;
        int numTotal = 0;
        std::string line;
        lineNo = 0;
        while (getline(fr, line).good()) {
            lineNo++;
            if (startsWith(line, "#") || (line.length() == 0))
                continue;
            size_t idx1 = line.find(" bm ");
            if (idx1 == line.npos) {
                std::cout << "Parse error, line:" << lineNo << std::endl;
                return;
            }
            std::string fen = line.substr(0, idx1);
            size_t idx2 = line.find(";", idx1);
            if (idx2 == line.npos) {
                std::cout << "Parse error, line:" << lineNo << std::endl;
                return;
            }
            std::string bm = line.substr(idx1+4, idx2 - (idx1+4));
//            std::cout << "Line " << std::setw(3) << lineNo << ": fen:" << fen << " bm:" << bm << std::endl;
            Position testPos = TextIO::readFEN(fen);
            cp.clearTT();
            std::pair<Move, std::string> ret = cp.searchPosition(testPos, timeLimit);
            Move sm = ret.first;
            std::string PV = ret.second;
            Move m(sm);
            std::vector<std::string> answers;
            splitString(bm, answers);
            bool correct = false;
            for (size_t i = 0; i < answers.size(); i++) {
                const std::string& a = answers[i];
                Move am(TextIO::stringToMove(testPos, a));
                if (am.isEmpty())
                    throw ChessParseError("Invalid move " + a);
                if (am.equals(m)) {
                    correct = true;
                    break;
                }
            }
            if (correct)
                numRight++;
            numTotal++;
            std::cout << std::setw(3) << lineNo
                      << ' ' << std::setw(6) << TextIO::moveToString(testPos, sm, false)
                      << ' ' << std::setw(6) << sm.score()
                      << ' ' << (correct ? 1 : 0)
                      << ' ' << std::setw(3) << numRight
                      << '/' << std::setw(3) << numTotal
                      << ' ' << bm << " : " << PV << std::endl;
        }
        fr.close();
    } catch (const std::ifstream::failure& ex) {
        std::cout << "IO error: " << ex.what() << std::endl;
    } catch (const ChessParseError& cpe) {
        std::cout << "Parse error, line " << lineNo << ": " << cpe.what() << std::endl;
    }
}