1
/* This file is part of GNU Dico.
2
Copyright (C) 2008 Sergey Poznyakoff
4
GNU Dico is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 3, or (at your option)
9
GNU Dico is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with GNU Dico. If not, see <http://www.gnu.org/licenses/>. */
19
static int levenshtein_distance = 1;
22
lev_sel(int cmd, const char *word, const char *dict_word, void *closure)
24
if (cmd == DICO_SELECT_RUN) {
25
int dist = dico_levenshtein_distance(word, dict_word, (int)closure);
28
return dist <= levenshtein_distance;
33
static struct dico_strategy levstrat[] = {
35
"Match headwords within given Levenshtein distance",
39
"Match headwords within given Levenshtein distance (normalized)",
41
(void*)DICO_LEV_NORM },
43
"Match headwords within given Damerau-Levenshtein distance",
45
(void*)DICO_LEV_DAMERAU },
47
"Match headwords within given Damerau-Levenshtein distance (normalized)",
49
(void*)(DICO_LEV_NORM|DICO_LEV_DAMERAU) }
53
dicod_xlevdist(dico_stream_t str, int argc, char **argv)
55
if (c_strcasecmp(argv[1], "tell") == 0)
56
stream_printf(str, "280 %d\r\n", levenshtein_distance);
57
else if (isdigit(argv[1][0]) && argv[1][0] != '0' && argv[1][1] == 0) {
58
levenshtein_distance = atoi(argv[1]);
59
stream_printf(str, "250 ok - Levenshtein threshold set to %d\r\n",
60
levenshtein_distance);
62
stream_writez(str, "500 invalid argument\r\n");
69
static struct dicod_command cmd[] = {
70
{ "XLEV", 2, 2, "distance", "Set Levenshtein distance",
74
for (i = 0; i < DICO_ARRAY_SIZE(levstrat); i++)
75
dico_strategy_add(&levstrat[i]);
76
dico_set_default_strategy("nlev");
77
dicod_capa_register("xlev", cmd, NULL, NULL);