<commit_before>#pragma once

#include "filesystem.hpp"
#include "logger.hpp"
#include "types.hpp"
#include <fstream>
#include <iostream>
#include <json/json.hpp>
#include <string>

namespace krbn {
class manipulator_environment final {
public:
  class frontmost_application final {
  public:
    frontmost_application(void) {
    }

    frontmost_application(const std::string& bundle_identifier,
                          const std::string& file_path) : bundle_identifier_(bundle_identifier),
                                                          file_path_(file_path) {
    }

    nlohmann::json to_json(void) const {<commit_msg>add frontmost_application(const nlohmann::json& json)<commit_after>#pragma once

#include "filesystem.hpp"
#include "logger.hpp"
#include "types.hpp"
#include <fstream>
#include <iostream>
#include <json/json.hpp>
#include <string>

namespace krbn {
class manipulator_environment final {
public:
  class frontmost_application final {
  public:
    frontmost_application(void) {
    }

    frontmost_application(const std::string& bundle_identifier,
                          const std::string& file_path) : bundle_identifier_(bundle_identifier),
                                                          file_path_(file_path) {
    }

    frontmost_application(const nlohmann::json& json) {
      if (json.is_object()) {
        for (auto it = std::begin(json); it != std::end(json); std::advance(it, 1)) {
          // it.key() is always std::string.
          const auto& key = it.key();
          const auto& value = it.value();

          if (key == "bundle_identifier") {
            if (value.is_string()) {
              bundle_identifier_ = value.get<std::string>();
            } else {
              logger::get_logger().error("bundle_identifier should be string: {0}", json.dump());
            }
          } else if (key == "file_path") {
            if (value.is_string()) {
              file_path_ = value.get<std::string>();
            } else {
              logger::get_logger().error("file_path should be string: {0}", json.dump());
            }
          } else {
            logger::get_logger().error("json error: Unknown key: {0} in {1}", key, json.dump());
          }
        }
      } else {
        logger::get_logger().error("frontmost_application should be object: {0}", json.dump());
      }
    }

    nlohmann::json to_json(void) const {
{'fraction_non_alphanumeric': 0.12931392931392932, 'fraction_numerical': 0.002494802494802495, 'mean_word_length': 2.3744740532959328, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '394999', 'n_tokens_mistral': 691, 'n_tokens_neox': 679, 'n_words': 150}