`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 及各子目录 文档同步说明新的位置与边界。
134 lines
4.8 KiB
C++
134 lines
4.8 KiB
C++
#include "pinyin_candidate_provider.h"
|
|
#include "../core/scheme_type.h"
|
|
#include "../shuangpin/shuangpin_query.h"
|
|
#include "../shuangpin/shuangpin_utils.h"
|
|
|
|
PinyinCandidateProvider::PinyinCandidateProvider(const ShuangpinProfile &shuangpin_profile,
|
|
metasequoia::RuntimePaths paths)
|
|
: shuangpin_profile_(shuangpin_profile), quanpin_engine_(paths), shuangpin_engine_(shuangpin_profile, paths)
|
|
{
|
|
}
|
|
|
|
std::vector<WordItem> PinyinCandidateProvider::query(const QueryRequest &request)
|
|
{
|
|
if (!request.valid)
|
|
{
|
|
return {};
|
|
}
|
|
|
|
if (request.scheme == SchemeType::Shuangpin)
|
|
{
|
|
return shuangpin_engine_.query(request);
|
|
}
|
|
|
|
if (request.scheme == SchemeType::Quanpin)
|
|
{
|
|
return quanpin_engine_.query(request);
|
|
}
|
|
|
|
return {};
|
|
}
|
|
|
|
bool PinyinCandidateProvider::expand_initial_candidates(const QueryRequest &request, std::vector<WordItem> &candidates)
|
|
{
|
|
if (request.scheme == SchemeType::Shuangpin)
|
|
{
|
|
return shuangpin_engine_.expand_initial_candidates(request, candidates);
|
|
}
|
|
if (request.scheme == SchemeType::Quanpin)
|
|
{
|
|
return quanpin_engine_.expand_initial_candidates(request, candidates);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void PinyinCandidateProvider::reset_cache()
|
|
{
|
|
quanpin_engine_.reset_cache();
|
|
shuangpin_engine_.reset_cache();
|
|
}
|
|
|
|
int PinyinCandidateProvider::create_word(SchemeType scheme, std::string pinyin, std::string word)
|
|
{
|
|
if (scheme == SchemeType::Shuangpin)
|
|
{
|
|
return shuangpin_engine_.create_word(std::move(pinyin), std::move(word));
|
|
}
|
|
return quanpin_engine_.create_word(std::move(pinyin), std::move(word));
|
|
}
|
|
|
|
int PinyinCandidateProvider::update_weight_by_pinyin_and_word(SchemeType scheme, std::string pinyin, std::string word)
|
|
{
|
|
if (scheme == SchemeType::Shuangpin)
|
|
{
|
|
return shuangpin_engine_.update_weight_by_pinyin_and_word(std::move(pinyin), std::move(word));
|
|
}
|
|
return quanpin_engine_.update_weight_by_pinyin_and_word(std::move(pinyin), std::move(word));
|
|
}
|
|
|
|
int PinyinCandidateProvider::delete_by_pinyin_and_word(SchemeType scheme, std::string pinyin, std::string word)
|
|
{
|
|
if (scheme == SchemeType::Shuangpin)
|
|
{
|
|
return shuangpin_engine_.delete_by_pinyin_and_word(std::move(pinyin), std::move(word));
|
|
}
|
|
return quanpin_engine_.delete_by_pinyin_and_word(std::move(pinyin), std::move(word));
|
|
}
|
|
|
|
int PinyinCandidateProvider::cache_dynamic_candidate(SchemeType scheme, const std::string &pinyin,
|
|
const std::string &word, CandidateSource source)
|
|
{
|
|
if (scheme == SchemeType::Shuangpin)
|
|
{
|
|
return shuangpin_engine_.insert_word_to_series_cache(pinyin, word, source);
|
|
}
|
|
return quanpin_engine_.insert_word_to_series_cache(pinyin, word, source);
|
|
}
|
|
|
|
std::optional<WordItem> PinyinCandidateProvider::find_candidate(SchemeType scheme, const std::string &key,
|
|
const std::string &value)
|
|
{
|
|
return scheme == SchemeType::Shuangpin ? shuangpin_engine_.find_candidate(key, value)
|
|
: quanpin_engine_.find_candidate(key, value);
|
|
}
|
|
|
|
int PinyinCandidateProvider::cache_dynamic_candidate_for_request(const QueryRequest &request, const std::string &word,
|
|
CandidateSource source)
|
|
{
|
|
if (request.scheme == SchemeType::Quanpin)
|
|
{
|
|
return quanpin_engine_.insert_word_to_series_cache(request, word, source);
|
|
}
|
|
|
|
if (request.scheme != SchemeType::Shuangpin)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
if (!request.enable_shuangpin_helpcode)
|
|
{
|
|
return shuangpin_engine_.insert_word_to_series_cache(request.raw_input, word, source);
|
|
}
|
|
|
|
const std::string &raw_input_with_cases =
|
|
request.raw_input_with_cases.empty() ? request.raw_input : request.raw_input_with_cases;
|
|
const std::string pure_input = shuangpin::remove_manual_delimiters(request.raw_input);
|
|
const std::string pure_input_with_cases = shuangpin::remove_manual_delimiters(raw_input_with_cases);
|
|
if (ShuangpinUtil::IsFullHelpMode(pure_input_with_cases, shuangpin_profile_))
|
|
{
|
|
return shuangpin_engine_.insert_word_to_active_helpcode_cache(request.raw_input, word, source);
|
|
}
|
|
|
|
if (pure_input.size() % 2 == 1 && pure_input.size() > 1)
|
|
{
|
|
const std::string base_raw_input = pure_input.substr(0, pure_input.size() - 1);
|
|
const std::string base_raw_segmentation = shuangpin::segment_input(base_raw_input, shuangpin_profile_);
|
|
if (ShuangpinUtil::is_all_complete_pinyin(base_raw_input, base_raw_segmentation))
|
|
{
|
|
return shuangpin_engine_.insert_word_to_active_helpcode_cache(request.raw_input, word, source);
|
|
}
|
|
}
|
|
|
|
return shuangpin_engine_.insert_word_to_series_cache(request.raw_input, word, source);
|
|
}
|