RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 829693
Accepted
nick_n_a
nick_n_a
Asked:2020-05-18 17:41:52 +0000 UTC2020-05-18 17:41:52 +0000 UTC 2020-05-18 17:41:52 +0000 UTC

拼写检查器库

  • 772

c++ 中是否有用于 Windows 的拼写检查库(只是单词的拼写)?

对于 Richedit,我发现EM_SETLANGOPTIONSIMF_SPELLCHECKING仅在 windows-8中启用拼写检查。并且没有“检查这个词”的功能。

在 windows-xp 中,我的 Firefox 将文本排成红色。

winxp 的操作系统中是否内置了拼写检查功能?

win7的操作系统是否内置了拼写检查?

什么是最简单的拼写检查库?我对“检查这个词”功能感兴趣,但也许还有其他概念。Edit 或 Richedit 的“附加组件”也是合适的。

c++
  • 2 2 个回答
  • 10 Views

2 个回答

  • Voted
  1. Best Answer
    Roman Prilepskiy
    2020-01-24T20:47:48Z2020-01-24T20:47:48Z

    看看JamSpell库。最初用 C++ 编写。对于JamSpell,还有针对三种语言——英语、法语、俄语——的训练拼写模型。

    使用示例:

    #include <jamspell/spell_corrector.hpp>
    
    int main(int argc, const char** argv) {
    
        NJamSpell::TSpellCorrector corrector;
        corrector.LoadLangModel("model.bin");
    
        corrector.FixFragment(L"I am the begt spell cherken!");
        // "I am the best spell checker!"
    
        corrector.GetCandidates({L"i", L"am", L"the", L"begt", L"spell", L"cherken"}, 3);
        // "best", "beat", "belt", "bet", "bent", ... )
    
        corrector.GetCandidates({L"i", L"am", L"the", L"begt", L"spell", L"cherken"}, 3);
        // "checker", "chicken", "checked", "wherein", "coherent", ... )
        return 0;
    }
    
    • 4
  2. MSDN.WhiteKnight
    2020-10-26T14:57:44Z2020-10-26T14:57:44Z

    Windows 有一个内置的拼写检查 API,但它只出现在 Windows 8 中。RichEdit 正是使用它。

    例子:

    #include <stdio.h>
    #include <stdlib.h>
    #include <exception>
    #include <locale.h>
    #include <iostream>
    #include <string>
    
    #include <windows.h>
    #include <wrl.h>
    #include <Spellcheck.h>
    
    //кидает исключение, если HRESULT является ошибкой
    inline void HR(HRESULT const result)
    {
        if (S_OK != result) {
            wprintf(L"Error HRESULT 0x%x!!!\n", (UINT)result);
            throw std::exception();
        }
    }
    
    //выполняет проверку орфографии в тексте и возвращает число ошибок
    int SpellCheck(LPCWSTR text) {
        Microsoft::WRL::ComPtr<ISpellCheckerFactory> factory;
    
        HR(CoCreateInstance(__uuidof(SpellCheckerFactory), nullptr,
            CLSCTX_INPROC_SERVER, __uuidof(factory),
            reinterpret_cast<void **>(factory.GetAddressOf())));
    
        BOOL supported = FALSE;
    
        HR(factory->IsSupported(L"ru-RU",
            &supported));
    
        if (supported == FALSE) {
            printf("Fatal error: Russian language not supported!\n");
            throw std::exception();
        }
    
        Microsoft::WRL::ComPtr<ISpellChecker> checker;
        HR(factory->CreateSpellChecker(L"ru-RU",
            checker.GetAddressOf()));
    
        int n_errors = 0;
    
        Microsoft::WRL::ComPtr<IEnumSpellingError> errors;
        HR(checker->Check(text,
            errors.GetAddressOf()));
    
        for (;;)
        {
            Microsoft::WRL::ComPtr<ISpellingError> error;
    
            if (S_OK != errors->Next(error.GetAddressOf()))
            {
                break;
            }       
    
            n_errors++;
    
            ULONG startIndex;
            HR(error->get_StartIndex(&startIndex));
    
            ULONG length;
            HR(error->get_Length(&length));
    
            std::wstring word(text + startIndex,
                text + startIndex + length);
            std::wcout << L"Ошибка в слове: " << word << std::endl;
    
            CORRECTIVE_ACTION action;
            HR(error->get_CorrectiveAction(&action));
    
    
            if (action == CORRECTIVE_ACTION_GET_SUGGESTIONS) {
                std::wcout << L" (Варианты исправления: ";
                Microsoft::WRL::ComPtr<IEnumString> suggestions;
    
                HR(checker->Suggest(word.c_str(),
                    suggestions.GetAddressOf()));
    
                for (;;)
                {
                    wchar_t * suggestion;
    
                    if (S_OK != suggestions->Next(1, &suggestion, nullptr))
                    {
                        break;
                    }
    
                    // Add the suggestion to a list for presentation
                    std::wcout << suggestion << L" ";
    
                    CoTaskMemFree(suggestion);
                }
                std::wcout << L")" << std::endl;
            }
            std::wcout  << std::endl;
        }
    
        return n_errors;
    }
    
    int main(int argc, char **argv)
    {
        setlocale(LC_ALL, "Russian");
        HR(CoInitializeEx(nullptr, COINIT_MULTITHREADED));  
    
        auto text = L"Превед, медвед!";
        std::wcout << text << std::endl;
        std::wcout << L"*********************************" << std::endl;
    
        auto res = SpellCheck(text);
    
        std::wcout << L"*********************************" << std::endl;
        std::wcout << L"Всего ошибок: " << res<< std::endl;
    
        getchar();
        return 0;
    }
    
    /*     Вывод программы:  
    
    Превед, медвед!
    *********************************
    Ошибка в слове: Превед
     (Варианты исправления: Привод Провод Приведи Приведу Приведя Правде Привад Проведи Проведу Проведя )
    
    Ошибка в слове: медвед
     (Варианты исправления: медведе медведи медведь медведю медведя медведей медведем медведка медведке медведки )
    
    *********************************
    Всего ошибок: 2
    */
    

    来源: 使用 C++ 拼写检查 API

    在 C++/CLI 中,您可以使用 WPF 中的拼写检查器,如此处所述。

    • 3

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    是否可以在 C++ 中继承类 <---> 结构?

    • 2 个回答
  • Marko Smith

    这种神经网络架构适合文本分类吗?

    • 1 个回答
  • Marko Smith

    为什么分配的工作方式不同?

    • 3 个回答
  • Marko Smith

    控制台中的光标坐标

    • 1 个回答
  • Marko Smith

    如何在 C++ 中删除类的实例?

    • 4 个回答
  • Marko Smith

    点是否属于线段的问题

    • 2 个回答
  • Marko Smith

    json结构错误

    • 1 个回答
  • Marko Smith

    ServiceWorker 中的“获取”事件

    • 1 个回答
  • Marko Smith

    c ++控制台应用程序exe文件[重复]

    • 1 个回答
  • Marko Smith

    按多列从sql表中选择

    • 1 个回答
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Suvitruf - Andrei Apanasik 什么是空? 2020-08-21 01:48:09 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5