| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- # -*- coding: utf-8 -*-
- # 规则文件:时间格式正则
- # 源:assembly/time_attrs.py 第 55-56 行 my_time_format_pattern + time_sub_pattern
- # common/attr_utils.py 第 98-101 行 extract_serviceTime() 内 pattern1-4
- # 迁移日期:2026-08-17 Phase 7 §7.6 高优先级
- version: 1
- category: TIME
- description: |
- 时间文本提取与格式化的核心正则。
- - time_format: 主时间格式(年-月-日 + 可选时分秒),含命名组 year/month/day
- - time_sub: 时间文本中需清除的括号字符
- - service_date: 完整日期(年月日)提取,用于 extract_serviceTime()
- - service_duration: 时长表达式(数字+单位),用于服务期推断
- - service_ym: 年月格式(无日),用于 extract_serviceTime() fallback
- - service_duration_rev: 倒序时长(单位在前数字在后),用于 extract_serviceTime() fallback
- patterns:
- - id: time_format
- description: |
- 主时间格式正则。支持:
- - 年份 20xx / xx / 二〇xx 中文
- - 月日阿拉伯数字或中文
- - 可选时分秒后缀
- pattern: '((?:(?P<year>20\d{2}|\d{2}|二[零〇0][零〇一二三四五六七八九0]{2})\s*[-/年.]\s*)?(?P<month>\d{1,2}|[一二三四五六七八九十]{1,3})\s*[-/月.]\s*(?P<day>\d{1,2}|[一二三四五六七八九十]{1,3}))(?:.?(?:[0-1][0-9]|2[0-4]|[0-9]):[0-5][0-9](?::[0-5][0-9])?)?'
- method: search
- named_groups:
- - year
- - month
- - day
- golden_examples:
- - input: "2024年08月15日"
- should_match: true
- - input: "2024-08-15 14:30"
- should_match: true
- - input: "08月15日"
- should_match: true
- - input: "二〇二四年八月十五日"
- should_match: true
- - input: "24.8.15"
- should_match: true
- - input: "无日期文本"
- should_match: false
- - id: time_sub
- description: 时间文本中需清除的括号字符(中英文方括号、圆括号、花括号)
- pattern: '[\[\]【】()(){}{}]+'
- method: search
- golden_examples:
- - input: "【2024年】"
- should_match: true
- - input: "(08月15日)"
- should_match: true
- - input: "2024年08月15日"
- should_match: false
- - id: service_date
- description: 完整日期格式(年-月-日),用于 extract_serviceTime() pattern1
- pattern: '\d{4}[年\-./]\d{1,2}[月\-./]\d{1,2}日?'
- method: search
- golden_examples:
- - input: "2024年08月15日"
- should_match: true
- - input: "2024-08-15"
- should_match: true
- - input: "2024.8.15"
- should_match: true
- - input: "2024年8月"
- should_match: false
- - id: service_duration
- description: |
- 时长表达式(数字在前 + 单位)。单位包括:
- 日/天/周年/整年/学年/年/月/周/日历天/工作天 等。
- pattern: '\d+(?:\.\d+)?[((]?个?[^\d]?[^\d]?(?:日|天|周年|整年|学?年|月|周|日历[天日]|工作[天日])'
- method: search
- golden_examples:
- - input: "30天"
- should_match: true
- - input: "6个月"
- should_match: true
- - input: "1.5年"
- should_match: true
- - input: "12个工作日"
- should_match: true
- - input: "无时长信息"
- should_match: false
- - id: service_ym
- description: 年月格式(无日),用于 extract_serviceTime() pattern3 fallback
- pattern: '\d{4}[年\-./]\d{1,2}月?'
- method: search
- golden_examples:
- - input: "2024年8月"
- should_match: true
- - input: "2024-08"
- should_match: true
- - input: "2024年08月15日"
- should_match: true
- - input: "无日期"
- should_match: false
- - id: service_duration_rev
- description: 倒序时长(单位在前 + 数字),用于 extract_serviceTime() pattern4 fallback
- pattern: '(?:日|天|周年|年|月|周|日历[天日]|工作[天日]|星期)[^\d]{1,3}\d+(?:\.\d+)?'
- method: search
- golden_examples:
- - input: "星期约3"
- should_match: true
- - input: "天计30"
- should_match: true
- - input: "月约6个"
- should_match: true
- - input: "30天"
- should_match: false
|