Files
msime-windows/engine/common/helpcode_utils.h
T
fanlusky a7779d2b05 refactor(engine): 将 engine 从 submodule 内嵌为仓内一等组件
`vendor/MetasequoiaImeEngine` submodule 改为 `engine/` 目录,导入的是
product-lock.json 原本钉住的提交 c810d201,逐文件核对过 blob,因此这是一次
搬迁而不是引擎升级。引擎自己的嵌套 submodule(googlepinyinime-rev、utfcpp、
miniaudio)按各自 gitlink 一并展开,来源与提交见 engine/UPSTREAM.md。

Windows 专门化裁掉了不属于本产品的部分:whisper.cpp 与本地推理 provider、
macOS 示例宿主、整个 dictionary/ 建库流水线、上游 CI 与 release-please 配置。
词库仍按 product-lock.json 在构建时取发布产物。

引擎不再进 product-lock.json:没有 gitlink 就没有可比对的东西,锁里写一个上游
commit 等于宣称这棵树仍等于上游,而第一个 Windows 专门化改动落地时这句话就假了。
verify-contracts / verify-checkout 随之移除,verify-published 保留。

CI 与工具链:引擎源码并入根 scripts/format.sh(删掉引擎自己的那份,避免两套排除
列表分叉);引擎 voice.yml 里的 silero_vad.onnx 摘要校验移到本仓 lock job;
engine-bump-triage 工作流与其测试删除;gitsubmodule 的 dependabot 频率由 daily
改为 monthly。

README、README.en、AGENTS.md、CONTRIBUTING、docs/product-release.md 及各子目录
文档同步说明新的位置与边界。
2026-09-12 03:40:48 +08:00

104 lines
3.6 KiB
C++

#pragma once
#include <string>
#include <filesystem>
#include <memory>
#include <unordered_map>
#include <vector>
namespace HelpcodeUtils
{
using Keymap = std::unordered_map<std::string, std::string>;
using SharedKeymap = std::shared_ptr<const Keymap>;
SharedKeymap load_helpcode_keymap(const std::filesystem::path &resources, const std::string &schema);
std::string selected_helpcode_schema();
const Keymap &helpcode_keymap();
bool is_supported_helpcode_schema(const std::string &schema);
bool select_helpcode_schema(const std::string &schema);
std::string get_first_han_char(const std::string &words);
std::string get_last_han_char(const std::string &words);
std::string::size_type count_han_chars(const std::string &words);
std::string::size_type count_utf8_chars(const std::string &text);
std::string compute_helpcodes(const std::string &words, bool uppercase_all = false, const Keymap *keymap = nullptr);
bool is_quanpin_single_help_mode(const std::string &pinyin_with_cases);
bool is_quanpin_double_help_mode(const std::string &pinyin_with_cases);
enum class SingleHelpcodeMatch
{
None,
First,
Last,
Both,
};
SingleHelpcodeMatch match_single_helpcode(const std::string &word, const std::string &help_code,
const Keymap *keymap = nullptr);
bool matches_double_helpcodes(const std::string &word, const std::string &help_codes, const Keymap *keymap = nullptr);
template <typename TWordItem>
std::vector<TWordItem> reorder_candidates_with_single_helpcode(const std::vector<TWordItem> &candidate_list,
const std::string &help_code,
const Keymap *keymap = nullptr)
{
if (help_code.size() != 1)
{
return candidate_list;
}
std::vector<TWordItem> first_helpcode_matched_list;
std::vector<TWordItem> last_helpcode_matched_list;
std::vector<TWordItem> left_helpcode_matched_list;
std::vector<TWordItem> result_list;
for (const auto &cand : candidate_list)
{
switch (match_single_helpcode(cand.word, help_code, keymap))
{
case SingleHelpcodeMatch::First:
first_helpcode_matched_list.push_back(cand);
break;
case SingleHelpcodeMatch::Last:
last_helpcode_matched_list.push_back(cand);
break;
case SingleHelpcodeMatch::Both:
first_helpcode_matched_list.push_back(cand);
break;
case SingleHelpcodeMatch::None:
left_helpcode_matched_list.push_back(cand);
break;
}
}
result_list.insert(result_list.end(), first_helpcode_matched_list.begin(), first_helpcode_matched_list.end());
result_list.insert(result_list.end(), last_helpcode_matched_list.begin(), last_helpcode_matched_list.end());
result_list.insert(result_list.end(), left_helpcode_matched_list.begin(), left_helpcode_matched_list.end());
return result_list;
}
template <typename TWordItem>
std::vector<TWordItem> filter_candidates_with_double_helpcodes(const std::vector<TWordItem> &candidate_list,
const std::string &help_codes,
const Keymap *keymap = nullptr)
{
std::vector<TWordItem> filtered_list;
if (help_codes.size() != 2)
{
return filtered_list;
}
for (const auto &cand : candidate_list)
{
if (matches_double_helpcodes(cand.word, help_codes, keymap))
{
filtered_list.push_back(cand);
}
}
return filtered_list;
}
} // namespace HelpcodeUtils