gpt4 book ai didi

Hunspell C++ 和俄语

转载 作者:行者123 更新时间:2023-12-05 08:00:55 25 4
gpt4 key购买 nike

我在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com