{ "$schema": "http://json-schema.org/draft-07/schema#", "$id": "pattern_schema.json", "title": "BiddingKG 正则规则 YAML Schema", "description": "定义 dl/rules/patterns/*.yaml 的合法结构", "type": "object", "definitions": { "condition": { "type": "object", "description": "结构化条件(Phase C 机器可读 guard DSL):guard 列表内 AND 组合,guard_not 列表内 OR 组合(任一命中则跳过规则),or_trigger 列表内 OR 组合(任一命中则规则触发,无需 pattern 匹配)", "required": ["type"], "properties": { "type": { "type": "string", "description": "条件类型:regex=切片上 re.search;regex_not=切片上 re.search 不命中;match=切片上 re.match;is_agency/not_is_agency=实体名是否命中代理机构词典;value_lt=values[index] < threshold;notes_in=entity.notes ∈ values;any/of、all/of=嵌套组合;count_eq=len(re.findall(pattern)) == equals", "enum": ["regex", "regex_not", "match", "is_agency", "not_is_agency", "value_lt", "notes_in", "any", "all", "count_eq"] }, "on": { "type": "string", "description": "求值目标切片:front=实体前文,behind=实体后文,whole=前文+实体+后文,entity_text=实体文本,title=公告标题,content=正文全文,content_head=正文前 size 字,title_content_head=标题+正文前 size 字", "enum": ["front", "behind", "whole", "entity_text", "title", "content", "content_head", "title_content_head"] }, "pattern": { "type": "string", "description": "条件正则(regex/regex_not/match/count_eq 类型必填)" }, "size": { "type": "integer", "description": "切片截断长度(front 取末 size 字,behind/content_head/title_content_head 取前 size 字;缺省不截断)", "minimum": 1 }, "index": { "type": "integer", "description": "values 数组下标(value_lt 用)", "minimum": 0, "maximum": 5 }, "threshold": { "type": "number", "description": "比较阈值(value_lt 用)", "minimum": 0, "maximum": 1 }, "values": { "type": "array", "description": "候选值列表(notes_in 用)", "items": {"type": "string"}, "minItems": 1 }, "equals": { "type": "integer", "description": "期望的 findall 计数(count_eq 用)", "minimum": 0 }, "of": { "type": "array", "description": "嵌套子条件列表(any/all 用)", "items": {"$ref": "#/definitions/condition"}, "minItems": 1 } }, "additionalProperties": false }, "set_prob_action": { "type": "object", "description": "概率改写动作(Phase C 机器可读):values[index] = value。index 缺省 = set_label(若有)否则当前 label", "required": ["value"], "properties": { "value": { "type": "number", "description": "写入的概率值", "minimum": 0, "maximum": 1 }, "index": { "type": "integer", "description": "values 数组下标;缺省时取 set_label(若规则声明)否则当前 label", "minimum": 0, "maximum": 5 } }, "additionalProperties": false } }, "required": ["version", "category"], "anyOf": [ {"required": ["patterns"]}, {"required": ["keyword_rules"]} ], "properties": { "version": { "type": "integer", "description": "规则文件版本号,当前为 1", "const": 1 }, "category": { "type": "string", "description": "规则类别", "enum": ["PACKAGE", "TIME", "MONEY", "CONTACT", "BIDWAY", "FAILURE", "RANK", "ROLE", "OTHER"] }, "description": { "type": "string", "description": "规则文件描述" }, "patterns": { "type": "array", "description": "正则规则列表", "items": { "type": "object", "required": ["id", "pattern"], "properties": { "id": { "type": "string", "description": "规则唯一标识,用于 loader.get_pattern(id) 查找", "pattern": "^[a-z][a-z0-9_]*$" }, "description": { "type": "string", "description": "规则用途说明" }, "pattern": { "type": "string", "description": "正则表达式字符串" }, "method": { "type": "string", "description": "匹配方法:search=搜索, match=头部匹配, fullmatch=全串匹配", "enum": ["search", "match", "fullmatch"], "default": "search" }, "flags": { "type": "array", "description": "正则标志", "items": { "type": "string", "enum": ["IGNORECASE", "MULTILINE", "DOTALL", "UNICODE", "VERBOSE"] }, "uniqueItems": true }, "named_groups": { "type": "array", "description": "命名捕获组列表(文档用途,不参与编译)", "items": {"type": "string"} }, "role": { "type": "string", "description": "召回/修正的目标角色标签(ROLE 类规则用):tenderee=招标人, agency=代理机构, winTenderer=中标人, secondTenderer=第二候选人, thirdTenderer=第三候选人, other=其他", "enum": ["tenderee", "agency", "winTenderer", "secondTenderer", "thirdTenderer", "other"] }, "prob": { "type": "number", "description": "命中后赋予的召回概率权重(ROLE 召回规则用,0-1)", "minimum": 0, "maximum": 1 }, "applies_to": { "type": "string", "description": "规则匹配的上下文切片位置(ROLE 类规则用):front=实体前文, behind=实体后文, whole=前后文拼接, title=公告标题(doc_title 阶段用)", "enum": ["front", "behind", "whole", "title"] }, "priority": { "type": "integer", "description": "执行优先级(数字越大越先执行,同文件内用于表达原代码的串行顺序;可选)", "minimum": 0, "maximum": 999 }, "stage": { "type": "string", "description": "执行阶段(Phase C RoleRuleEngine 用):引擎按 stage 分组、按固定阶段序执行,同阶段内首条命中规则生效(对应原 elif 链短路)。角色修正:global_pre/seq_check/l0/l2/l5_win_yes/notify/l1/l34/l5;金额修正:m1/m0/m_bid/doc_title", "pattern": "^[a-z][a-z0-9_]*$" }, "window": { "type": "object", "description": "applies_to 切片的机器可读截断(front 取末 size 字,behind 取前 size 字),对应原代码 front[-N:]/behind[:N]", "required": ["size"], "properties": { "size": { "type": "integer", "description": "截断长度(字符)", "minimum": 1 } }, "additionalProperties": false }, "model_labels": { "type": "array", "description": "修正规则适用的模型预测标签列表(label 改写规则用):0=tenderee,1=agency,2=winTenderer,3=secondTenderer,4=thirdTenderer,5=other", "items": {"type": "integer", "minimum": 0, "maximum": 5} }, "set_label": { "type": "integer", "description": "命中后改写的角色标签(修正规则用)", "minimum": 0, "maximum": 5 }, "set_prob": { "$ref": "#/definitions/set_prob_action" }, "guard": { "type": "array", "description": "附加条件列表(AND 组合,全部满足规则才生效;Phase C 起参与引擎执行)", "items": {"$ref": "#/definitions/condition"} }, "guard_not": { "type": "array", "description": "排除条件列表(OR 组合,任一命中则规则不生效)", "items": {"$ref": "#/definitions/condition"} }, "or_trigger": { "type": "array", "description": "替代触发条件列表(OR 组合,任一命中则规则生效,无需 pattern 匹配)", "items": {"$ref": "#/definitions/condition"} }, "entity_filter": { "type": "object", "description": "实体过滤条件(doc_title 阶段批量修正用):仅满足全部过滤条件的实体参与规则", "properties": { "entity_type": { "type": "string", "description": "实体类型,如 money" }, "notes_in": { "type": "array", "description": "entity.notes ∈ 列表", "items": {"type": "string"}, "minItems": 1 }, "label": { "type": "integer", "description": "实体当前标签", "minimum": 0, "maximum": 5 } }, "additionalProperties": false }, "golden_examples": { "type": "array", "description": "黄金样例(正例和负例)", "items": { "type": "object", "required": ["input", "should_match"], "properties": { "input": {"type": "string", "description": "测试输入文本"}, "should_match": {"type": "boolean", "description": "true=应匹配, false=不应匹配"}, "expected_group": { "type": "string", "description": "期望的匹配组 0 内容(可选)" }, "expected_named_groups": { "type": "object", "description": "期望的命名捕获组键值对(可选)" } } } } }, "additionalProperties": false } }, "keyword_rules": { "type": "array", "description": "关键词分类规则列表(用于 turnMoneySource 等关键词驱动分类)", "items": { "type": "object", "required": ["id", "label", "keywords"], "properties": { "id": { "type": "string", "pattern": "^[a-z][a-z0-9_]*$" }, "label": { "type": "string", "description": "匹配后输出的分类标签" }, "keywords": { "type": "array", "description": "正向关键词列表(任一命中即归类)", "items": {"type": "string"}, "minItems": 1 }, "excludes": { "type": "array", "description": "排除关键词(任一命中则不归类)", "items": {"type": "string"} }, "priority": { "type": "integer", "description": "优先级(数字越大越优先,默认 0)", "default": 0 } }, "additionalProperties": false } }, "classifier_config": { "type": "object", "description": "分类器配置(用于关键词分类规则的全局参数)", "properties": { "min_matches": { "type": "integer", "description": "最少命中数(低于此数返回默认标签)", "default": 1 }, "max_matches": { "type": "integer", "description": "最多命中数(超过此数返回默认标签)", "default": 99 }, "default_label": { "type": "string", "description": "默认标签(未命中或超出范围时返回)", "default": "" }, "separator": { "type": "string", "description": "多标签连接符", "default": "," }, "sort": { "type": "boolean", "description": "是否对结果排序", "default": true } }, "additionalProperties": false }, "probability_ladder": { "type": "object", "description": "概率阶梯(ROLE 类规则用):命名原代码中的魔法概率,须与 predictors/role_context.py 中常量一致", "properties": { "p_model_threshold": { "type": "number", "description": "模型置信阈值:prob < 此值时置 label=5 交给规则召回", "minimum": 0, "maximum": 1 }, "p_rule_override": { "type": "number", "description": "规则覆盖模型(略高于模型置信)", "minimum": 0, "maximum": 1 }, "p_fallback": { "type": "number", "description": "兜底召回(略高于标题召回基线)", "minimum": 0, "maximum": 1 }, "p_title": { "type": "number", "description": "标题召回基线", "minimum": 0, "maximum": 1 } }, "required": ["p_model_threshold", "p_rule_override", "p_fallback", "p_title"], "additionalProperties": false } }, "additionalProperties": false }