Sha256: b82755209ca9805cb53cbea2c500c043da2a365a973b03533318a632b0d8bdae

Contents?: true

Size: 1.96 KB

Versions: 3

Compression:

Stored size: 1.96 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, size_t seed) {
        tomoto::DMRArgs args;
        args.k = k;
        args.alpha = {alpha};
        args.sigma = sigma;
        args.eta = eta;
        args.alphaEps = alpha_epsilon;
        if (seed >= 0) {
          args.seed = seed;
        }
        return tomoto::IDMRModel::create((tomoto::TermWeight)tw, args);
      })
    .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

3 entries across 3 versions & 1 rubygems

Version Path
tomoto-0.2.2 ext/tomoto/dmr.cpp
tomoto-0.2.1 ext/tomoto/dmr.cpp
tomoto-0.2.0 ext/tomoto/dmr.cpp