From 4ddd15f34e0c2e5c7e456f0d17a2dd8cdf0c6b91 Mon Sep 17 00:00:00 2001
From: falsycat <me@falsy.cat>
Date: Mon, 10 Oct 2022 22:39:58 +0900
Subject: [PATCH] implement a converter from aprob to bmap

---
 conv/CMakeLists.txt |  6 +++++
 conv/aprob_bmap.cc  | 55 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)
 create mode 100644 conv/aprob_bmap.cc

diff --git a/conv/CMakeLists.txt b/conv/CMakeLists.txt
index 9168c6d..333af1f 100644
--- a/conv/CMakeLists.txt
+++ b/conv/CMakeLists.txt
@@ -1,3 +1,4 @@
+# ---- main procedural
 add_executable(dcode_feat common.hh dcode_feat.cc)
 target_link_libraries(dcode_feat PRIVATE args)
 
@@ -18,3 +19,8 @@ target_link_libraries(fprob_feat PRIVATE args)
 
 add_executable(feat_dcode common.hh feat_dcode.cc)
 target_link_libraries(feat_dcode PRIVATE args)
+
+
+# ---- procedural of preprocessing
+add_executable(aprob_bmap common.hh aprob_bmap.cc)
+target_link_libraries(aprob_bmap PRIVATE args)
diff --git a/conv/aprob_bmap.cc b/conv/aprob_bmap.cc
new file mode 100644
index 0000000..489f61f
--- /dev/null
+++ b/conv/aprob_bmap.cc
@@ -0,0 +1,55 @@
+#include <fstream>
+#include <iostream>
+#include <string>
+
+#include <args.hxx>
+
+#include "common.hh"
+
+
+namespace param {
+using namespace ::args;
+
+ArgumentParser parser {
+  "converter: aprob -> bmap"
+};
+HelpFlag help {
+  parser, "help", "display this menu", {'h', "help"},
+};
+
+ValueFlag<double> min {
+  parser, "0.2", "minimum alter-probability to select", {"min"}, 0.4,
+};
+ValueFlag<double> max {
+  parser, "0.6", "maximum alter-probability to select", {"max"}, 0.6,
+};
+
+}  // namespace param
+
+
+static void Exec() {
+  const auto aprob = ReadMatrix<double>(std::cin);
+
+  for (auto& probs : aprob) {
+    for (size_t i = 0; i < probs.size(); ++i) {
+      if (args::get(param::min) <= probs[i] && probs[i] <= args::get(param::max)) {
+        std::cout << i << ' ';
+      }
+    }
+    std::cout << '\n';
+  }
+}
+
+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;
+}
+