Hunspell C++ 和俄语

标签 hunspell cyrillic

我在使用 hunspell 拼写检查器和俄语词典时遇到了一些问题。问题是我的项目与英语配合良好,但如果我要连接俄语并尝试检查我的单词的拼写,它总是返回 0(意味着没有结果)。 这是我的代码(适用于英语)

char *aff = "c:\\ru_RU.aff";
char *dic = "c:\\ru_RU.dic";
Hunspell *spellObj = new Hunspell(aff,dic);
char *words = "собака"
int result = spellObj->spell(words);

结果为“0”。可能是编码中的问题。我试过 UTF-8、KOI8-R 词典。使用 UTF-8 字典时无法读取“单词”,使用 KOI8-R 时结果为 0。

它太糟糕了,我必须让它运行良好。 附: hunspell+vs2008 c++最新版本

最佳答案

新词典通常编码为 UTF-8。在 MSYS2/mingw64 中编译的相同示例使用新的 UTF-8 词典给出了正确的 result=1

// UTF-8 file "main.cpp"
#include <iostream>
#include <hunspell.hxx>

int main()
{
char *aff = "ru_RU.aff";
char *dic = "ru_RU.dic";
Hunspell *spellObj = new Hunspell(aff,dic);
char *words = "собака";
int result = spellObj->spell(words);
std::cout << "result=" << result << std::endl;
return result;
}

使用了预编译包。安装需要在mingw64.exe环境中进入pacman -Su mingw-w64-x86_64-hunspellMakefile内容如下:

PKGS=hunspell
CFLAGS=$(shell pkg-config --cflags $(PKGS)) -std=gnu++98
LIBS=$(shell pkg-config --libs $(PKGS))
all: main
%: %.cpp
    $(CXX) $(CFLAGS) -o $@ $< $(LIBS)

关于Hunspell C++ 和俄语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16566431/

相关文章:

c# - 如何显示所有错误的单词

c# - 如何在不区分大小写的情况下检查 Hunspell 中的拼写

C++ 无法从文件中读取 UTF-8 西里尔文本

java - 如何使用 iText 在 jFreeChart 中写入西里尔字符

python - conda cythen pip pkg hunspell CyHunspell AttributeError : module 'hunspell' has no attribute 'HunSpell'

machine-learning - 拼写检查器使用语言模型

android - Android 上的 Hunspell

javascript - 将文本与塞尔维亚西里尔字母相互转换

c++ - 在不同操作系统上使用 UTF8 时的不同行为算法

java - getBytes() 不适用于西里尔字母