#include <yaz/icu_I18N.h>
+#include <yaz/stemmer.h>
+
#include <yaz/log.h>
#include <string.h>
enum icu_chain_step_type {
ICU_chain_step_type_none,
- ICU_chain_step_type_display, /* convert to utf8 display format */
- ICU_chain_step_type_casemap, /* apply utf16 charmap */
- ICU_chain_step_type_transform, /* apply utf16 transform */
- ICU_chain_step_type_tokenize, /* apply utf16 tokenization */
- ICU_chain_step_type_transliterate /* apply utf16 tokenization */
+ ICU_chain_step_type_display, /* convert to utf8 display format */
+ ICU_chain_step_type_casemap, /* apply utf16 charmap */
+ ICU_chain_step_type_transform, /* apply utf16 transform */
+ ICU_chain_step_type_tokenize, /* apply utf16 tokenization */
+ ICU_chain_step_type_transliterate, /* apply utf16 tokenization */
+ YAZ_chain_step_type_stemming /* apply utf16 stemming (YAZ) */
};
struct icu_chain_step
/* type and action object */
enum icu_chain_step_type type;
union {
- struct icu_casemap * casemap;
- struct icu_transform * transform;
- struct icu_tokenizer * tokenizer;
+ struct icu_casemap * casemap;
+ struct icu_transform * transform;
+ struct icu_tokenizer * tokenizer;
+ yaz_stemmer_p stemmer;
} u;
struct icu_chain_step * previous;
};
step->u.transform = icu_transform_create("custom", 'f',
(const char *) rule, status);
break;
+ case YAZ_chain_step_type_stemming:
+ step->u.stemmer = yaz_stemmer_create((char *) chain->locale, (const char *) rule, status);
+ break;
default:
break;
}
case ICU_chain_step_type_tokenize:
icu_tokenizer_destroy(step->u.tokenizer);
break;
+ case YAZ_chain_step_type_stemming:
+ yaz_stemmer_destroy(step->u.stemmer);
+ break;
default:
break;
}
case ICU_chain_step_type_tokenize:
(*sp)->u.tokenizer = icu_tokenizer_clone(old->u.tokenizer);
break;
+ case YAZ_chain_step_type_stemming:
+ yaz_stemmer_clone(step->u.stemmer);
+ break;
case ICU_chain_step_type_none:
break;
}
else if (!strcmp((const char *) node->name, "display"))
step = icu_chain_insert_step(chain, ICU_chain_step_type_display,
(const uint8_t *) "", status);
+ else if (!strcmp((const char *) node->name, "stemming"))
+ step = yaz_chain_insert_step(chain, YAZ_chain_step_type_stemming,
+ (const uint8_t *) xml_rule, status);
else if (!strcmp((const char *) node->name, "normalize"))
{
yaz_log(YLOG_WARN, "Element %s is deprecated. "
if (dst)
icu_utf16_to_utf8(iter->display, dst, &iter->status);
break;
+ case YAZ_chain_step_type_stemming:
+ if (dst)
+ {
+ struct icu_buf_utf16 *src = dst;
+ dst = icu_buf_utf16_create(0);
+ yaz_stemmer_stem(step->u.stemmer, dst, src, &iter->status);
+ icu_buf_utf16_destroy(src);
+ }
+ break;
default:
assert(0);
}