Files
msime-windows/engine/core/ime_session.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

86 lines
4.0 KiB
C++

#pragma once
#include "composition_state.h"
#include "input_session_types.h"
#include "scheme_type.h"
#include "../providers/provider_registry.h"
#include "../schemes/input_scheme.h"
#include "../schemes/wubi_scheme.h"
#include "../shuangpin/shuangpin_profile.h"
#include <memory>
class ImeSession
{
public:
explicit ImeSession(SchemeType scheme_type = SchemeType::Shuangpin,
const ShuangpinProfile &shuangpin_profile = GetXiaoheShuangpinProfile(),
metasequoia::RuntimePaths paths = metasequoia::RuntimePaths::legacy());
void handle_key(ImeKeyCode vk, ImeModifierMask modifiers_down = 0, ImeCharacter wch = 0);
void switch_scheme(SchemeType scheme_type);
void set_shuangpin_helpcode_enabled(bool enabled);
void set_quanpin_helpcode_enabled(bool enabled);
void set_quanpin_autocorrect_types(unsigned autocorrect_types);
void set_fuzzy_pinyin_options(metasequoia::FuzzyPinyinOptions options)
{
fuzzy_pinyin_ = options;
}
void set_wubi_input_options(metasequoia::WubiInputOptions options);
void replace_shuangpin_raw_input(const std::string &raw_input, const std::string &raw_input_with_cases);
void replace_quanpin_raw_input(const std::string &raw_input, const std::string &raw_input_with_cases);
void replace_wubi_raw_input(const std::string &raw_input, const std::string &raw_input_with_cases);
void replace_japanese_raw_input(const std::string &raw_input, const std::string &raw_input_with_cases);
// Writes back to whichever scheme is composing. Committing a spelling out of a longer one
// has to shorten the live composition, and under the wubi fallback the pinyin-shaped
// caller would otherwise address a scheme that is not the active one and be ignored.
void replace_active_raw_input(const std::string &raw_input, const std::string &raw_input_with_cases);
void reset();
void reset_cache();
int create_word(std::string pinyin, std::string word);
int update_weight_by_pinyin_and_word(std::string pinyin, std::string word);
int delete_by_pinyin_and_word(std::string pinyin, std::string word);
int cache_dynamic_candidate(const std::string &pinyin, const std::string &word, CandidateSource source);
int cache_dynamic_candidate_for_current_request(const std::string &word, CandidateSource source);
int apply_dynamic_candidate(const std::string &word, CandidateSource source);
std::optional<WordItem> find_candidate(const std::string &key, const std::string &value);
SchemeType current_scheme_type() const;
const std::string &get_preedit() const;
const QueryRequest &get_request() const;
bool answered_by_pinyin_fallback() const
{
return state_.answered_by_pinyin_fallback;
}
const std::vector<WordItem> &get_candidates() const;
bool expand_initial_candidates();
void set_helpcode_keymap(HelpcodeUtils::SharedKeymap table)
{
provider_registry_.set_helpcode_keymap(std::move(table));
refresh_candidates();
}
private:
void refresh_candidates();
void bind_wubi_scheme();
SchemeType candidate_scheme() const;
std::unique_ptr<IInputScheme> create_scheme(SchemeType scheme_type) const;
private:
ProviderRegistry provider_registry_;
const ShuangpinProfile shuangpin_profile_;
std::unique_ptr<IInputScheme> scheme_;
CompositionState state_;
bool enable_shuangpin_helpcode_ = false;
bool enable_quanpin_helpcode_ = false;
unsigned quanpin_autocorrect_types_ = 0;
metasequoia::FuzzyPinyinOptions fuzzy_pinyin_;
metasequoia::WubiInputOptions wubi_options_;
// Resolved when the scheme changes rather than on every keystroke.
WubiScheme *wubi_scheme_ = nullptr;
// Once a composition has been answered by pinyin it stays with pinyin until it ends.
// Committing a spelling out of a longer one leaves a tail the wubi table may happen to
// know, and switching back mid-composition would answer a pinyin spelling with wubi.
bool composition_uses_pinyin_fallback_ = false;
};