23 #include <unicode/ustring.h>
24 #include <unicode/uchar.h>
26 enum stemmer_implementation {
38 const char* yaz_stemmer_lookup_charenc(
const char *charenc,
const char *rule) {
42 const char* yaz_stemmer_lookup_algorithm(
const char *locale,
const char *rule) {
46 yaz_stemmer_p yaz_stemmer_snowball_create(
const char *locale,
const char *rule, UErrorCode *status) {
47 const char *charenc = yaz_stemmer_lookup_charenc(locale, rule);
48 const char *algorithm = yaz_stemmer_lookup_algorithm(locale,rule);
52 *status = U_ILLEGAL_ARGUMENT_ERROR;
53 yaz_log(
YLOG_FATAL,
"yaz_stemmer: Failed to create snowball stemmer from locale %srule %s. Showball: charenc %s algorithm %s ",
54 locale, rule, charenc, algorithm);
57 yaz_log(
YLOG_DEBUG,
"created snowball stemmer: algorithm %s charenc %s ", algorithm, charenc);
58 yaz_stemmer =
xmalloc(
sizeof(*yaz_stemmer));
59 yaz_stemmer->implementation = yaz_snowball;
61 yaz_stemmer->locale =
xstrdup(locale);
62 yaz_stemmer->rule =
xstrdup(rule);
63 yaz_stemmer->sb_stemmer = stemmer;
64 yaz_log(
YLOG_DEBUG,
"created snowball stemmer: algorithm %s charenc %s ", algorithm, charenc);
69 *status = U_ZERO_ERROR;
71 return yaz_stemmer_snowball_create(locale, rule, status);
75 UErrorCode error = U_ZERO_ERROR;
83 switch(stemmer->implementation) {
87 if (*status == U_ZERO_ERROR) {
95 const char *cstr2 = (
const char *)
sb_symbol;
106 case yaz_no_operation:
120 switch (stemmer->implementation) {
125 xfree(stemmer->locale);
126 xfree(stemmer->rule);
struct icu_buf_utf16 * icu_buf_utf16_copy(struct icu_buf_utf16 *dest16, const struct icu_buf_utf16 *src16)
void icu_buf_utf8_destroy(struct icu_buf_utf8 *buf8)
UErrorCode icu_utf16_from_utf8_cstr(struct icu_buf_utf16 *dest16, const char *src8cstr, UErrorCode *status)
const char * icu_buf_utf8_to_cstr(struct icu_buf_utf8 *src8)
struct icu_buf_utf8 * icu_buf_utf8_create(size_t capacity)
UErrorCode icu_utf16_to_utf8(struct icu_buf_utf8 *dest8, const struct icu_buf_utf16 *src16, UErrorCode *status)
struct sb_stemmer * sb_stemmer_new(const char *algorithm, const char *charenc)
const sb_symbol * sb_stemmer_stem(struct sb_stemmer *stemmer, const sb_symbol *word, int size)
void sb_stemmer_delete(struct sb_stemmer *stemmer)
void yaz_log(int level, const char *fmt,...)
Writes log message.
#define YLOG_FATAL
log level: fatal
#define YLOG_DEBUG
log level: debugging
Header for the stemming API.
yaz_stemmer_p yaz_stemmer_create(const char *locale, const char *rule, UErrorCode *status)
void yaz_stemmer_stem(yaz_stemmer_p stemmer, struct icu_buf_utf16 *dst, struct icu_buf_utf16 *src, UErrorCode *status)
void yaz_stemmer_destroy(yaz_stemmer_p stemmer)
yaz_stemmer_p yaz_stemmer_clone(yaz_stemmer_p stemmer)
struct yaz_stemmer_t * yaz_stemmer_p
Header for memory handling functions.
#define xstrdup(s)
utility macro which calls xstrdup_f
#define xfree(x)
utility macro which calls xfree_f
#define xmalloc(x)
utility macro which calls malloc_f