Skip to content

Commit

Permalink
Add tests for dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
K0R0L committed Feb 29, 2024
1 parent ec2687e commit f5ee86c
Show file tree
Hide file tree
Showing 50 changed files with 8,112 additions and 0 deletions.
131 changes: 131 additions & 0 deletions Common/3dParty/hunspell/test/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/

#include "../../../../Common/3dParty/hunspell/hunspell/src/hunspell/hunspell.h"
#include "../../../../DesktopEditor/common/StringExt.h"
#include "../../../../DesktopEditor/common/Directory.h"

bool CheckCaret(std::vector<std::wstring>& words)
{
bool bIsCaret = false;
for (int i = 0, len = (int)words.size(); i < len; ++i)
{
if (words[i].find('\r') == (words[i].length() - 1))
{
words[i] = words[i].substr(0, words[i].length() - 1);
bIsCaret = true;
}
}
return bIsCaret;
}

std::wstring CheckWord(Hunhandle* pDic, const std::wstring& sWord, const bool& bIsCaret)
{
std::wstring sResult = sWord;

std::string sWordA = U_TO_UTF8(sWord);
int nSpellResult = Hunspell_spell(pDic, sWordA.c_str());

if (0 == nSpellResult)
{
char** pSuggest;
int nSuggestCount = Hunspell_suggest(pDic, &pSuggest, sWordA.c_str());

sResult += L" [";

for (int i = 0; i < nSuggestCount; ++i)
{
std::string sSuggestA(pSuggest[i], strlen(pSuggest[i]));
std::wstring sSuggest = UTF8_TO_U(sSuggestA);

sResult += sSuggest;
if (i != (nSuggestCount - 1))
sResult += (L", ");
}

if (0 < nSuggestCount)
Hunspell_free_list(pDic, &pSuggest, nSuggestCount);

sResult += L"]";
}

if (bIsCaret)
sResult += L"\r";
sResult += L"\n";

return sResult;
}

int main(int argc, char *argv[])
{
std::wstring sSrcDir = NSFile::GetProcessDirectory() + L"/../src";
std::wstring sDstDir = NSFile::GetProcessDirectory() + L"/../dst";
std::wstring sDictionariesDir = NSFile::GetProcessDirectory() + L"/../../../../../../dictionaries";
std::vector<std::wstring> arSrcFiles = NSDirectory::GetFiles(sSrcDir);

for (int i = 0, len = (int)arSrcFiles.size(); i < len; ++i)
{
std::wstring sFileWords = arSrcFiles[i];
std::wstring sName = NSFile::GetFileName(sFileWords);
std::wstring::size_type sNamePos = sName.find(L".");
if (std::wstring::npos != sNamePos)
sName = sName.substr(0, sNamePos);

std::wstring sFileWordsContent = L"";
NSFile::CFileBinary::ReadAllTextUtf8(sFileWords, sFileWordsContent);

std::vector<std::wstring> arWords = NSStringExt::Split(sFileWordsContent, '\n');
bool bIsCaret = CheckCaret(arWords);

std::wstring sAff = sDictionariesDir + L"/" + sName + L"/" + sName + L".aff";
std::wstring sDic = sDictionariesDir + L"/" + sName + L"/" + sName + L".dic";

std::string sAffA = U_TO_UTF8(sAff);
std::string sDicA = U_TO_UTF8(sDic);

Hunhandle* pDictionary = Hunspell_create(sAffA.c_str(), sDicA.c_str());

std::wstring sFileDst = sDstDir + L"/" + sName + L".txt";

std::wstring sResult = L"";
for (const std::wstring& word : arWords)
{
sResult += CheckWord(pDictionary, word, bIsCaret);
}

Hunspell_destroy(pDictionary);

NSFile::CFileBinary::SaveToFile(sFileDst, sResult, true);
}

return 0;
}
213 changes: 213 additions & 0 deletions Common/3dParty/hunspell/test/src/az_Latn_AZ.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
A
qocalmaq
Alderaan'ın
hamısı
həmçinin
cavab
dir
incəsənət
kimi
da
uzaq
körpə
zirzəmi
ol
olub
doğuldu
bulvar
fasilə
nəsllər
gəlin
lakin
al
ilə
Kaliforniya
Kalifornikasiya
bilər
kartlar
şans
Çin
çənə
klublar
Cobain
bürc
nəzarət
qiymət
edə bilməzdim
yaratmaq
lənət
rəqs
saziş
sövdələşmələr
dağıdıcı
almazlar
etməz
etməyərik
arzu
xülyalar
Şərq
kənar
kənarları
məmnunluq
hamının
uzaq
peri
solğun
üz
son
tap
ilk
üçün
-dan
sərhəd
qız
qızın
yaxşı
gitara
əl
hardcore
var
yoxdur
o
eşitmək
ürək
O'nun
ona
gizli
yüksək
ona
onun
Hollivud
Mən
Mənəm
əgər
içində
məlumat
içində
dir
bu
jack
sadəcə
kral
qohum
bilmək
qoyulmuş
qanun
yerləşdirilmək
qurğuşun
aparmaq
yerləşdirilmə
məkan
sevmək
şans
edilmiş
adam
çox
Evlənmək
maska
o bilər
bəlkə də
mənası
mən
meditasiya
xatirə
ağılın
pul
mənim
heç vaxt
deyil
heç nə
nömrələr
of
of
üstündə
bir
yalnız
və ya
nəticə
öz
Ödə
Şəftəli
yerlər
oynayır
oynamaq
əhali
porno
tərifləmək
ehtimal ki
ehtimal
psixik
kraliça
qaldırmaq
qalan
hörmət
qalxmaq
yol
xam
müqəddəs
Xilas et
elmi
çığırmaq
satılır
şəkil
xəstələnmək
gümüşçü
dəri
əsgər
bir şey
Mahnı
mahnılar
qılınclar
büyü
casuslar
ulduz
Stansiya
oğurlamaq
daşlar
günəş
şübhəli
İsveç
qılınclar
yeniyetmə
test
dandan
bu ki
bu ki
bu
onların
bu
onlar
düşünmək
bu
onlar
gel-git
üçün
deyilmişəm
çox
cəhd et
başa düşdüm
qilin
titrəmək
mübarizə aparır?
istəyirəm
müharibə
idi
dalğalar
geymək
silahlar
yaxşı
idarə olunan
Qərbi
arasında
qalib gəlmək
qalib gəlir
ilə
qadın
dünya
səhv
siz
sizə
sənsən
sənin
Loading

0 comments on commit f5ee86c

Please sign in to comment.