Method: Lingua::Stemmer#stem

Defined in:
ext/lingua/stemmer.c

#stemObject

Stems a word

require 'lingua/stemmer'
s = Lingua::Stemmer.new
s.stem "installation" # ==> install


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'ext/lingua/stemmer.c', line 75

static VALUE
rb_stemmer_stem(VALUE self, VALUE word) {
  struct sb_stemmer * stemmer;

  Data_Get_Struct(self, struct sb_stemmer, stemmer);
  if(!stemmer) rb_raise(rb_eRuntimeError, "Stemmer is not initialized");

  VALUE s_word = rb_String(word);
  const sb_symbol * stemmed = sb_stemmer_stem(stemmer,
      (sb_symbol *)RSTRING_PTR(s_word),
      RSTRING_LEN(s_word)
  );

  VALUE rb_enc = rb_iv_get(self, "@encoding");
  return ENCODED_STR_NEW2((char *)stemmed, rb_enc);
}