Files
msime-windows/engine/quanpin/engine.h
T
fanlusky e365a8d1b5 perf(engine): 大模型改为只读映射并按需载入,缩短每键查询路径
- sc.lm 改用 kenlm 的 LAZY 载入:Windows 上默认的 POPULATE_OR_READ 会退成 READ,
  把 33 MB 整份拷进私有堆且永不释放;现在是 MapViewOfFile 只读映射,可被系统回收
- dict_japanese.dat 在 Windows 上同样改为只读映射,与 POSIX 分支一致
- 神经整句模型改为开关首次生效时才载入(LazySentenceModel),默认关闭的桌面模型
  不再占用约 24 MB
- 新增 reset_sentence_cache():重排结果与上文只影响词格整句,只清 series 一层,
  逐前缀查库与切分缓存保持热;set_rescoring_context 也改用它
- CircularBuffer 新增 find():命中时返回指针而不复制整份候选列表,并改为真正的 LRU;
  全拼、双拼每键的命中路径改用它
- Google 解码器去掉每次调用前的 im_reset_search,沿用上游的公共前缀增量搜索
- 测试:出货 sc.lm 能映射载入并正常打分;增量搜索与从头搜结果逐步一致
2026-09-30 19:58:18 +08:00

42 lines
1.6 KiB
C++

#pragma once
#include "../common/helpcode_utils.h"
#include "../core/query_request.h"
#include "../core/word_item.h"
#include "../common/cache.h"
#include "quanpin_dictionary.h"
#include <string>
#include <vector>
class QuanpinEngine
{
public:
explicit QuanpinEngine(metasequoia::RuntimePaths paths = metasequoia::RuntimePaths::legacy());
~QuanpinEngine();
std::vector<WordItem> query(const QueryRequest &request);
bool expand_initial_candidates(const QueryRequest &request, std::vector<WordItem> &candidates);
std::optional<WordItem> find_candidate(const std::string &key, const std::string &value);
int handleVkCode(ImeKeyCode vk, ImeModifierMask modifiers_down, ImeCharacter wch = 0);
int create_word(std::string pinyin, std::string word);
int create_word_from_canonical_pinyin(std::string pinyin, std::string word);
int update_weight_by_word(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 insert_word_to_series_cache(const std::string &pinyin, const std::string &word, CandidateSource source);
int insert_word_to_series_cache(const QueryRequest &request, const std::string &word, CandidateSource source);
std::string search_sentence_from_ime_engine(const std::string &user_pinyin);
void reset_state();
void reset_cache();
void reset_sentence_cache();
void set_helpcode_keymap(HelpcodeUtils::SharedKeymap table)
{
helpcodes_ = std::move(table);
reset_cache();
}
private:
QuanpinDictionary dictionary_;
HelpcodeUtils::SharedKeymap helpcodes_;
};