Sha256: d4c517f95525248aa0b640c2dbcfc12ade40dafb24c9efd86c82541940e22cbf

Contents?: true

Size: 1.14 KB

Versions: 5

Compression:

Stored size: 1.14 KB

Contents

#include "jaro_winkler.h"
#include "distance.h"

VALUE rb_mJaroWinkler;

void Init_jaro_winkler(void){
  rb_mJaroWinkler = rb_define_module("JaroWinkler");
  rb_define_module_function(rb_mJaroWinkler, "c_distance", rb_distance, -1);
}

VALUE rb_distance(int argc, VALUE *argv, VALUE self){
  VALUE s1, s2, opt;
  rb_scan_args(argc, argv, "2:", &s1, &s2, &opt);
  Option *c_opt = option_new();
  if(TYPE(opt) == T_HASH){
    VALUE weight = rb_hash_aref(opt, ID2SYM(rb_intern("weight")));
    VALUE threshold = rb_hash_aref(opt, ID2SYM(rb_intern("threshold")));
    VALUE case_match = rb_hash_aref(opt, ID2SYM(rb_intern("case_match")));
    if(!NIL_P(weight)) c_opt->weight = NUM2DBL(weight);
    if(c_opt->weight > 0.25) rb_raise(rb_eRuntimeError, "Scaling factor should not exceed 0.25, otherwise the distance can become larger than 1.");
    if(!NIL_P(threshold)) c_opt->threshold = NUM2DBL(threshold);
    if(!NIL_P(case_match)) c_opt->case_match = (TYPE(case_match) == T_FALSE || NIL_P(case_match)) ? 0 : 1;
  }
  VALUE ret = rb_float_new(c_distance(StringValuePtr(s1), RSTRING_LEN(s1), StringValuePtr(s2), RSTRING_LEN(s2), c_opt));
  free(c_opt);
  return ret;
}

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
jaro_winkler-1.2.7 ext/jaro_winkler/jaro_winkler.c
jaro_winkler-1.2.6 ext/jaro_winkler/jaro_winkler.c
jaro_winkler-1.2.5 ext/jaro_winkler/jaro_winkler.c
jaro_winkler-1.2.4 ext/jaro_winkler/jaro_winkler.c
jaro_winkler-1.2.3 ext/jaro_winkler/jaro_winkler.c