Repository navigation
feat(query): split camelCase/snake_case identifiers as fallback - #83
Merged
Merged
Conversation
英文标识符式输入此前无法识别:`helloWorld` 归一化后被小写为 `helloworld` 而查不到,`hello_world` 因下划线不在 IsEN 字符集内落到 ch 表。现在: - 短词查询先按整体查询,未找到时把标识符拆成空格分隔词组 (如 helloWorld -> hello world),走长文本机器翻译通道展示。 - 长文本(-t)对整段中每个标识符 token 拆词重写后再翻译,重写无结果 时退回原文重试。 - 拆分规则:连续大写视为整体、下划线切分并忽略空段、单字母保留、 数字不单独成段;普通单词/词组/全大写词不触发。 不改 IsEN 判定、en/ch 表结构与 daemon 协议,短词整体查询键保持小写, 旧缓存继续命中。回退结果复用主查询的计数通道,避免 freq_alert 开启时 在长文本结果上永久阻塞。
Owner
|
感谢贡献🙏,挺实用的功能 |
Contributor
Author
|
已按建议补上配置项 关闭时短词回退与长文本拆词重写完全禁用,行为与本次改动前一致;开启后才会拆分。 辛苦再看一下🙏 |
…akecase 拆词贴近编程语境,可能影响普通查询意图,因此改为默认关闭的配置项: - Config 新增 SplitCamelcaseAndSnakecase(默认 false), toml 键为 split_camelcase_and_snakecase,会随 --generate-config 输出。 - QueryWithProgress 用该开关门控短词回退与长文本重写;关闭时行为与 该功能引入前完全一致。 - README 配置示例与说明同步,并补 config 测试覆盖默认值与生成/回读。
bighu630
force-pushed
the
feat/identifier-splitting
branch
from
September 16, 2026 03:19
3d931ae to
9c419c0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Identifier-style English input cannot be looked up:
kd helloWorld—normalizeQuerylowercases it tohelloworld, so the camel boundaries are lost and Youdao has no entry.kd hello_world— the underscore is not in theIsENcharset (^[A-Za-z0-9 -.?]+$), so it is routed to thechtable.Change
Detect camelCase/snake_case identifiers and fall back to machine translation of the space-separated words.
helloWorld->hello world).-t): rewrite every identifier token in the segment before translating; if the rewrite yields nothing, retry with the original text.HTTPServer->HTTP Server,getHTTPResponse->get HTTP Response); underscores are split with empty segments dropped (hello_world->hello world,_private->private); single letters are kept (getUserByID->get User By ID); digits stay attached to the previous segment (user2FA->user2 FA). Plain words, phrases and all-caps words are left untouched.Examples:
Compatibility
split_camelcase_and_snakecase(defaultfalse);--generate-configemits the option.IsENdetection, theen/chschema and the daemon protocol are unchanged.freq_alertdoes not block on a long-text result.Implementation notes
pkg/str:SplitIdentifier,IdentifierPhrase,RewriteIdentifiers.internal/query.goextracts the existing body intoquerySingleand adds the fallback orchestration inQueryWithProgress.Tests
Table-driven tests cover every splitting rule, the fallback decision and long-text rewriting.
gofmtclean,CGO_ENABLED=0 go test -count=1 ./...,go vet ./...andCGO_ENABLED=0 go build ./...all pass.