예제 #1
0
static void
assert_dot_notation_eval_equals(const gchar *input_json, const gchar *subscript, const gchar *expected_json)
{
  struct json_object *input, *expected, *sub;

  input = compile_json(input_json);
  expected = compile_json(expected_json);

  sub = json_extract(input, subscript);
  assert_json_equals(sub, expected, subscript);
  json_object_put(expected);
  json_object_put(input);
}
예제 #2
0
static void
assert_dot_notation_eval_fails(const gchar *input_json, const gchar *subscript)
{
  struct json_object *input, *sub;

  input = compile_json(input_json);
  sub = json_extract(input, subscript);
  assert_null(sub, "extracted JSON is not NULL as expected, json=%s, subscript=%s", input_json, subscript);
  json_object_put(input);
}
예제 #3
0
int main(int argc, char** argv) {
  std::vector<std::string> input_files;
  std::string output_file;

  boost::program_options::options_description description(
      "keyvi compiler options:");

  description.add_options()("help,h", "Display this help message")(
      "version,v", "Display the version number");

  description.add_options()("input-file,i",
                            boost::program_options::value<std::vector<std::string>>(),
                            "input file");
  description.add_options()("output-file,o",
                            boost::program_options::value<std::string>(),
                            "output file");
  description.add_options()("memory-limit,m",
                            boost::program_options::value<size_t>(),
                            "amount of main memory to use");
  description.add_options()(
      "dictionary-type,d",
      boost::program_options::value<std::string>()->default_value("integer"),
      "type of dictionary (integer (default), string, key-only, json)");
  description.add_options()("partition-size,p",
                            boost::program_options::value<size_t>(),
                            "create partitions with a maximum size");
  description.add_options()("compact,c", "Compact Mode");

  // Declare which options are positional
  boost::program_options::positional_options_description p;
  p.add("input-file", -1);

  boost::program_options::variables_map vm;
  boost::program_options::store(
      boost::program_options::command_line_parser(argc, argv).options(
          description).run(),
      vm);
  boost::program_options::notify(vm);

  // parse positional options
  boost::program_options::store(
      boost::program_options::command_line_parser(argc, argv).options(
          description).positional(p).run(),
      vm);
  boost::program_options::notify(vm);
  if (vm.count("help")) {
    std::cout << description;
    return 0;
  }

  size_t memory_limit = 1073741824;
  if (vm.count("memory-limit")) {
    memory_limit = vm["memory-limit"].as<size_t>();
  }

  bool compact = false;
  if (vm.count("compact")) {
      compact = true;
  }

  size_t partition_size = 0;
  if (vm.count("partition-size")) {
    partition_size = vm["partition-size"].as<size_t>();
  }

  if (vm.count("input-file") && vm.count("output-file")) {
    input_files = vm["input-file"].as<std::vector<std::string>>();
    output_file = vm["output-file"].as<std::string>();

    std::string dictionary_type = vm["dictionary-type"].as<std::string>();
    if (dictionary_type == "integer") {
      if (compact){
        compile_integer<uint16_t>(input_files, output_file, memory_limit, partition_size);
      } else {
        compile_integer(input_files, output_file, memory_limit, partition_size);
      }
    } else if (dictionary_type == "string") {
      if (compact){
        compile_strings<uint16_t>(input_files, output_file, memory_limit, partition_size);
      } else {
        compile_strings(input_files, output_file, memory_limit, partition_size);
      }
    } else if (dictionary_type == "key-only") {
      if (compact){
        compile_key_only<uint16_t>(input_files, output_file, memory_limit, partition_size);
      } else {
        compile_key_only(input_files, output_file, memory_limit, partition_size);
      }
    } else if (dictionary_type == "json") {
      if (compact){
        compile_json<uint16_t>(input_files, output_file, memory_limit, partition_size);
      } else {
        compile_json(input_files, output_file, memory_limit, partition_size);
      }
    } else {
      std::cout << "ERROR: unknown dictionary type." << std::endl << std::endl;
      std::cout << description;
      return 1;
    }
  } else {
    std::cout << "ERROR: arguments wrong or missing." << std::endl << std::endl;
    std::cout << description;
    return 1;
  }

  return 0;
}