<commit_before>/**
 * Copyright (c) 2015 - The CM Authors <<EMAIL>>
 *   All Rights Reserved.
 *
 * This file is CONFIDENTIAL -- Distribution or duplication of this material or
 * the information contained herein is strictly forbidden unless prior written
 * permission is obtained.
 */
#include <fnord-json/json.h>
#include "reports/TermInfoTableSink.h"

using namespace fnord;

namespace cm {

TermInfoTableSink::TermInfoTableSink(
    const String& output_file) :
    output_file_(output_file) {
  sstable_schema_.addColumn("related_terms", 1, sstable::SSTableColumnType::STRING);
}

void TermInfoTableSink::open() {
  if (FileUtil::exists(output_file_ + "~")) {
    fnord::logInfo(
        "cm.reportbuild",
        "Deleting orphaned temp file: $0",
        output_file_ + "~");

    FileUtil::rm(output_file_ + "~");
  }

  fnord::logInfo(
      "cm.reportbuild",
      "Opening output sstable: $0",
      output_file_);

  sstable_writer_ = sstable::SSTableWriter::create(
      output_file_ + "~",
      sstable::IndexProvider{},
      nullptr,
      0);
}

void TermInfoTableSink::addRow(const String& key, const TermInfo& term_info) {
  String terms_str;
  for (const auto t : term_info.related_terms) {
    terms_str += StringUtil::format("$0:$1,", t.first, t.second);
  }

  sstable::SSTableColumnWriter cols(&sstable_schema_);
  cols.addStringColumn(1, terms_str);
  sstable_writer_->appendRow(key, cols);
}

void TermInfoTableSink::close() {
  fnord::logInfo(
      "cm.reportbuild",
      "Finalizing output sstable: $0",
      output_file_);

  sstable_schema_.writeIndex(sstable_writer_.get());
  sstable_writer_->finalize();

  FileUtil::mv(output_file_ + "~", output_file_);
}

Set<String> TermInfoTableSink::outputFiles() {
  return Set<String> { output_file_ };
}

} // namespace cm

<commit_msg>write top categories in TermInfoTableSink<commit_after>/**
 * Copyright (c) 2015 - The CM Authors <<EMAIL>>
 *   All Rights Reserved.
 *
 * This file is CONFIDENTIAL -- Distribution or duplication of this material or
 * the information contained herein is strictly forbidden unless prior written
 * permission is obtained.
 */
#include <fnord-json/json.h>
#include "reports/TermInfoTableSink.h"

using namespace fnord;

namespace cm {

TermInfoTableSink::TermInfoTableSink(
    const String& output_file) :
    output_file_(output_file) {
  sstable_schema_.addColumn(
      "related_terms",
      1,
      sstable::SSTableColumnType::STRING);

  sstable_schema_.addColumn(
      "top_categories",
      2,
      sstable::SSTableColumnType::STRING);
}

void TermInfoTableSink::open() {
  if (FileUtil::exists(output_file_ + "~")) {
    fnord::logInfo(
        "cm.reportbuild",
        "Deleting orphaned temp file: $0",
        output_file_ + "~");

    FileUtil::rm(output_file_ + "~");
  }

  fnord::logInfo(
      "cm.reportbuild",
      "Opening output sstable: $0",
      output_file_);

  sstable_writer_ = sstable::SSTableWriter::create(
      output_file_ + "~",
      sstable::IndexProvider{},
      nullptr,
      0);
}

void TermInfoTableSink::addRow(const String& key, const TermInfo& term_info) {
  String terms_str;
  for (const auto t : term_info.related_terms) {
    terms_str += StringUtil::format("$0:$1,", t.first, t.second);
  }

  String topcats_str;
  for (const auto t : term_info.top_categories) {
    topcats_str += StringUtil::format("$0:$1,", t.first, t.second);
  }

  sstable::SSTableColumnWriter cols(&sstable_schema_);
  cols.addStringColumn(1, terms_str);
  cols.addStringColumn(2, topcats_str);
  sstable_writer_->appendRow(key, cols);
}

void TermInfoTableSink::close() {
  fnord::logInfo(
      "cm.reportbuild",
      "Finalizing output sstable: $0",
      output_file_);

  sstable_schema_.writeIndex(sstable_writer_.get());
  sstable_writer_->finalize();

  FileUtil::mv(output_file_ + "~", output_file_);
}

Set<String> TermInfoTableSink::outputFiles() {
  return Set<String> { output_file_ };
}

} // namespace cm


{'fraction_non_alphanumeric': 0.13418932527693858, 'fraction_numerical': 0.007049345417925478, 'mean_word_length': 4.067602040816326, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3846363', 'n_tokens_mistral': 1352, 'n_tokens_neox': 1311, 'n_words': 266}