Skip to content

Commit 87df4d8

Browse files
committed
Исправление метода расчёта Дамерау-Левенштейна
1 parent ceec487 commit 87df4d8

File tree

5 files changed

+18
-16
lines changed

5 files changed

+18
-16
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# [Change Log](https://github.com/anyks/asc/archive/release.tar.gz)
22

3+
## [1.1.0](https://github.com/anyks/asc/archive/v1.1.0.tar.gz) Bug fixes
4+
35
## [1.0.9](https://github.com/anyks/asc/archive/v1.0.9.tar.gz) Bug fixes
46

57
## [1.0.8](https://github.com/anyks/asc/archive/v1.0.8.tar.gz) Bug fixes

app/asc.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// Название языковой модели
1010
#define ANYKS_ASC_NAME "asc"
1111
// Версия приложения
12-
#define ANYKS_ASC_VERSION "1.0.9"
12+
#define ANYKS_ASC_VERSION "1.1.0"
1313
// Версия словаря
1414
#define ANYKS_ASC_DICT_VERSION "1.0.0"
1515
// Автор приложения

src/dict.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ void anyks::Dict::setDate(const time_t date) noexcept {
560560
*/
561561
void anyks::Dict::setCode(const wstring & code) noexcept {
562562
// Если код языка передан
563-
if(!code.empty()) this->params.code = code;
563+
if(!code.empty()) this->params.code = this->alphabet->toLower(code);
564564
}
565565
/**
566566
* setName Метод установки названия словаря
@@ -848,7 +848,7 @@ const pair <size_t, size_t> anyks::Dict::find(const word_t & word, dumper_t & dm
848848
// Если список слов не пустой
849849
if(!this->words.empty() && (word.length() <= MAX_WORD_LENGTH)){
850850
// Объект левенштейна
851-
lev_t levenshtein;
851+
lev_t algorithms;
852852
// Создаём гипотезу
853853
dumper_t::awrd_t hypothesis;
854854
// Устанавливаем эталонную фразу
@@ -869,13 +869,13 @@ const pair <size_t, size_t> anyks::Dict::find(const word_t & word, dumper_t & dm
869869
// Устанавливаем идентификатор гипотезы
870870
hypothesis.idw = idw;
871871
// Получаем дистанцию
872-
hypothesis.lev = (errors > 1 ? levenshtein.distance(word, it->second) : levenshtein.damerau(word, it->second));
872+
hypothesis.lev = (errors > 1 ? algorithms.distance(word, it->second) : algorithms.damerau(word, it->second));
873873
// Отфильтровываем ненужные нам слова
874874
if(!it->second.empty() && (hypothesis.lev <= errors)){
875875
// Извлекаем слово из списка
876876
hypothesis.word = it->second;
877877
// Устанавливаем значение Танимото
878-
hypothesis.tmo = levenshtein.tanimoto(word, hypothesis.word);
878+
hypothesis.tmo = algorithms.tanimoto(word, hypothesis.word);
879879
// Если расстояние Левенштейна слишком большое, тогда Танимото должен быть больше 4.0
880880
if((hypothesis.lev <= 3) || (hypothesis.tmo >= 0.4)){
881881
// Если вывод отладочной информации разрешён

src/spl.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ void anyks::ASpell::spell(wstring & text, const u_short options, vector <vector
712712
// Если текст передан
713713
if(!text.empty() && (this->dict != nullptr) && (this->alm != nullptr) && (this->alphabet != nullptr) && (this->tokenizer != nullptr)){
714714
// Объект левенштейна
715-
lev_t levenshtein;
715+
lev_t algorithms;
716716
// Предыдущее слово
717717
word_t lastWord = L"";
718718
// Позиция добавления слов
@@ -867,9 +867,9 @@ void anyks::ASpell::spell(wstring & text, const u_short options, vector <vector
867867
// Устанавливаем полученное слово
868868
hypothesis.word = (* this->dict->word(bwrd.first));
869869
// Выполняем расчёт дистанции Дамерау-Левенштейна
870-
hypothesis.lev = levenshtein.damerau(bwrd.second.first, bwrd.second.second);
870+
hypothesis.lev = algorithms.damerau(bwrd.second.first, bwrd.second.second);
871871
// Выполняем расчёт значения Танимото
872-
hypothesis.tmo = levenshtein.tanimoto(bwrd.second.first, bwrd.second.second);
872+
hypothesis.tmo = algorithms.tanimoto(bwrd.second.first, bwrd.second.second);
873873
// Добавляем гипотезу в сборщик гипотез
874874
dmp.once(hypothesis, parts.size(), pos2);
875875
}
@@ -922,7 +922,7 @@ void anyks::ASpell::spell(wstring & text, const u_short options, vector <vector
922922
hypotheses.at(i) = hypothesis;
923923
}
924924
// Добавляем список гипотез в список
925-
pos1 = dmp.add(hypotheses, levenshtein.damerau(word, text), levenshtein.tanimoto(word, text), pos1);
925+
pos1 = dmp.add(hypotheses, algorithms.damerau(word, text), algorithms.tanimoto(word, text), pos1);
926926
}
927927
}
928928
// Если разрешено выполнять сплиты
@@ -969,7 +969,7 @@ void anyks::ASpell::spell(wstring & text, const u_short options, vector <vector
969969
hypotheses.at(i) = hypothesis;
970970
}
971971
// Добавляем список гипотез в список
972-
pos1 = dmp.add(hypotheses, levenshtein.damerau(word, text), levenshtein.tanimoto(word, text), pos1);
972+
pos1 = dmp.add(hypotheses, algorithms.damerau(word, text), algorithms.tanimoto(word, text), pos1);
973973
}
974974
}
975975
// Если сплит выполнять не удалось
@@ -1050,7 +1050,7 @@ void anyks::ASpell::analyze(const wstring & text, const u_short options, vector
10501050
// Очищаем список анализируемых слов
10511051
info.clear();
10521052
// Объект левенштейна
1053-
lev_t levenshtein;
1053+
lev_t algorithms;
10541054
// Предыдущее слово
10551055
word_t lastWord = L"";
10561056
// Позиция добавления слов
@@ -1216,9 +1216,9 @@ void anyks::ASpell::analyze(const wstring & text, const u_short options, vector
12161216
// Устанавливаем полученное слово
12171217
hypothesis.word = (* this->dict->word(bwrd.first));
12181218
// Выполняем расчёт дистанции Дамерау-Левенштейна
1219-
hypothesis.lev = levenshtein.damerau(bwrd.second.first, bwrd.second.second);
1219+
hypothesis.lev = algorithms.damerau(bwrd.second.first, bwrd.second.second);
12201220
// Выполняем расчёт значения Танимото
1221-
hypothesis.tmo = levenshtein.tanimoto(bwrd.second.first, bwrd.second.second);
1221+
hypothesis.tmo = algorithms.tanimoto(bwrd.second.first, bwrd.second.second);
12221222
// Добавляем гипотезу в сборщик гипотез
12231223
dmp.once(hypothesis, parts.size(), pos2);
12241224
}
@@ -1271,7 +1271,7 @@ void anyks::ASpell::analyze(const wstring & text, const u_short options, vector
12711271
hypotheses.at(i) = hypothesis;
12721272
}
12731273
// Добавляем список гипотез в список
1274-
pos1 = dmp.add(hypotheses, levenshtein.damerau(word, text), levenshtein.tanimoto(word, text), pos1);
1274+
pos1 = dmp.add(hypotheses, algorithms.damerau(word, text), algorithms.tanimoto(word, text), pos1);
12751275
}
12761276
}
12771277
// Если разрешено выполнять сплиты
@@ -1318,7 +1318,7 @@ void anyks::ASpell::analyze(const wstring & text, const u_short options, vector
13181318
hypotheses.at(i) = hypothesis;
13191319
}
13201320
// Добавляем список гипотез в список
1321-
pos1 = dmp.add(hypotheses, levenshtein.damerau(word, text), levenshtein.tanimoto(word, text), pos1);
1321+
pos1 = dmp.add(hypotheses, algorithms.damerau(word, text), algorithms.tanimoto(word, text), pos1);
13221322
}
13231323
}
13241324
// Если сплит выполнять не удалось

0 commit comments

Comments
 (0)