std::string DebugString()

in research/carls/base/input_context_helper.cc [616:703]


std::string DebugString(const InputContext& input_context) {
  std::vector<std::string> lines;
  for (const auto& pair : input_context.feature()) {
    const auto& feature_name = pair.first;
    const auto& feature_value = pair.second;
    lines.push_back("feature {");
    lines.push_back(absl::StrCat("  key: \"", feature_name, "\""));
    if (feature_value.feature_value().empty()) {
      continue;
    }
    std::vector<std::string> values;
    std::vector<std::string> weights;
    std::vector<std::string> debug_infos;
    values.reserve(feature_value.feature_value().size());
    weights.reserve(feature_value.feature_value().size());
    std::string feature_prefix;
    for (const auto& value : feature_value.feature_value()) {
      std::vector<std::string> per_feature_weights;
      if (value.feature_case() == FeatureValue::kBytesFeature) {
        if (feature_prefix.empty()) {
          feature_prefix = "bytes_";
        }
        values.push_back(value.bytes_feature().value());
        for (const auto weight : value.bytes_feature().weight()) {
          per_feature_weights.push_back(absl::StrCat(weight));
        }
        if (!value.bytes_feature().debug_info().empty()) {
          debug_infos.push_back(value.bytes_feature().debug_info());
        }
      } else if (value.feature_case() == FeatureValue::kFloatFeature) {
        if (feature_prefix.empty()) {
          feature_prefix = "float_";
        }
        values.push_back(absl::StrCat(value.float_feature().value()));
        for (const auto weight : value.float_feature().weight()) {
          per_feature_weights.push_back(absl::StrCat(weight));
        }
        if (!value.float_feature().debug_info().empty()) {
          debug_infos.push_back(value.float_feature().debug_info());
        }
      } else if (value.feature_case() == FeatureValue::kInt64Feature) {
        if (feature_prefix.empty()) {
          feature_prefix = "int64_";
        }
        values.push_back(absl::StrCat(value.int64_feature().value()));
        for (const auto weight : value.int64_feature().weight()) {
          per_feature_weights.push_back(absl::StrCat(weight));
        }
        if (!value.int64_feature().debug_info().empty()) {
          debug_infos.push_back(value.int64_feature().debug_info());
        }
      } else if (value.feature_case() == FeatureValue::kUint64Feature) {
        if (feature_prefix.empty()) {
          feature_prefix = "uint64_";
        }
        values.push_back(absl::StrCat(value.uint64_feature().value()));
        for (const auto weight : value.uint64_feature().weight()) {
          per_feature_weights.push_back(absl::StrCat(weight));
        }
        if (!value.uint64_feature().debug_info().empty()) {
          debug_infos.push_back(value.uint64_feature().debug_info());
        }
      } else {  // FeatureValue::FEATURE_NOT_SET
        values.push_back("FEATURE_NOT_SET");
      }
      if (!per_feature_weights.empty()) {
        if (per_feature_weights.size() > 1) {
          weights.push_back(
              absl::StrCat("(", absl::StrJoin(per_feature_weights, ", "), ")"));
        } else {
          weights.push_back(absl::StrCat(per_feature_weights[0]));
        }
      }
    }
    lines.push_back(absl::StrCat("  ", feature_prefix, "values: [",
                                 absl::StrJoin(values, ", "), "]"));
    if (!weights.empty()) {
      lines.push_back(
          absl::StrCat("  weights: [", absl::StrJoin(weights, ", "), "]"));
    }
    if (!debug_infos.empty()) {
      lines.push_back(absl::StrCat("  debug_infos: [",
                                   absl::StrJoin(debug_infos, ", "), "]"));
    }
    lines.push_back("}");
  }
  return absl::StrJoin(lines, "\n");
}