1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
16 #include <yaz/stemmer.h>
18 int test_stemmer_stem(yaz_stemmer_p stemmer, const char* to_stem, const char *expected)
20 struct icu_buf_utf16 *src = icu_buf_utf16_create(0);
21 struct icu_buf_utf16 *dst = icu_buf_utf16_create(0);
22 struct icu_buf_utf8 *dst8 = icu_buf_utf8_create(0);
27 icu_utf16_from_utf8_cstr(src, to_stem, &status);
28 yaz_stemmer_stem(stemmer, dst, src, &status);
29 if (status == U_ZERO_ERROR) {
30 icu_utf16_to_utf8(dst8, dst, &status);
31 result = icu_buf_utf8_to_cstr(dst8);
32 rc = strcmp(result, expected) == 0;
34 icu_buf_utf8_destroy(dst8);
35 icu_buf_utf16_destroy(src);
36 icu_buf_utf16_destroy(dst);
45 yaz_stemmer_p stemmer = yaz_stemmer_create("en", "porter", &status);
49 YAZ_CHECK(test_stemmer_stem(stemmer, "beer", "water") == 0 );
52 YAZ_CHECK(test_stemmer_stem(stemmer, "adadwwr", "adadwwr"));
55 YAZ_CHECK(test_stemmer_stem(stemmer, "beers", "beer"));
56 YAZ_CHECK(test_stemmer_stem(stemmer, "persons", "person"));
58 /* Remove s and ing */
59 YAZ_CHECK(test_stemmer_stem(stemmer, "runs", "run"));
60 YAZ_CHECK(test_stemmer_stem(stemmer, "running", "run"));
62 yaz_stemmer_destroy(stemmer);
66 int main (int argc, char **argv)
68 YAZ_CHECK_INIT(argc, argv);
78 * c-file-style: "Stroustrup"
79 * indent-tabs-mode: nil
81 * vim: shiftwidth=4 tabstop=8 expandtab