ext/quarry/quarry_toolkit.cpp in thera-0.0.7 vs ext/quarry/quarry_toolkit.cpp in thera-0.0.8

- old
+ new

@@ -43,19 +43,39 @@ delete ranks; return names; } +Object quarry_rank_text_names_from_binary_model(Object path, Object text) { + string model_path = from_ruby<string>(path); + string example_text = from_ruby<string>(text); + Array names; + + Storage::Binary reader(model_path); + Model::Model *model = reader.read_model(); + + vector<Classifier::Score> *ranks = model->rank_text(example_text); + DataSet::NominalFeature *categories = model->data_set->category_feature(); + for(unsigned int i = 0; i < ranks->size(); i++) + names.push(categories->names[ranks->at(i).category]); + + delete ranks; + delete model; + return names; +} + extern "C" { void Init_quarry_toolkit() { Module rb_mQuarry = define_module("Quarry"); Module rb_mDataSet = define_module_under(rb_mQuarry, "DataSet"); Module rb_mClassifier = define_module_under(rb_mQuarry, "Classifier"); Module rb_mPreprocessing = define_module_under(rb_mQuarry, "Preprocessing"); Module rb_mText = define_module_under(rb_mPreprocessing, "Text"); + // quarry helper + rb_mQuarry.define_module_function("rank_text_names_from_binary_model", &quarry_rank_text_names_from_binary_model); // text pipeline rb_mText.define_module_function("standard_pipeline", &Preprocessing::Text::StandardPipeline); Data_Type<Preprocessing::Text::TextPipeline> rb_cTextPipeline = define_class_under<Preprocessing::Text::TextPipeline>(rb_mQuarry, "ImplTextPipeline") .define_constructor(Constructor<Preprocessing::Text::TextPipeline>());