`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 及各子目录 文档同步说明新的位置与边界。
127 lines
3.2 KiB
C++
127 lines
3.2 KiB
C++
#include "wubi_candidate_provider.h"
|
|
#include "../quanpin/quanpin_query.h"
|
|
#include <spdlog/spdlog.h>
|
|
#include <utility>
|
|
|
|
namespace
|
|
{
|
|
constexpr int kNoMutation = 0;
|
|
}
|
|
|
|
WubiCandidateProvider::WubiCandidateProvider(std::string db_path)
|
|
: db_path_(db_path.empty() ? quanpin::get_default_db_path() : std::move(db_path))
|
|
{
|
|
}
|
|
|
|
WubiCandidateProvider::~WubiCandidateProvider()
|
|
{
|
|
close_database();
|
|
}
|
|
|
|
std::vector<WordItem> WubiCandidateProvider::query(const QueryRequest &request)
|
|
{
|
|
if (!request.valid || request.scheme != SchemeType::Wubi || request.normalized_input.empty() ||
|
|
!ensure_query_statement())
|
|
{
|
|
return {};
|
|
}
|
|
|
|
sqlite3_reset(query_statement_);
|
|
sqlite3_clear_bindings(query_statement_);
|
|
if (sqlite3_bind_text(query_statement_, 1, request.normalized_input.c_str(), -1, SQLITE_TRANSIENT) != SQLITE_OK)
|
|
{
|
|
return {};
|
|
}
|
|
|
|
std::vector<WordItem> candidates;
|
|
int result = SQLITE_ROW;
|
|
while ((result = sqlite3_step(query_statement_)) == SQLITE_ROW)
|
|
{
|
|
const auto *key = reinterpret_cast<const char *>(sqlite3_column_text(query_statement_, 0));
|
|
const auto *value = reinterpret_cast<const char *>(sqlite3_column_text(query_statement_, 1));
|
|
if (key == nullptr || value == nullptr)
|
|
{
|
|
continue;
|
|
}
|
|
candidates.emplace_back(key, value, sqlite3_column_int64(query_statement_, 2));
|
|
}
|
|
|
|
if (result != SQLITE_DONE)
|
|
{
|
|
(void)0;
|
|
return {};
|
|
}
|
|
return candidates;
|
|
}
|
|
|
|
void WubiCandidateProvider::reset_cache()
|
|
{
|
|
close_database();
|
|
}
|
|
|
|
int WubiCandidateProvider::create_word(SchemeType, std::string, std::string)
|
|
{
|
|
return kNoMutation;
|
|
}
|
|
|
|
int WubiCandidateProvider::update_weight_by_pinyin_and_word(SchemeType, std::string, std::string)
|
|
{
|
|
return kNoMutation;
|
|
}
|
|
|
|
int WubiCandidateProvider::delete_by_pinyin_and_word(SchemeType, std::string, std::string)
|
|
{
|
|
return kNoMutation;
|
|
}
|
|
|
|
int WubiCandidateProvider::cache_dynamic_candidate(SchemeType, const std::string &, const std::string &,
|
|
CandidateSource)
|
|
{
|
|
return kNoMutation;
|
|
}
|
|
|
|
int WubiCandidateProvider::cache_dynamic_candidate_for_request(const QueryRequest &, const std::string &,
|
|
CandidateSource)
|
|
{
|
|
return kNoMutation;
|
|
}
|
|
|
|
bool WubiCandidateProvider::ensure_query_statement()
|
|
{
|
|
if (query_statement_ != nullptr)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (db_ == nullptr && sqlite3_open_v2(db_path_.c_str(), &db_, SQLITE_OPEN_READONLY, nullptr) != SQLITE_OK)
|
|
{
|
|
(void)0;
|
|
close_database();
|
|
return false;
|
|
}
|
|
|
|
constexpr const char *query_sql = "SELECT \"key\", \"value\", \"weight\" FROM wubi86 "
|
|
"WHERE \"key\" = ?1 ORDER BY \"weight\" DESC, rowid ASC";
|
|
if (sqlite3_prepare_v2(db_, query_sql, -1, &query_statement_, nullptr) != SQLITE_OK)
|
|
{
|
|
(void)0;
|
|
close_database();
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void WubiCandidateProvider::close_database()
|
|
{
|
|
if (query_statement_ != nullptr)
|
|
{
|
|
sqlite3_finalize(query_statement_);
|
|
query_statement_ = nullptr;
|
|
}
|
|
if (db_ != nullptr)
|
|
{
|
|
sqlite3_close(db_);
|
|
db_ = nullptr;
|
|
}
|
|
}
|