feat: add compound preset time rules for semantic search - #372
Conversation
1. 新增 time_last_year_month 规则,支持"去年12月""上一年三月"等预设年份+月份组合; 2. 新增 time_this_year_month 规则,支持"今年3月""本年十二月"等预设年份+月份组合; 3. 新增 time_this_week_day 规则,支持"本周三""这周五"等预设周+星期几组合; 4. 新增 time_last_week_day 规则,支持"上周一""上个星期五"等预设周+星期几组合; 5. 新增 time_this_month_day 规则,支持"本月5号""当月十五日"等预设月+日组合; 6. 新增 time_last_month_day 规则,支持"上个月15号""上月三号"等预设月+日组合; 7. 在 TimeExtractor 中新增 preset_year_month/preset_week_day/preset_month_day 三个解析分支; 8. 补充对应的单元测试覆盖所有新增规则及回归测试; ===================================== 1. added time_last_year_month rule for "last year + month" compound (e.g. 去年12月, 上一年三月); 2. added time_this_year_month rule for "this year + month" compound (e.g. 今年3月, 本年十二月); 3. added time_this_week_day rule for "this week + weekday" compound (e.g. 本周三, 这周五); 4. added time_last_week_day rule for "last week + weekday" compound (e.g. 上周一, 上个星期五); 5. added time_this_month_day rule for "this month + day" compound (e.g. 本月5号, 当月十五日); 6. added time_last_month_day rule for "last month + day" compound (e.g. 上个月15号, 上月三号); 7. added preset_year_month/preset_week_day/preset_month_day parsing branches in TimeExtractor; 8. added unit tests covering all new rules plus regression tests; Log: 为语义搜索新增预设年份+月份、预设周+星期几、预设月+日的复合时间规则,解决"去年12月创建的表格"等复合时间查询结果为空的问题 Bug: https://pms.uniontech.com/bug-view-372155.html
There was a problem hiding this comment.
Sorry @Johnson-zs, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Johnson-zs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideAdds new compound preset time rules and corresponding parsing branches so that phrases like "去年12月" are consumed as a single time span instead of leaking the month part into keywords, plus comprehensive unit and integration tests. Sequence diagram for compound preset time parsing in semantic searchsequenceDiagram
actor User
participant SemanticRuleEngine
participant TimeExtractor
participant TimeConstraint
User->>SemanticRuleEngine: submitQuery("去年12月创建的表格")
SemanticRuleEngine->>SemanticRuleEngine: match(time_rules.json)
SemanticRuleEngine->>TimeExtractor: extract(input, intent)
TimeExtractor->>TimeExtractor: parsePresetYearMonth(match, metadata, tc)
TimeExtractor->>TimeConstraint: setKind(TimeConstraintKind::Custom)
TimeExtractor->>TimeConstraint: setCustomStart(QDateTime(monthStart,...))
TimeExtractor->>TimeConstraint: setCustomEnd(QDateTime(monthEnd,...))
SemanticRuleEngine-->>User: resultsFilteredByCustomMonthSpan
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review★ 总体评分:95分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // time_rules.json 可以考虑提取公共配置,减少重复(示意)
// 虽然当前方式可行,但若规则增多,维护成本会上升
{
"definitions": {
"common_digit_map": {
"零": 0, "一": 1, "二": 2, "两": 2, "三": 3, "四": 4,
"五": 5, "六": 6, "七": 7, "八": 8, "九": 9, "十": 10
}
},
"rules": [
{
"id": "time_last_year_month",
"pattern": "(?:去年|上一年)(?<month>(?:\\d{1,2}|[零一二两三四五六七八九十]{1,3}))月份?",
"metadata": {
"type": "preset_year_month",
"preset": "last_year",
"digit_map_ref": "common_digit_map",
"tens_unit": "十"
}
}
]
} |
|
/forcemerge |
|
This pr force merged! (status: blocked) |
根因分析
输入
去年12月创建的表格搜索结果为空。根因:TimeExtractor每次只调用一次match()(返回优先级最高的单条命中),time_last_year(priority 170) 先命中去年即返回,12月不被任何时间规则消费,漏成 keyword12月,最终把"按创建时间筛选"误变成"按字面量 12月 筛选"。timeextractor.cpp:30— 单次match()只取一个时间命中semanticruleengine.cpp:124—match()命中首条即返回time_rules.json— 缺「预设年份+月份」组合规则修复方案
新增 6 条高优先级复合时间规则(priority 高于对应纯预设规则),在
TimeExtractor新增 3 个解析分支,将"预设年份+月份"、"预设周+星期几"、"预设月+日"合并为单一 Custom 时间区间:time_last_year_monthtime_this_year_monthtime_this_week_daytime_last_week_daytime_this_month_daytime_last_month_day改动安全评估
改动为纯新增(6 条 JSON 规则 + 3 个私有方法 + 3 个 type 分支),不修改任何已有函数签名、不删除公开接口、不改变
match()语义。低风险。测试
在
tst_semantic_search.cpp中补充:tst_TimeExtraction:6 个新规则的正则命中/不命中测试tst_IsSemanticQuery:7 个端到端测试(含核心回归compoundTimeNoKeywordLeak),验证复合时间被整体消费、不漏 keyword、时间区间正确Bug: https://pms.uniontech.com/bug-view-372155.html
Summary by Sourcery
Add support for compound preset time expressions in semantic search so that combined presets like year+month, week+weekday, and month+day are interpreted as single custom time ranges instead of leaking secondary components into keywords.
New Features:
Bug Fixes:
Tests: