-
Notifications
You must be signed in to change notification settings - Fork 9
/
stemmer.c
133 lines (110 loc) · 3.63 KB
/
stemmer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_stemmer.h"
#include "libstemmer_c/include/libstemmer.h"
ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0)
ZEND_END_ARG_INFO()
static zend_function_entry stemmer_functions[] = {
PHP_FE(stemword, arginfo_void)
{NULL, NULL, NULL}
};
zend_module_entry stemmer_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
PHP_STEMMER_EXTNAME,
stemmer_functions,
NULL,
NULL,
NULL,
NULL,
NULL,
#if ZEND_MODULE_API_NO >= 20010901
PHP_STEMMER_VERSION,
#endif
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_STEMMER
ZEND_GET_MODULE(stemmer)
#endif
#if PHP_MAJOR_VERSION < 7
PHP_FUNCTION(stemword)
{
zval *lang, *enc, *arg;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &arg,&lang,&enc) == FAILURE)RETURN_NULL();
convert_to_string(lang);
convert_to_string(enc);
struct sb_stemmer * stemmer;
//char * language = "kraaij_pohlmann";
//char * charenc = "UTF_8";
stemmer = sb_stemmer_new(Z_STRVAL_P(lang),Z_STRVAL_P(enc));
if(!stemmer) RETURN_NULL();
if(Z_TYPE_P(arg) == IS_ARRAY)
{
array_init(return_value);
HashTable *arr_hash;
HashPosition pointer;
int array_count;
arr_hash = Z_ARRVAL_P(arg);
array_count = zend_hash_num_elements(arr_hash);
zval **data;
for( zend_hash_internal_pointer_reset_ex(arr_hash,&pointer);
zend_hash_get_current_data_ex(arr_hash,(void **)&data, &pointer)==SUCCESS;
zend_hash_move_forward_ex(arr_hash,&pointer) ){
const sb_symbol *stemmed = "";
if(Z_TYPE_PP(data) == IS_STRING){
stemmed = sb_stemmer_stem(stemmer, Z_STRVAL_PP(data), Z_STRLEN_PP(data));
}
add_next_index_string(return_value,stemmed, 1);
}
}else{
convert_to_string(arg);
const sb_symbol *stemmed = sb_stemmer_stem(stemmer, Z_STRVAL_P(arg), Z_STRLEN_P(arg));
if(stemmed)ZVAL_STRING( return_value, stemmed, 1);
}
sb_stemmer_delete(stemmer);
// RETURN_STRING(stemmed, 1);
//return 1;
}
#else
PHP_FUNCTION(stemword)
{
zval *lang, *enc, *arg;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &arg,&lang,&enc) == FAILURE)RETURN_NULL();
convert_to_string(lang);
convert_to_string(enc);
struct sb_stemmer * stemmer;
//char * language = "kraaij_pohlmann";
//char * charenc = "UTF_8";
stemmer = sb_stemmer_new(Z_STRVAL_P(lang),Z_STRVAL_P(enc));
if(!stemmer) RETURN_NULL();
if(Z_TYPE_P(arg) == IS_ARRAY)
{
array_init(return_value);
HashTable *arr_hash;
HashPosition pointer;
int array_count;
arr_hash = Z_ARRVAL_P(arg);
array_count = zend_hash_num_elements(arr_hash);
zval *data;
for( zend_hash_internal_pointer_reset_ex(arr_hash,&pointer);
zend_hash_get_current_data_ex(arr_hash,(void *)&data)==SUCCESS;
zend_hash_move_forward_ex(arr_hash,&pointer) ){
const sb_symbol *stemmed = "";
if(Z_TYPE_P(data) == IS_STRING){
stemmed = sb_stemmer_stem(stemmer, Z_STRVAL_P(data), Z_STRLEN_P(data));
}
add_next_index_string(return_value,stemmed);
}
}else{
convert_to_string(arg);
const sb_symbol *stemmed = sb_stemmer_stem(stemmer, Z_STRVAL_P(arg), Z_STRLEN_P(arg));
if(stemmed)ZVAL_STRING( return_value, stemmed);
}
sb_stemmer_delete(stemmer);
// RETURN_STRING(stemmed, 1);
//return 1;
}
#endif