72 lines
1.7 KiB
C++
72 lines
1.7 KiB
C++
#include <fstream>
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
#include <args.hxx>
|
|
|
|
#include "common.hh"
|
|
|
|
|
|
namespace param {
|
|
using namespace ::args;
|
|
|
|
ArgumentParser parser {
|
|
"converter: feature code probability matrix -> feature code"
|
|
};
|
|
HelpFlag help {
|
|
parser, "help", "display this menu", {'h', "help"},
|
|
};
|
|
|
|
ValueFlag<std::string> smap {
|
|
parser, "path", "step map file path", {"smap"},
|
|
};
|
|
|
|
ValueFlag<uint32_t> fnum {
|
|
parser, "50", "number of feature kinds", {"fnum"}, 50
|
|
};
|
|
|
|
} // namespace param
|
|
|
|
|
|
static void Exec() {
|
|
const auto fnum = args::get(param::fnum);
|
|
Enforce(fnum > 0, "fc-num must be greater than 0");
|
|
|
|
std::ifstream smap_st {args::get(param::smap)};
|
|
Enforce(!!smap_st, "smap path is invalid");
|
|
const auto smap = ReadMatrix<uint32_t>(smap_st);
|
|
Enforce(smap.size() > 0 && smap[0].size() > 0, "empty smap");
|
|
|
|
const auto bn = smap[0].size();
|
|
for (auto& br : smap) {
|
|
Enforce(br.size() == bn, "all node should have the same number of branch");
|
|
}
|
|
|
|
size_t feat_p;
|
|
std::cin >> feat_p;
|
|
for (uint32_t feat, t = 0; std::cin >> feat; ++t) {
|
|
Enforce(feat < fnum, "feat overflow");
|
|
Enforce(fnum*(t+1) <= smap.size(), "smap row shortage");
|
|
|
|
const auto& row = smap[t*fnum + feat_p];
|
|
auto itr = std::find(row.begin(), row.end(), feat);
|
|
Enforce(itr != row.end(), "invalid step detected");
|
|
std::cout << std::distance(row.begin(), itr) << '\n';
|
|
feat_p = feat;
|
|
}
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
try {
|
|
param::parser.ParseCLI(argc, argv);
|
|
Exec();
|
|
return EXIT_SUCCESS;
|
|
} catch (const args::Help&) {
|
|
std::cout << param::parser << std::endl;
|
|
return EXIT_SUCCESS;
|
|
} catch (const std::exception& e) {
|
|
std::cerr << e.what() << std::endl;
|
|
return EXIT_FAILURE;
|
|
}
|
|
|