line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
#include |
3
|
|
|
|
|
|
|
#include |
4
|
|
|
|
|
|
|
#include "../include/libstemmer.h" |
5
|
|
|
|
|
|
|
#include "../runtime/api.h" |
6
|
|
|
|
|
|
|
#include "modules.h" |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
struct sb_stemmer { |
9
|
|
|
|
|
|
|
struct SN_env * (*create)(void); |
10
|
|
|
|
|
|
|
void (*close)(struct SN_env *); |
11
|
|
|
|
|
|
|
int (*stem)(struct SN_env *); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
struct SN_env * env; |
14
|
|
|
|
|
|
|
}; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
extern const char ** |
17
|
0
|
|
|
|
|
|
sb_stemmer_list(void) |
18
|
|
|
|
|
|
|
{ |
19
|
0
|
|
|
|
|
|
return algorithm_names; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
static stemmer_encoding_t |
23
|
2
|
|
|
|
|
|
sb_getenc(const char * charenc) |
24
|
|
|
|
|
|
|
{ |
25
|
|
|
|
|
|
|
struct stemmer_encoding * encoding; |
26
|
2
|
50
|
|
|
|
|
if (charenc == NULL) return ENC_UTF_8; |
27
|
2
|
50
|
|
|
|
|
for (encoding = encodings; encoding->name != 0; encoding++) { |
28
|
2
|
50
|
|
|
|
|
if (strcmp(encoding->name, charenc) == 0) break; |
29
|
|
|
|
|
|
|
} |
30
|
2
|
50
|
|
|
|
|
if (encoding->name == NULL) return ENC_UNKNOWN; |
31
|
2
|
|
|
|
|
|
return encoding->enc; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
extern struct sb_stemmer * |
35
|
2
|
|
|
|
|
|
sb_stemmer_new(const char * algorithm, const char * charenc) |
36
|
|
|
|
|
|
|
{ |
37
|
|
|
|
|
|
|
stemmer_encoding_t enc; |
38
|
|
|
|
|
|
|
struct stemmer_modules * module; |
39
|
2
|
|
|
|
|
|
struct sb_stemmer * stemmer = |
40
|
|
|
|
|
|
|
(struct sb_stemmer *) malloc(sizeof(struct sb_stemmer)); |
41
|
2
|
50
|
|
|
|
|
if (stemmer == NULL) return NULL; |
42
|
2
|
|
|
|
|
|
enc = sb_getenc(charenc); |
43
|
2
|
50
|
|
|
|
|
if (enc == ENC_UNKNOWN) return NULL; |
44
|
|
|
|
|
|
|
|
45
|
2
|
50
|
|
|
|
|
for (module = modules; module->name != 0; module++) { |
46
|
2
|
50
|
|
|
|
|
if (strcmp(module->name, algorithm) == 0 && module->enc == enc) break; |
|
|
50
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
48
|
2
|
50
|
|
|
|
|
if (module->name == NULL) return NULL; |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
|
stemmer->create = module->create; |
51
|
2
|
|
|
|
|
|
stemmer->close = module->close; |
52
|
2
|
|
|
|
|
|
stemmer->stem = module->stem; |
53
|
|
|
|
|
|
|
|
54
|
2
|
|
|
|
|
|
stemmer->env = stemmer->create(); |
55
|
2
|
50
|
|
|
|
|
if (stemmer->env == NULL) |
56
|
|
|
|
|
|
|
{ |
57
|
0
|
|
|
|
|
|
sb_stemmer_delete(stemmer); |
58
|
0
|
|
|
|
|
|
return NULL; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
return stemmer; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
void |
65
|
2
|
|
|
|
|
|
sb_stemmer_delete(struct sb_stemmer * stemmer) |
66
|
|
|
|
|
|
|
{ |
67
|
2
|
50
|
|
|
|
|
if (stemmer == 0) return; |
68
|
2
|
50
|
|
|
|
|
if (stemmer->close == 0) return; |
69
|
2
|
|
|
|
|
|
stemmer->close(stemmer->env); |
70
|
2
|
|
|
|
|
|
stemmer->close = 0; |
71
|
2
|
|
|
|
|
|
free(stemmer); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
const sb_symbol * |
75
|
16
|
|
|
|
|
|
sb_stemmer_stem(struct sb_stemmer * stemmer, const sb_symbol * word, int size) |
76
|
|
|
|
|
|
|
{ |
77
|
|
|
|
|
|
|
int ret; |
78
|
16
|
50
|
|
|
|
|
if (SN_set_current(stemmer->env, size, (const symbol *)(word))) |
79
|
|
|
|
|
|
|
{ |
80
|
0
|
|
|
|
|
|
stemmer->env->l = 0; |
81
|
0
|
|
|
|
|
|
return NULL; |
82
|
|
|
|
|
|
|
} |
83
|
16
|
|
|
|
|
|
ret = stemmer->stem(stemmer->env); |
84
|
16
|
50
|
|
|
|
|
if (ret < 0) return NULL; |
85
|
16
|
|
|
|
|
|
stemmer->env->p[stemmer->env->l] = 0; |
86
|
16
|
|
|
|
|
|
return (const sb_symbol *)(stemmer->env->p); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
int |
90
|
16
|
|
|
|
|
|
sb_stemmer_length(struct sb_stemmer * stemmer) |
91
|
|
|
|
|
|
|
{ |
92
|
16
|
|
|
|
|
|
return stemmer->env->l; |
93
|
|
|
|
|
|
|
} |