Skip to content
Snippets Groups Projects
Select Git revision
  • e6540cb0d4e69a41590dc8226e4f058459ea6fe7
  • main default protected
2 results

experiment1.py

Blame
  • macaon_decode.cpp 4.24 KiB
    /// @file macaon_decode.cpp
    /// @author Franck Dary
    /// @version 1.0
    /// @date 2018-08-07
    
    #include <cstdio>
    #include <cstdlib>
    #include <boost/program_options.hpp>
    #include "BD.hpp"
    #include "Config.hpp"
    #include "TransitionMachine.hpp"
    #include "Decoder.hpp"
    
    namespace po = boost::program_options;
    
    /// @brief Get the list of mandatory and optional program arguments.
    ///
    /// @return The lists.
    po::options_description getOptionsDescription()
    {
      po::options_description desc("Command-Line Arguments ");
    
      po::options_description req("Required");
      req.add_options()
        ("expName", po::value<std::string>()->required(),
          "Name of this experiment")
        ("tm", po::value<std::string>()->required(),
          "File describing the Tape Machine to use")
        ("bd", po::value<std::string>()->required(),
          "BD file that describes the multi-tapes buffer")
        ("mcd", po::value<std::string>()->required(),
          "MCD file that describes the input")
        ("input,I", po::value<std::string>()->required(),
          "Input file formated according to the mcd");
    
      po::options_description opt("Optional");
      opt.add_options()
        ("help,h", "Produce this help message")
        ("debug,d", "Print infos on stderr")
        ("printEntropy", "Print entropy for each sequence")
        ("sequenceDelimiterTape", po::value<std::string>()->default_value("EOS"),
          "The name of the buffer's tape that contains the delimiter token for a sequence")
        ("sequenceDelimiter", po::value<std::string>()->default_value("1"),
          "The value of the token that act as a delimiter for sequences")
    
        ("lang", po::value<std::string>()->default_value("fr"),
          "Language you are working with");
    
    
      desc.add(req).add(opt);
    
      return desc;
    }
    
    /// @brief Store the program arguments inside a variables_map
    ///
    /// @param od The description of all the possible options.
    /// @param argc The number of arguments given to this program.
    /// @param argv The values of arguments given to this program.
    ///
    /// @return The variables map
    po::variables_map checkOptions(po::options_description & od, int argc, char ** argv)
    {
      po::variables_map vm;
    
      try {po::store(po::parse_command_line(argc, argv, od), vm);}
      catch(std::exception& e)
      {
        std::cerr << "Error: " << e.what() << "\n";
        od.print(std::cerr);
        exit(1);
      }
    
      if (vm.count("help"))
      {
        std::cout << od << "\n";
        exit(0);
      }
    
      try {po::notify(vm);}
      catch(std::exception& e)
      {
        std::cerr << "Error: " << e.what() << "\n";
        od.print(std::cerr);
        exit(1);
      }
    
      return vm;
    }
    
    /// @brief Uses a pre-trained TransitionMachine to predict and add information to a structured input file.
    ///
    /// @param argc The number of arguments given to this program.
    /// @param argv[] Array of arguments given to this program.
    ///
    /// @return 0 if there was no crash.
    int main(int argc, char * argv[])
    {
      auto od = getOptionsDescription();
    
      po::variables_map vm = checkOptions(od, argc, argv);
    
      ProgramParameters::expName = vm["expName"].as<std::string>();
      ProgramParameters::tmName = vm["tm"].as<std::string>();
      ProgramParameters::bdName = vm["bd"].as<std::string>();
      ProgramParameters::input = vm["input"].as<std::string>();
      ProgramParameters::mcdName = vm["mcd"].as<std::string>();
      ProgramParameters::debug = vm.count("debug") == 0 ? false : true;
      ProgramParameters::printEntropy = vm.count("printEntropy") == 0 ? false : true;
      ProgramParameters::lang = vm["lang"].as<std::string>();
      ProgramParameters::sequenceDelimiterTape = vm["sequenceDelimiterTape"].as<std::string>();
      ProgramParameters::sequenceDelimiter = vm["sequenceDelimiter"].as<std::string>();
    
      const char * MACAON_DIR = std::getenv("MACAON_DIR");
      std::string slash = "/";
      ProgramParameters::expPath = MACAON_DIR + slash + ProgramParameters::lang + slash + "bin/" + ProgramParameters::expName + slash;
    
      ProgramParameters::tmFilename = ProgramParameters::expPath + ProgramParameters::tmName;
      ProgramParameters::bdFilename = ProgramParameters::expPath + ProgramParameters::bdName;
      ProgramParameters::mcdFilename = ProgramParameters::mcdName;
    
      TransitionMachine tapeMachine(false);
    
      BD bd(ProgramParameters::bdFilename, ProgramParameters::mcdFilename);
      Config config(bd);
      config.readInput(ProgramParameters::input);
    
      Decoder decoder(tapeMachine, config);
    
      decoder.decode();
    
      return 0;
    }