Sha256: b2d7af80098176664290079c719c1156b79703236a7b62bf0411b50662cd0a12

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

#include <DMR.h>

#include <rice/Class.hpp>
#include <rice/Module.hpp>

#include "utils.h"

void init_dmr(Rice::Module& m) {
  Rice::define_class_under<tomoto::IDMRModel, tomoto::ILDAModel>(m, "DMR")
    .define_singleton_method(
      "_new",
      *[](size_t tw, size_t k, tomoto::Float alpha, tomoto::Float sigma, tomoto::Float eta, tomoto::Float alpha_epsilon, int seed) {
        if (seed < 0) {
          seed = std::random_device{}();
        }
        return tomoto::IDMRModel::create((tomoto::TermWeight)tw, k, alpha, sigma, eta, alpha_epsilon, seed);
      })
    .define_method(
      "_add_doc",
      *[](tomoto::IDMRModel& self, std::vector<std::string> words, std::string metadata) {
        auto doc = buildDoc(words);
        doc.misc["metadata"] = metadata;
        return self.addDoc(doc);
      })
    .define_method(
      "alpha_epsilon",
      *[](tomoto::IDMRModel& self) {
        return self.getAlphaEps();
      })
    .define_method(
      "alpha_epsilon=",
      *[](tomoto::IDMRModel& self, tomoto::Float value) {
        self.setAlphaEps(value);
        return value;
      })
    .define_method(
      "f",
      *[](tomoto::IDMRModel& self) {
        return self.getF();
      })
    .define_method(
      "_lambdas",
      *[](tomoto::IDMRModel& self, tomoto::Tid topic_id) {
        return self.getLambdaByTopic(topic_id);
      })
    .define_method(
      "metadata_dict",
      *[](tomoto::IDMRModel& self) {
        auto dict = self.getMetadataDict();
        Array res;
        auto utf8 = Rice::Class(rb_cEncoding).call("const_get", "UTF_8");
        for (size_t i = 0; i < dict.size(); i++) {
          res.push(to_ruby<std::string>(dict.toWord(i)).call("force_encoding", utf8));
        }
        return res;
      })
    .define_method(
      "sigma",
      *[](tomoto::IDMRModel& self) {
        return self.getSigma();
      });
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tomoto-0.1.4 ext/tomoto/dmr.cpp