Files
msime-windows/engine/core/query_request.h
T
Lu Fan(SonnyCalcr) 5208753ce8 feat: 句中辅助码新增大写字母触发方式 (#620)
* feat(engine): add uppercase trigger for shuangpin mid-sentence helpcode

With the uppercase trigger on, an uppercase letter right after a complete
two-key syllable opens a mid-sentence helpcode block by itself, as if the
backtick had been typed before it: ulpbXihfa is ulpb`xihfa, and a following
uppercase letter is still the second code (ulpbXYih is ulpb`xYih). The raw
input keeps the typed letters; the block rules live in
contracts/mid_sentence_helpcode.h so TSF, Server and engine parse alike,
including the semicolon final, which no longer counts uppercase blocks.

The scheme now hands the parsed layout (source index and decorations) to the
request, so selection advance and preedit no longer re-parse the raw input.
Adds the MidSentenceHelpcodeUppercaseChanged worker opcode (31).

* feat(windows): count uppercase helpcode blocks before backtick and semicolon

With MidSentenceHelpcodeUppercaseChanged on, TSF uses the shared block rules
when deciding whether '`' opens a block and whether ';' is the ing final, in
both the synchronous and the deferred key classification.

* feat(server): wire the mid-sentence helpcode uppercase trigger

New helpcode.shuangpin_mid_sentence_helpcode_uppercase (default off) in both
config templates, both settings hosts and the settings page as a third
trigger checkbox. It takes effect only with mid-sentence helpcode on and
direct helpcode off; the Server applies it to the semicolon final rule and
broadcasts MidSentenceHelpcodeUppercaseChanged to TSF.
2026-10-04 21:00:41 +08:00

66 lines
3.5 KiB
C++

#pragma once
#include "key_event.h"
#include "fuzzy_pinyin_options.h"
#include "scheme_type.h"
#include "sentence_association_options.h"
#include "syllable_helpcode.h"
#include <cstddef>
#include <string>
#include <utility>
#include <vector>
struct KeyStroke
{
ImeKeyCode vk = 0;
ImeModifierMask modifiers_down = 0;
ImeCharacter wch = 0;
};
struct QueryRequest
{
SchemeType scheme = SchemeType::Quanpin;
std::string raw_input;
std::string raw_input_with_cases;
std::string normalized_input;
std::string raw_segmentation;
std::string normalized_segmentation;
std::string segmentation;
bool enable_shuangpin_helpcode = false;
bool enable_quanpin_helpcode = false;
// 句中辅助码,见 syllable_helpcode.h。输入串里带反引号段时,raw_input / raw_input_with_cases /
// 各切分都是把每段换成一个 ' 之后的结果,下游按普通手动分隔来切分、推进;原样的输入串放在
// raw_input_with_syllable_helpcodes,宿主回读输入串、显示预编辑时用它。没有反引号段时两者
// 都为空。syllable_helpcodes 不受开关影响(开关只管能不能敲进去),由开关决定是否参与筛选。
bool enable_mid_sentence_helpcode = false;
std::string raw_input_with_syllable_helpcodes;
SyllableHelpcodes syllable_helpcodes;
// 去段串(raw_input_with_cases)到原串(raw_input_with_syllable_helpcodes)的下标映射,末尾多一项
// 等于原串长度;以及每段原样的辅码文本挂在哪个音节后面。下游推进选词、显示预编辑时直接用它,
// 不再从原串反推:反推要知道当时的触发规则(大写触发开没开),而直接辅助码的原串里根本没有段
// 标记,切分是解析器整句解码选出来的。由方案层(反引号段、大写段)或直接辅助码的解析器填写。
bool has_syllable_helpcode_layout = false;
std::vector<std::size_t> syllable_helpcode_source_index;
std::vector<std::pair<std::size_t, std::string>> syllable_helpcode_decorations;
// 会话开着直接辅助码(不论这次请求有没有被改写)。词典层据此让词格与解析器共用一份跨度查询缓存。
bool enable_direct_helpcode = false;
// Autocorrection is type-gated (bit0 transposition, bit1 neighbor in the session-level
// mask); both default off, so a fresh install never rewrites the user's spelling.
bool enable_quanpin_autocorrect_transposition = false;
bool enable_quanpin_autocorrect_neighbor = false;
std::vector<KeyStroke> key_strokes;
metasequoia::FuzzyPinyinOptions fuzzy_pinyin;
// 整句候选来源与去重补位选项,默认全关。
SentenceAssociationOptions sentence_association;
// 给神经重排看的前文:本会话最近上屏的文本。空着也能重排,只是模型看不到语境,「shanghai」
// 到底是上海还是伤害就只能靠词格自己的静态分。词典层只取末尾若干字(RerankOptions::
// context_chars),所以这里给多了也无妨。
std::string rescoring_context;
// Wubi wildcard mode and the code in hand holds a z: the provider matches the code as a
// pattern (z = one arbitrary letter) instead of a prefix range. Never set for other schemes.
// With mixed input also on, the same z is offered to pinyin as a plain letter and those
// candidates are placed ahead of the wildcard rows (see ImeSession::refresh_candidates).
bool wubi_z_wildcard = false;
bool valid = false;
};