Sha256: 2d41bad7c995c1c157367096945a5a4e300cdb30204999e247876b502ae03584
Contents?: true
Size: 983 Bytes
Versions: 3
Compression:
Stored size: 983 Bytes
Contents
#include <ruby.h> #ifndef RSTRING_PTR #define RSTRING_PTR(str) (RSTRING(str)->ptr) #endif extern struct stemmer * create_stemmer(void); extern void free_stemmer(struct stemmer * z); extern int stem(struct stemmer * z, char * b, int k); /* copied from porter.c */ struct stemmer { char * b; /* buffer for word to be stemmed */ int k; /* offset to the end of the string */ int j; /* a general offset into the string */ }; static VALUE stem_word(VALUE self, VALUE arg) { size_t length, i; char *word; struct stemmer z; VALUE str, rv; str = StringValue(arg); word = malloc(RSTRING_LEN(str) + 1); strncpy(word, RSTRING_PTR(str), RSTRING_LEN(str)); word[RSTRING_LEN(str)] = '\0'; length = stem(&z, word, strlen(word)-1); word[length+1] = 0; rv = rb_str_new2(word); free(word); return rv; } VALUE mStemmer; void Init_stemmer(void) { mStemmer = rb_define_module("Stemmer"); rb_define_module_function(mStemmer, "stem_word", stem_word, 1); }
Version data entries
3 entries across 3 versions & 2 rubygems
Version | Path |
---|---|
scoot-0.0.4 | .bundle/gems/ruby/2.2.0/gems/fast-stemmer-1.0.2/ext/porter_wrap.c |
fast-stemmer-1.0.2 | ext/porter_wrap.c |
fast-stemmer-1.0.1 | ext/porter_wrap.c |