pluskid-rmmseg-cpp 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/rmmseg/algor.cpp +3 -1
- data/ext/rmmseg/rmmseg.cpp +7 -3
- data/lib/rmmseg/ferret.rb +5 -1
- metadata +1 -1
data/ext/rmmseg/algor.cpp
CHANGED
data/ext/rmmseg/rmmseg.cpp
CHANGED
@@ -68,7 +68,6 @@ extern "C" {
|
|
68
68
|
|
69
69
|
static void tk_mark(Token *t)
|
70
70
|
{
|
71
|
-
// start and end are Fixnums, no need to mark them
|
72
71
|
rb_gc_mark(t->text);
|
73
72
|
}
|
74
73
|
static void tk_free(Token *t)
|
@@ -95,9 +94,14 @@ extern "C" {
|
|
95
94
|
static VALUE cToken;
|
96
95
|
static VALUE tk_create(const char* base, const rmmseg::Token &t)
|
97
96
|
{
|
98
|
-
Token *tk = (Token
|
97
|
+
Token *tk = ALLOC(Token);
|
99
98
|
int start = t.text-base;
|
100
99
|
tk->text = rb_str_new(t.text, t.length);
|
100
|
+
|
101
|
+
// This is necessary, see
|
102
|
+
// http://pluskid.lifegoo.com/?p=348
|
103
|
+
rb_gc_mark(tk->text);
|
104
|
+
|
101
105
|
tk->start = INT2FIX(start);
|
102
106
|
tk->end = INT2FIX(start + t.length);
|
103
107
|
return Data_Wrap_Struct(cToken,
|
@@ -127,7 +131,7 @@ extern "C" {
|
|
127
131
|
static VALUE cAlgorithm;
|
128
132
|
static VALUE algor_create(VALUE klass, VALUE text)
|
129
133
|
{
|
130
|
-
Algorithm *algor = (Algorithm
|
134
|
+
Algorithm *algor = ALLOC(Algorithm);
|
131
135
|
void *mem;
|
132
136
|
algor->text = text;
|
133
137
|
mem = malloc(sizeof(rmmseg::Algorithm));
|
data/lib/rmmseg/ferret.rb
CHANGED
@@ -42,7 +42,10 @@ module RMMSeg
|
|
42
42
|
if tok.nil?
|
43
43
|
return nil
|
44
44
|
else
|
45
|
-
|
45
|
+
@token.text = tok.text
|
46
|
+
@token.start = tok.start
|
47
|
+
@token.end = tok.end
|
48
|
+
return @token
|
46
49
|
end
|
47
50
|
end
|
48
51
|
|
@@ -53,6 +56,7 @@ module RMMSeg
|
|
53
56
|
|
54
57
|
# Set the text to be tokenized
|
55
58
|
def text=(str)
|
59
|
+
@token = ::Ferret::Analysis::Token.new("", 0, 0)
|
56
60
|
@text = str
|
57
61
|
@algor = Algorithm.new(@text)
|
58
62
|
end
|