1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2011 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);
26 icu_utf16_from_utf8_cstr(src, to_stem, &status);
27 yaz_stemmer_stem(stemmer, dst, src, &status);
30 if (status == U_ZERO_ERROR) {
31 icu_utf16_to_utf8(dst8, dst, &status);
32 result = icu_buf_utf8_to_cstr(dst8);
33 rc = strcmp(result, expected) == 0;
35 icu_buf_utf8_destroy(dst8);
36 icu_buf_utf16_destroy(src);
37 icu_buf_utf16_destroy(dst);
46 yaz_stemmer_p stemmer = yaz_stemmer_create("en", "porter", &status);
50 YAZ_CHECK(test_stemmer_stem(stemmer, "beer", "water") == 0 );
53 YAZ_CHECK(test_stemmer_stem(stemmer, "adadwwr", "adadwwr"));
56 YAZ_CHECK(test_stemmer_stem(stemmer, "beers", "beer"));
57 YAZ_CHECK(test_stemmer_stem(stemmer, "persons", "person"));
59 /* Remove s and ing */
60 YAZ_CHECK(test_stemmer_stem(stemmer, "runs", "run"));
61 YAZ_CHECK(test_stemmer_stem(stemmer, "running", "run"));
63 yaz_stemmer_destroy(stemmer);
67 int main (int argc, char **argv)
69 YAZ_CHECK_INIT(argc, argv);
79 * c-file-style: "Stroustrup"
80 * indent-tabs-mode: nil
82 * vim: shiftwidth=4 tabstop=8 expandtab