Hypergraph is more powerful. Transform unstructured text into structured knowledge with LLMs. Graphs, hypergraphs, and spatio-temporal extractions — with one command.
refactor(templates): 将字段类型从array统一改为list
yifanfeng973afbe664ed68
diff --git a/hyperextract/templates/legacy/presets/agriculture/field_observation_list.yaml b/hyperextract/templates/legacy/presets/agriculture/field_observation_list.yamlindex 8230f30..490f30e 100644--- a/hyperextract/templates/legacy/presets/agriculture/field_observation_list.yaml+++ b/hyperextract/templates/legacy/presets/agriculture/field_observation_list.yaml@@ -26,7 +26,7 @@ item_schema:description:zh: "观测日期,统一格式为年-月-日(如2025-06-15)"- name: issues- type: "array"+ type: "list"description:zh: "观测到的问题列表,如杂草、虫害、病害、生长异常"- name: severity_level@@ -34,7 +34,7 @@ item_schema:description:zh: "严重等级:轻微、中等、严重"- name: recommendations- type: "array"+ type: "list"description:zh: "建议措施列表"diff --git a/hyperextract/templates/legacy/presets/biology/binding_site_model.yaml b/hyperextract/templates/legacy/presets/biology/binding_site_model.yamlindex 0d8903c..5aa1c01 100644--- a/hyperextract/templates/legacy/presets/biology/binding_site_model.yaml+++ b/hyperextract/templates/legacy/presets/biology/binding_site_model.yaml@@ -22,7 +22,7 @@ schema:description:zh: "关键残基编号范围,如Asp169-Lys210"- name: residue_details- type: "array"+ type: "list"description:zh: "关键残基详情列表"- name: chemical_propertiesdiff --git a/hyperextract/templates/legacy/presets/biology/biochemical_reaction_hypergraph.yaml b/hyperextract/templates/legacy/presets/biology/biochemical_reaction_hypergraph.yamlindex 2c01e7c..662fb0f 100644--- a/hyperextract/templates/legacy/presets/biology/biochemical_reaction_hypergraph.yaml+++ b/hyperextract/templates/legacy/presets/biology/biochemical_reaction_hypergraph.yaml@@ -30,15 +30,15 @@ edge_schema:description:zh: "催化该反应的酶名称"- name: substrates- type: "array"+ type: "list"description:zh: "反应底物列表"- name: products- type: "array"+ type: "list"description:zh: "反应产物列表"- name: cofactors- type: "array"+ type: "list"description:zh: "辅因子列表,如NAD+、Mg2+"required: falsediff --git a/hyperextract/templates/legacy/presets/biology/protein_complex_map.yaml b/hyperextract/templates/legacy/presets/biology/protein_complex_map.yamlindex 0debebf..2ed0d91 100644--- a/hyperextract/templates/legacy/presets/biology/protein_complex_map.yaml+++ b/hyperextract/templates/legacy/presets/biology/protein_complex_map.yaml@@ -31,7 +31,7 @@ node_schema:edge_schema:fields:- name: members- type: "array"+ type: "list"description:zh: "参与组成复合物的所有蛋白质或亚基名称列表"- name: complex_namediff --git a/hyperextract/templates/legacy/presets/finance/call_sentiment_hypergraph.yaml b/hyperextract/templates/legacy/presets/finance/call_sentiment_hypergraph.yamlindex fffcc93..bc6d0f4 100644--- a/hyperextract/templates/legacy/presets/finance/call_sentiment_hypergraph.yaml+++ b/hyperextract/templates/legacy/presets/finance/call_sentiment_hypergraph.yaml@@ -38,7 +38,7 @@ output:required: truedefault: ''- name: participating_elements- type: array+ type: listdescription:zh: 此情绪聚类中所有元素的名称(主题 + 发言人 + 情绪 + 驱动因素)required: truediff --git a/hyperextract/templates/legacy/presets/finance/earnings_call_summary.yaml b/hyperextract/templates/legacy/presets/finance/earnings_call_summary.yamlindex 35d0042..754bf07 100644--- a/hyperextract/templates/legacy/presets/finance/earnings_call_summary.yaml+++ b/hyperextract/templates/legacy/presets/finance/earnings_call_summary.yaml@@ -75,19 +75,19 @@ output:required: falsedefault: ''- name: key_highlights- type: array+ type: listdescription:zh: 管理层准备发言中的 3-5 项核心亮点required: falsedefault: ''- name: key_concerns- type: array+ type: listdescription:zh: 管理层或分析师在问答环节提出的主要关切required: falsedefault: ''- name: strategic_priorities- type: array+ type: listdescription:zh: 管理层强调的战略重点required: falsediff --git a/hyperextract/templates/legacy/presets/finance/factor_influence_hypergraph.yaml b/hyperextract/templates/legacy/presets/finance/factor_influence_hypergraph.yamlindex f76f5a5..5ad870d 100644--- a/hyperextract/templates/legacy/presets/finance/factor_influence_hypergraph.yaml+++ b/hyperextract/templates/legacy/presets/finance/factor_influence_hypergraph.yaml@@ -38,7 +38,7 @@ output:required: truedefault: ''- name: factors- type: array+ type: listdescription:zh: 导致该结果的因子列表(至少2个)required: truediff --git a/hyperextract/templates/legacy/presets/finance/filing_financial_snapshot.yaml b/hyperextract/templates/legacy/presets/finance/filing_financial_snapshot.yamlindex b1b9f7f..5352207 100644--- a/hyperextract/templates/legacy/presets/finance/filing_financial_snapshot.yaml+++ b/hyperextract/templates/legacy/presets/finance/filing_financial_snapshot.yaml@@ -81,7 +81,7 @@ output:required: falsedefault: ''- name: key_metrics- type: array+ type: listdescription:zh: 其他关键财务指标列表(如毛利率、ROE、市盈率等)required: falsediff --git a/hyperextract/templates/legacy/presets/finance/filing_risk_factor_set.yaml b/hyperextract/templates/legacy/presets/finance/filing_risk_factor_set.yamlindex b7038ca..238a8ad 100644--- a/hyperextract/templates/legacy/presets/finance/filing_risk_factor_set.yaml+++ b/hyperextract/templates/legacy/presets/finance/filing_risk_factor_set.yaml@@ -33,7 +33,7 @@ output:required: falsedefault: ''- name: affected_areas- type: array+ type: listdescription:zh: 受影响的业务板块或职能(例如 ['国际业务', '供应链'])required: falsediff --git a/hyperextract/templates/legacy/presets/finance/market_sentiment_model.yaml b/hyperextract/templates/legacy/presets/finance/market_sentiment_model.yamlindex 72c487d..c49b5e6 100644--- a/hyperextract/templates/legacy/presets/finance/market_sentiment_model.yaml+++ b/hyperextract/templates/legacy/presets/finance/market_sentiment_model.yaml@@ -39,19 +39,19 @@ output:required: falsedefault: ''- name: mentioned_tickers- type: array+ type: listdescription:zh: 提及的股票代码(例如 ['AAPL', 'MSFT', 'GOOGL'])required: falsedefault: ''- name: mentioned_sectors- type: array+ type: listdescription:zh: 涉及的行业板块(例如 ['科技', '金融', '能源'])required: falsedefault: ''- name: key_events- type: array+ type: listdescription:zh: 驱动情绪的关键事件(例如 ['美联储利率决议', 'NVDA 财报超预期'])required: false@@ -69,7 +69,7 @@ output:required: falsedefault: ''- name: contrarian_signals- type: array+ type: listdescription:zh: 任何逆向或不同意见的观点required: falsediff --git a/hyperextract/templates/legacy/presets/finance/multi_source_sentiment_hypergraph.yaml b/hyperextract/templates/legacy/presets/finance/multi_source_sentiment_hypergraph.yamlindex a2a0b9d..fc434a2 100644--- a/hyperextract/templates/legacy/presets/finance/multi_source_sentiment_hypergraph.yaml+++ b/hyperextract/templates/legacy/presets/finance/multi_source_sentiment_hypergraph.yaml@@ -44,7 +44,7 @@ output:required: truedefault: ''- name: participating_sources- type: array+ type: listdescription:zh: 参与此融合的所有来源和受影响实体的名称required: truediff --git a/hyperextract/templates/legacy/presets/finance/research_note_summary.yaml b/hyperextract/templates/legacy/presets/finance/research_note_summary.yamlindex f1a13fb..b2c974a 100644--- a/hyperextract/templates/legacy/presets/finance/research_note_summary.yaml+++ b/hyperextract/templates/legacy/presets/finance/research_note_summary.yaml@@ -75,13 +75,13 @@ output:required: falsedefault: ''- name: key_catalysts- type: array+ type: listdescription:zh: 已识别的近期催化剂(例如 ['Q4 业绩超预期', '新产品发布', '监管审批'])required: falsedefault: ''- name: key_risks- type: array+ type: listdescription:zh: 分析师强调的主要风险required: falsediff --git a/hyperextract/templates/legacy/presets/finance/segment_performance_list.yaml b/hyperextract/templates/legacy/presets/finance/segment_performance_list.yamlindex e7b875a..68d19cf 100644--- a/hyperextract/templates/legacy/presets/finance/segment_performance_list.yaml+++ b/hyperextract/templates/legacy/presets/finance/segment_performance_list.yaml@@ -39,7 +39,7 @@ output:required: falsedefault: ''- name: key_metrics- type: array+ type: listdescription:zh: 板块特定的关键绩效指标(例如 ['订阅用户:2.3亿', 'ARPU:$14.99', '流失率:2.1%'])required: falsediff --git a/hyperextract/templates/legacy/presets/food/dish_review_summary.yaml b/hyperextract/templates/legacy/presets/food/dish_review_summary.yamlindex bed2373..154e773 100644--- a/hyperextract/templates/legacy/presets/food/dish_review_summary.yaml+++ b/hyperextract/templates/legacy/presets/food/dish_review_summary.yaml@@ -22,13 +22,13 @@ item_schema:required: truedefault: ""- name: highlights- type: "array"+ type: "list"description:zh: "亮点列表"required: truedefault: ""- name: improvements- type: "array"+ type: "list"description:zh: "改进空间列表"required: truediff --git a/hyperextract/templates/legacy/presets/food/ingredient_composition_hypergraph.yaml b/hyperextract/templates/legacy/presets/food/ingredient_composition_hypergraph.yamlindex d5238dc..4e3f3fd 100644--- a/hyperextract/templates/legacy/presets/food/ingredient_composition_hypergraph.yaml+++ b/hyperextract/templates/legacy/presets/food/ingredient_composition_hypergraph.yaml@@ -37,19 +37,19 @@ edge_schema:required: falsedefault: ""- name: main_ingredients- type: "array"+ type: "list"description:zh: "主料列表(包含食材名称、角色、用量)"required: falsedefault: ""- name: auxiliary_ingredients- type: "array"+ type: "list"description:zh: "辅料列表(包含食材名称、角色、用量)"required: falsedefault: ""- name: seasonings- type: "array"+ type: "list"description:zh: "调味品列表(包含食材名称、角色、用量)"required: falsediff --git a/hyperextract/templates/legacy/presets/food/standard_recipe_card.yaml b/hyperextract/templates/legacy/presets/food/standard_recipe_card.yamlindex f12d3ae..f5dfef9 100644--- a/hyperextract/templates/legacy/presets/food/standard_recipe_card.yaml+++ b/hyperextract/templates/legacy/presets/food/standard_recipe_card.yaml@@ -52,31 +52,31 @@ schema:required: falsedefault: ""- name: main_ingredients- type: "array"+ type: "list"description:zh: "主料列表"required: falsedefault: ""- name: auxiliary_ingredients- type: "array"+ type: "list"description:zh: "辅料列表"required: falsedefault: ""- name: seasonings- type: "array"+ type: "list"description:zh: "调味品列表"required: falsedefault: ""- name: steps- type: "array"+ type: "list"description:zh: "烹饪步骤列表"required: falsedefault: ""- name: tips- type: "array"+ type: "list"description:zh: "关键控制点TIPS"required: falsediff --git a/hyperextract/templates/legacy/presets/general/compliance_logic.yaml b/hyperextract/templates/legacy/presets/general/compliance_logic.yamlindex b5b4159..585f6fe 100644--- a/hyperextract/templates/legacy/presets/general/compliance_logic.yaml+++ b/hyperextract/templates/legacy/presets/general/compliance_logic.yaml@@ -31,7 +31,7 @@ output:description:zh: 规则类型:必须、禁止、允许、其他- name: participants- type: array+ type: listdescription:zh: 参与要素名称列表,必须使用已提取节点的 name- name: actiondiff --git a/hyperextract/templates/legacy/presets/general/encyclopedia_item.yaml b/hyperextract/templates/legacy/presets/general/encyclopedia_item.yamlindex 07d7921..f6512cd 100644--- a/hyperextract/templates/legacy/presets/general/encyclopedia_item.yaml+++ b/hyperextract/templates/legacy/presets/general/encyclopedia_item.yaml@@ -17,12 +17,12 @@ output:description:zh: 实体类型:人物、地点、组织、事件、概念、物品、其他- name: alternativeNames- type: array+ type: listdescription:zh: 别名、俗称、外文名称required: false- name: category- type: array+ type: listdescription:zh: 分类标签required: false@@ -32,17 +32,17 @@ output:zh: 摘要/简介required: false- name: attributes- type: array+ type: listdescription:zh: '关键属性列表,每个元素格式为''属性名: 属性值'''required: false- name: keyEvents- type: array+ type: listdescription:zh: 重要事件/里程碑required: false- name: relatedConcepts- type: array+ type: listdescription:zh: 相关概念/条目required: falsediff --git a/hyperextract/templates/legacy/presets/general/personal_profile.yaml b/hyperextract/templates/legacy/presets/general/personal_profile.yamlindex dfc7b40..68aa377 100644--- a/hyperextract/templates/legacy/presets/general/personal_profile.yaml+++ b/hyperextract/templates/legacy/presets/general/personal_profile.yaml@@ -38,27 +38,27 @@ output:zh: 出生地required: false- name: education- type: array+ type: listdescription:zh: 教育经历required: false- name: occupations- type: array+ type: listdescription:zh: 职业/身份required: false- name: coreIdentity- type: array+ type: listdescription:zh: 核心身份/标签required: false- name: majorAchievements- type: array+ type: listdescription:zh: 主要成就required: false- name: affiliations- type: array+ type: listdescription:zh: 所属组织/机构required: falsediff --git a/hyperextract/templates/legacy/presets/general/regulation_profile.yaml b/hyperextract/templates/legacy/presets/general/regulation_profile.yamlindex 9e3a883..cf1f7f2 100644--- a/hyperextract/templates/legacy/presets/general/regulation_profile.yaml+++ b/hyperextract/templates/legacy/presets/general/regulation_profile.yaml@@ -38,12 +38,12 @@ output:zh: 失效日期required: false- name: scope- type: array+ type: listdescription:zh: 适用范围required: false- name: targetAudience- type: array+ type: listdescription:zh: 适用对象required: false@@ -53,12 +53,12 @@ output:zh: 核心宗旨/目的required: false- name: keywords- type: array+ type: listdescription:zh: 关键词/标签required: false- name: relatedRegulations- type: array+ type: listdescription:zh: 关联规章required: falsediff --git a/hyperextract/templates/legacy/presets/history/epistolary_knowledge_graph.yaml b/hyperextract/templates/legacy/presets/history/epistolary_knowledge_graph.yamlindex 281a2e4..a8f751c 100644--- a/hyperextract/templates/legacy/presets/history/epistolary_knowledge_graph.yaml+++ b/hyperextract/templates/legacy/presets/history/epistolary_knowledge_graph.yaml@@ -44,12 +44,12 @@ edge_schema:description:zh: "信件主题或主要议题"- name: mentionedPersons- type: "array"+ type: "list"description:zh: "信中提及的人物"required: false- name: mentionedEvents- type: "array"+ type: "list"description:zh: "信中提及的事件"required: falsediff --git a/hyperextract/templates/legacy/presets/history/multi_participant_event_map.yaml b/hyperextract/templates/legacy/presets/history/multi_participant_event_map.yamlindex 7a762ff..4ca8a5d 100644--- a/hyperextract/templates/legacy/presets/history/multi_participant_event_map.yaml+++ b/hyperextract/templates/legacy/presets/history/multi_participant_event_map.yaml@@ -47,7 +47,7 @@ edge_schema:description:zh: "事件概述,描述事件背景、经过和结果"- name: participants- type: "array"+ type: "list"description:zh: "参与者列表,与节点对应"diff --git a/hyperextract/templates/legacy/presets/history/personal_trajectory_hypergraph.yaml b/hyperextract/templates/legacy/presets/history/personal_trajectory_hypergraph.yamlindex f58f700..ff04b60 100644--- a/hyperextract/templates/legacy/presets/history/personal_trajectory_hypergraph.yaml+++ b/hyperextract/templates/legacy/presets/history/personal_trajectory_hypergraph.yaml@@ -34,11 +34,11 @@ edge_schema:description:zh: "地点"- name: companions- type: "array"+ type: "list"description:zh: "同行或交往人物"- name: experiences- type: "array"+ type: "list"description:zh: "核心经历列表"required: falsediff --git a/hyperextract/templates/legacy/presets/history/political_struggle_hypergraph.yaml b/hyperextract/templates/legacy/presets/history/political_struggle_hypergraph.yamlindex 0a55b77..f88f140 100644--- a/hyperextract/templates/legacy/presets/history/political_struggle_hypergraph.yaml+++ b/hyperextract/templates/legacy/presets/history/political_struggle_hypergraph.yaml@@ -34,20 +34,20 @@ edge_schema:description:zh: "事件名称"- name: attackers- type: "array"+ type: "list"description:zh: "攻方列表"- name: defenders- type: "array"+ type: "list"description:zh: "守方列表"- name: planners- type: "array"+ type: "list"description:zh: "策划者列表"required: false- name: turncoats- type: "array"+ type: "list"description:zh: "变节者列表"required: falsediff --git a/hyperextract/templates/legacy/presets/industry/failure_knowledge_hypergraph.yaml b/hyperextract/templates/legacy/presets/industry/failure_knowledge_hypergraph.yamlindex f512a99..23b7c8c 100644--- a/hyperextract/templates/legacy/presets/industry/failure_knowledge_hypergraph.yaml+++ b/hyperextract/templates/legacy/presets/industry/failure_knowledge_hypergraph.yaml@@ -32,7 +32,7 @@ output:description: {}fields:- name: nodes- type: array+ type: listdescription:zh: 参与故障推理的节点列表:[故障现象1, 故障现象2, ..., 根因, 部件, 解决方案1, 解决方案2, ...]required: truediff --git a/hyperextract/templates/legacy/presets/industry/incident_causality_map.yaml b/hyperextract/templates/legacy/presets/industry/incident_causality_map.yamlindex 95e21b6..2c9dbf7 100644--- a/hyperextract/templates/legacy/presets/industry/incident_causality_map.yaml+++ b/hyperextract/templates/legacy/presets/industry/incident_causality_map.yaml@@ -38,7 +38,7 @@ output:description: {}fields:- name: nodes- type: array+ type: listdescription:zh: 参与因果链条的节点列表:[隐患1, 隐患2, ..., 触发条件, 违章行为, 事故后果1, 事故后果2, ...]required: truediff --git a/hyperextract/templates/legacy/presets/industry/maintenace_operation_map.yaml b/hyperextract/templates/legacy/presets/industry/maintenace_operation_map.yamlindex 96a28ec..08566e8 100644--- a/hyperextract/templates/legacy/presets/industry/maintenace_operation_map.yaml+++ b/hyperextract/templates/legacy/presets/industry/maintenace_operation_map.yaml@@ -32,7 +32,7 @@ output:description: {}fields:- name: nodes- type: array+ type: listdescription:zh: 参与作业的节点列表:[操作人员, 工具1, 工具2, 设备, 材料1, ...]required: truediff --git a/hyperextract/templates/legacy/presets/industry/spec_parameter_table.yaml b/hyperextract/templates/legacy/presets/industry/spec_parameter_table.yamlindex 780e4ca..e005cad 100644--- a/hyperextract/templates/legacy/presets/industry/spec_parameter_table.yaml+++ b/hyperextract/templates/legacy/presets/industry/spec_parameter_table.yaml@@ -117,7 +117,7 @@ output:required: falsedefault: ''- name: other_parameters- type: array+ type: listdescription:zh: 其他关键技术参数列表(如适用)required: falsediff --git a/hyperextract/templates/legacy/presets/industry/system_compatibility_graph.yaml b/hyperextract/templates/legacy/presets/industry/system_compatibility_graph.yamlindex d10eade..3113fbb 100644--- a/hyperextract/templates/legacy/presets/industry/system_compatibility_graph.yaml+++ b/hyperextract/templates/legacy/presets/industry/system_compatibility_graph.yaml@@ -32,7 +32,7 @@ output:description: {}fields:- name: nodes- type: array+ type: listdescription:zh: 参与兼容性关系的节点列表:[设备, 材质/介质/环境1, 材质/介质/环境2, ...]required: truediff --git a/hyperextract/templates/legacy/presets/legal/adjudication_logic.yaml b/hyperextract/templates/legacy/presets/legal/adjudication_logic.yamlindex 4f83fc1..0ee2d62 100644--- a/hyperextract/templates/legacy/presets/legal/adjudication_logic.yaml+++ b/hyperextract/templates/legacy/presets/legal/adjudication_logic.yaml@@ -38,7 +38,7 @@ output:required: truedefault: ''- name: participants- type: array+ type: listdescription:zh: 参与要素名称列表,必须使用已提取节点的 namerequired: truediff --git a/hyperextract/templates/legacy/presets/legal/contract_obligation_hypergraph.yaml b/hyperextract/templates/legacy/presets/legal/contract_obligation_hypergraph.yamlindex 0e81e6d..e6f7505 100644--- a/hyperextract/templates/legacy/presets/legal/contract_obligation_hypergraph.yaml+++ b/hyperextract/templates/legacy/presets/legal/contract_obligation_hypergraph.yaml@@ -38,7 +38,7 @@ output:required: truedefault: ''- name: participants- type: array+ type: listdescription:zh: 参与要素名称列表,必须使用已提取节点的 namerequired: truediff --git a/hyperextract/templates/legacy/presets/literature/complex_character_relation.yaml b/hyperextract/templates/legacy/presets/literature/complex_character_relation.yamlindex 1b42283..96d249b 100644--- a/hyperextract/templates/legacy/presets/literature/complex_character_relation.yaml+++ b/hyperextract/templates/legacy/presets/literature/complex_character_relation.yaml@@ -34,7 +34,7 @@ edge_schema:description:zh: "关系类型:三角恋、结盟、敌对、背叛、竞争、家族"- name: participants- type: "array"+ type: "list"description:zh: "参与方列表(3人或以上)"- name: descriptiondiff --git a/hyperextract/templates/legacy/presets/literature/critique_argument_hypergraph.yaml b/hyperextract/templates/legacy/presets/literature/critique_argument_hypergraph.yamlindex de74587..01f50f3 100644--- a/hyperextract/templates/legacy/presets/literature/critique_argument_hypergraph.yaml+++ b/hyperextract/templates/legacy/presets/literature/critique_argument_hypergraph.yaml@@ -34,11 +34,11 @@ edge_schema:description:zh: "核心观点"- name: evidences- type: "array"+ type: "list"description:zh: "论据列表"- name: citations- type: "array"+ type: "list"description:zh: "引用文本列表"required: falsediff --git a/hyperextract/templates/legacy/presets/literature/scene_event_hypergraph.yaml b/hyperextract/templates/legacy/presets/literature/scene_event_hypergraph.yamlindex d331b3c..425dcd5 100644--- a/hyperextract/templates/legacy/presets/literature/scene_event_hypergraph.yaml+++ b/hyperextract/templates/legacy/presets/literature/scene_event_hypergraph.yaml@@ -29,7 +29,7 @@ edge_schema:description:zh: "场景名称,如'第一场:桐花台夜话'"- name: characters- type: "array"+ type: "list"description:zh: "出场角色列表"- name: location@@ -37,12 +37,12 @@ edge_schema:description:zh: "场景地点"- name: props- type: "array"+ type: "list"description:zh: "关键道具列表"required: false- name: actions- type: "array"+ type: "list"description:zh: "核心动作列表"- name: timeOfDaydiff --git a/hyperextract/templates/legacy/presets/medicine/complex_interaction_net.yaml b/hyperextract/templates/legacy/presets/medicine/complex_interaction_net.yamlindex 46a6f30..2dd1260 100644--- a/hyperextract/templates/legacy/presets/medicine/complex_interaction_net.yaml+++ b/hyperextract/templates/legacy/presets/medicine/complex_interaction_net.yaml@@ -31,7 +31,7 @@ output:description:zh: 超边名称,如药物相互作用- name: nodes- type: array+ type: listdescription:zh: 参与超边的节点列表- name: interactionTypediff --git a/hyperextract/templates/legacy/presets/medicine/discharge_instruction.yaml b/hyperextract/templates/legacy/presets/medicine/discharge_instruction.yamlindex a844e30..681a209 100644--- a/hyperextract/templates/legacy/presets/medicine/discharge_instruction.yaml+++ b/hyperextract/templates/legacy/presets/medicine/discharge_instruction.yaml@@ -9,32 +9,32 @@ output:description: {}fields:- name: medications- type: array+ type: listdescription:zh: 出院带药列表,每个药物包含名称、剂量、用法、频次等信息required: false- name: followUp- type: array+ type: listdescription:zh: 复诊计划列表,每个复诊包含时间、科室、检查项目等信息required: false- name: rehabilitation- type: array+ type: listdescription:zh: 康复建议列表required: false- name: diet- type: array+ type: listdescription:zh: 饮食建议列表required: false- name: activity- type: array+ type: listdescription:zh: 活动建议列表required: false- name: notes- type: array+ type: listdescription:zh: 其他注意事项列表required: falsediff --git a/hyperextract/templates/legacy/presets/medicine/pathology_hypergraph.yaml b/hyperextract/templates/legacy/presets/medicine/pathology_hypergraph.yamlindex f2ac83d..533536a 100644--- a/hyperextract/templates/legacy/presets/medicine/pathology_hypergraph.yaml+++ b/hyperextract/templates/legacy/presets/medicine/pathology_hypergraph.yaml@@ -31,7 +31,7 @@ output:description:zh: 机制名称,简短描述性名称- name: participating_entities- type: array+ type: listdescription:zh: 参与此病理机制的所有实体名称列表- name: relationTypediff --git a/hyperextract/templates/legacy/presets/medicine/surgical_event_graph.yaml b/hyperextract/templates/legacy/presets/medicine/surgical_event_graph.yamlindex 0f83d68..d8b24f7 100644--- a/hyperextract/templates/legacy/presets/medicine/surgical_event_graph.yaml+++ b/hyperextract/templates/legacy/presets/medicine/surgical_event_graph.yaml@@ -31,7 +31,7 @@ output:description:zh: 超边名称,如手术名称- name: nodes- type: array+ type: listdescription:zh: 参与超边的节点列表- name: datediff --git a/hyperextract/templates/legacy/presets/medicine/treatment_regimen_map.yaml b/hyperextract/templates/legacy/presets/medicine/treatment_regimen_map.yamlindex 505ed3a..028abdb 100644--- a/hyperextract/templates/legacy/presets/medicine/treatment_regimen_map.yaml+++ b/hyperextract/templates/legacy/presets/medicine/treatment_regimen_map.yaml@@ -31,7 +31,7 @@ output:description:zh: 超边名称,如治疗方案、康复计划等- name: nodes- type: array+ type: listdescription:zh: 参与超边的节点列表- name: diseasediff --git a/hyperextract/templates/legacy/presets/news/complex_relation_net.yaml b/hyperextract/templates/legacy/presets/news/complex_relation_net.yamlindex c042c3f..ec33a3b 100644--- a/hyperextract/templates/legacy/presets/news/complex_relation_net.yaml+++ b/hyperextract/templates/legacy/presets/news/complex_relation_net.yaml@@ -37,7 +37,7 @@ edge_schema:required: truedefault: ""- name: participants- type: "array"+ type: "list"description:zh: "参与者列表(3个及以上)"required: truediff --git a/hyperextract/templates/legacy/presets/news/viewpoint_structure.yaml b/hyperextract/templates/legacy/presets/news/viewpoint_structure.yamlindex 5ece582..096a68e 100644--- a/hyperextract/templates/legacy/presets/news/viewpoint_structure.yaml+++ b/hyperextract/templates/legacy/presets/news/viewpoint_structure.yaml@@ -43,7 +43,7 @@ edge_schema:required: truedefault: ""- name: participantNames- type: "array"+ type: "list"description:zh: "参与此观点论证的所有元素名称列表,必须从已提取的节点中选择"required: truediff --git a/hyperextract/templates/legacy/presets/tcm/formula_composition.yaml b/hyperextract/templates/legacy/presets/tcm/formula_composition.yamlindex dde0d66..03fc117 100644--- a/hyperextract/templates/legacy/presets/tcm/formula_composition.yaml+++ b/hyperextract/templates/legacy/presets/tcm/formula_composition.yaml@@ -50,37 +50,37 @@ output:required: falsedefault: ''- name: junHerbs- type: array+ type: listdescription:zh: 君药列表(包含药物名称、剂量、炮制方法)required: falsedefault: ''- name: chenHerbs- type: array+ type: listdescription:zh: 臣药列表(包含药物名称、剂量、炮制方法)required: falsedefault: ''- name: zuoHerbs- type: array+ type: listdescription:zh: 佐药列表(包含药物名称、剂量、炮制方法)required: falsedefault: ''- name: shiHerbs- type: array+ type: listdescription:zh: 使药列表(包含药物名称、剂量、炮制方法)required: falsedefault: ''- name: functions- type: array+ type: listdescription:zh: 方剂功能,如:解肌发表、调和营卫required: falsedefault: ''- name: indications- type: array+ type: listdescription:zh: 主治证候,如:外感风寒表虚证required: falsediff --git a/hyperextract/templates/legacy/presets/tcm/herb_property_model.yaml b/hyperextract/templates/legacy/presets/tcm/herb_property_model.yamlindex 7d91f59..5fc9573 100644--- a/hyperextract/templates/legacy/presets/tcm/herb_property_model.yaml+++ b/hyperextract/templates/legacy/presets/tcm/herb_property_model.yaml@@ -15,25 +15,25 @@ output:required: truedefault: ''- name: alternativeNames- type: array+ type: listdescription:zh: 别名、俗称required: falsedefault: ''- name: properties- type: array+ type: listdescription:zh: 四气:寒、热、温、凉、平required: falsedefault: ''- name: flavors- type: array+ type: listdescription:zh: 五味:酸、苦、甘、辛、咸required: falsedefault: ''- name: meridians- type: array+ type: listdescription:zh: 归经:如肺经、肝经、脾经等required: false@@ -63,13 +63,13 @@ output:required: falsedefault: ''- name: indications- type: array+ type: listdescription:zh: 功效主治required: falsedefault: ''- name: contraindications- type: array+ type: listdescription:zh: 配伍禁忌required: falsediff --git a/hyperextract/templates/legacy/presets/tcm/prescription_modification.yaml b/hyperextract/templates/legacy/presets/tcm/prescription_modification.yamlindex e3993c7..7188a68 100644--- a/hyperextract/templates/legacy/presets/tcm/prescription_modification.yaml+++ b/hyperextract/templates/legacy/presets/tcm/prescription_modification.yaml@@ -44,7 +44,7 @@ output:required: truedefault: ''- name: herbs- type: array+ type: listdescription:zh: 加减药物列表required: truediff --git a/hyperextract/templates/legacy/presets/tcm/syndrome_reasoning_graph.yaml b/hyperextract/templates/legacy/presets/tcm/syndrome_reasoning_graph.yamlindex a5b2121..98acd22 100644--- a/hyperextract/templates/legacy/presets/tcm/syndrome_reasoning_graph.yaml+++ b/hyperextract/templates/legacy/presets/tcm/syndrome_reasoning_graph.yaml@@ -32,7 +32,7 @@ output:description: {}fields:- name: nodes- type: array+ type: listdescription:zh: 参与推理的节点列表:[症状1, 症状2, ..., 证型, 治则, 药物1, 药物2, ...]required: truediff --git a/hyperextract/templates/presets/legal/adjudication_logic.yaml b/hyperextract/templates/presets/legal/adjudication_logic.yamlindex d71949e..e9cc403 100644--- a/hyperextract/templates/presets/legal/adjudication_logic.yaml+++ b/hyperextract/templates/presets/legal/adjudication_logic.yaml@@ -42,7 +42,7 @@ output:required: truedefault: ''- name: participants- type: array+ type: listdescription:zh: '参与要素名称列表,必须使用已提取节点的 name'required: truediff --git "a/hyperextract/templates/\347\237\245\350\257\206\346\250\241\346\235\277\350\256\276\350\256\241\346\214\207\345\215\227.md" "b/hyperextract/templates/\347\237\245\350\257\206\346\250\241\346\235\277\350\256\276\350\256\241\346\214\207\345\215\227.md"index 93e4ea1..fb8512a 100644--- "a/hyperextract/templates/\347\237\245\350\257\206\346\250\241\346\235\277\350\256\276\350\256\241\346\214\207\345\215\227.md"+++ "b/hyperextract/templates/\347\237\245\350\257\206\346\250\241\346\235\277\350\256\276\350\256\241\346\214\207\345\215\227.md"@@ -671,7 +671,7 @@ output:type: stringdescription: '机制名称'- name: participating_entities- type: array+ type: listdescription: '参与的实体列表'- name: relationTypetype: stringdiff --git a/hyperextract/utils/template_engine/__init__.py b/hyperextract/utils/template_engine/__init__.pyindex 5be7eb9..62f1e85 100644--- a/hyperextract/utils/template_engine/__init__.py+++ b/hyperextract/utils/template_engine/__init__.py@@ -4,9 +4,9 @@ Main Components:- Template: Unified API for template operations- Gallery: Template library management- TemplateFactory: Creates template instances from configuration-- RawTemplateCfg: Raw YAML config (multilingual) for validation-- TemplateCfg: Single-language config for actual use+- TemplateCfg: Template config (supports multilingual)- ConfigLoader: Loads YAML configuration+- localize_template: Converts multilingual config to single-language config- SchemaParser: Parses output schemas based on template type- GuidelineParser: Parses prompts based on template type- IdentifierResolver: Resolves identifier extractors@@ -15,26 +15,15 @@ Main Components:from .template import Templatefrom .gallery import Galleryfrom .factory import TemplateFactory, TemplateWrapper-from .builder import (- RawTemplateCfg,+from .parsers import (TemplateCfg,- ConfigLoader,- SchemaBuilder,- SchemaParser,+ OutputParser,GuidelineParser,PromptParser,IdentifierResolver,OptionsBuilder,- parse_multi_lang,- GuidelineSchema,- GuidelineSchemaMono,- OutputSchema,- OutputSchemaMono,- DisplaySchema,- DisplaySchemaMono,- IdentifiersSchema,- FieldSchema,- FieldsDefinition,+ _localize_data,+ localize_template,)@@ -43,23 +32,12 @@ __all__ = ["Gallery","TemplateFactory","TemplateWrapper",- "RawTemplateCfg","TemplateCfg",- "ConfigLoader",- "SchemaBuilder",- "SchemaParser",+ "OutputParser","GuidelineParser","PromptParser","IdentifierResolver","OptionsBuilder",- "parse_multi_lang",- "GuidelineSchema",- "GuidelineSchemaMono",- "OutputSchema",- "OutputSchemaMono",- "DisplaySchema",- "DisplaySchemaMono",- "IdentifiersSchema",- "FieldSchema",- "FieldsDefinition",+ "_localize_data",+ "localize_template",]diff --git a/hyperextract/utils/template_engine/builder/__init__.py b/hyperextract/utils/template_engine/builder/__init__.pydeleted file mode 100644index 15b1598..0000000--- a/hyperextract/utils/template_engine/builder/__init__.py+++ /dev/null@@ -1,52 +0,0 @@-"""Builder module - Configuration models, loaders and builders."""--from .loader import (- RawTemplateCfg,- TemplateCfg,- ConfigLoader,- parse_multi_lang,- GuidelineSchema,- GuidelineSchemaMono,- FieldSchema,- FieldsDefinition,- OutputSchema,- OutputSchemaMono,- OptionsSchema,- DisplaySchema,- DisplaySchemaMono,- IdentifiersSchema,- TemplateSchema,-)-from .output import SchemaParser, SchemaBuilder-from .guideline import GuidelineParser, PromptParser-from .identifiers import IdentifierResolver-from .options import (- Options,- OptionsBuilder,-)---__all__ = [- "RawTemplateCfg",- "TemplateCfg",- "ConfigLoader",- "parse_multi_lang",- "GuidelineSchema",- "GuidelineSchemaMono",- "FieldSchema",- "FieldsDefinition",- "OutputSchema",- "OutputSchemaMono",- "OptionsSchema",- "DisplaySchema",- "DisplaySchemaMono",- "IdentifiersSchema",- "TemplateSchema",- "SchemaParser",- "SchemaBuilder",- "GuidelineParser",- "PromptParser",- "IdentifierResolver",- "Options",- "OptionsBuilder",-]diff --git a/hyperextract/utils/template_engine/builder/loader.py b/hyperextract/utils/template_engine/builder/loader.pydeleted file mode 100644index b002414..0000000--- a/hyperextract/utils/template_engine/builder/loader.py+++ /dev/null@@ -1,257 +0,0 @@-"""Config loader and template configuration models."""--import yaml-from pathlib import Path-from typing import Any, Dict, List, Literal, Union-from pydantic import BaseModel, Field---VALID_MERGE_STRATEGIES = Literal[- "merge_field",- "keep_incoming",- "keep_existing",- "llm_balanced",- "llm_prefer_incoming",- "llm_prefer_existing",-]---def parse_multi_lang(- value: str | List[str] | Dict[str, str | List[str]],- language: str,-) -> str:- """Get multilingual text value, supports list format."""- if isinstance(value, str):- return value- elif isinstance(value, list):- return "\n".join(f"{i + 1}. {item}" for i, item in enumerate(value))- else:- dict_value = value.get(language)- if isinstance(dict_value, str):- return dict_value- if isinstance(dict_value, list):- return "\n".join(f"{i + 1}. {item}" for i, item in enumerate(dict_value))---class GuidelineSchema(BaseModel):- """Extraction guideline configuration"""-- target: str | List[str] | Dict[str, str | List[str]]- rules: str | List[str] | Dict[str, str | List[str]] | None = None- rules_for_entities: str | List[str] | Dict[str, str | List[str]] | None = None- rules_for_relations: str | List[str] | Dict[str, str | List[str]] | None = None- rules_for_time: str | List[str] | Dict[str, str | List[str]] | None = None- rules_for_location: str | List[str] | Dict[str, str | List[str]] | None = None---class FieldSchema(BaseModel):- """Field definition"""-- name: str- type: str- description: str | Dict[str, str]- required: bool = False- default: Any | None = None---class OutputUnitSchema(BaseModel):- """Output unit schema"""-- description: str | Dict[str, str]- fields: List[FieldSchema] = Field(default_factory=list)--class NaiveOutputSchema(BaseModel):- """Naive output schema"""-- description: str | Dict[str, str]- fields: List[FieldSchema] = Field(default_factory=list)--class GraphOutputSchema(BaseModel):- """Graph output schema"""-- description: str | Dict[str, str]- entities: OutputUnitSchema- relations: OutputUnitSchema--class OptionsSchema(BaseModel):- """Runtime options"""-- chunk_size: int = 2048- chunk_overlap: int = 256- max_workers: int = 10- verbose: bool = False- # [non-graph] AutoModel, AutoList, AutoSet- merge_strategy: VALID_MERGE_STRATEGIES = "llm_balanced"- fields_for_search: List[str] | None = None- # [graph] AutoGraph, AutoHypergraph, AutoTemporalGraph, AutoSpatialGraph, AutoSpatioTemporalGraph- entity_merge_strategy: VALID_MERGE_STRATEGIES = "llm_balanced"- relation_merge_strategy: VALID_MERGE_STRATEGIES = "llm_balanced"- extraction_mode: str | None = None- entity_fields_for_search: List[str] | None = None- relation_fields_for_search: List[str] | None = None- # [graph] AutoTemporalGraph, AutoSpatioTemporalGraph- observation_time: str | None = None- # [graph] AutoSpatialGraph, AutoSpatioTemporalGraph- observation_location: str | None = None---class DisplaySchema(BaseModel):- """Display configuration"""-- # [non-graph] AutoModel, AutoList, AutoSet- label: str | None = None- # [graph] AutoGraph, AutoHypergraph, AutoTemporalGraph, AutoSpatialGraph, AutoSpatioTemporalGraph- entity_label: Union[str, Dict[str, str | None]] = None- relation_label: Union[str, Dict[str, str | None]] = None---class IdentifiersSchema(BaseModel):- """Identifier configuration"""-- # [non-graph] AutoSet- item_id: str | None = None- # [graph] AutoGraph, AutoHypergraph, AutoTemporalGraph, AutoSpatialGraph, AutoSpatioTemporalGraph- entity_id: str | None = None- relation_id: str | None = None- relation_members: str | Dict[str, str | None, List[str]] | None = None- # [graph] AutoTemporalGraph, AutoSpatioTemporalGraph- time_field: str | None = None- # [graph] AutoSpatialGraph, AutoSpatioTemporalGraph- location_field: str | None = None---class RawTemplateCfg(BaseModel):- """Template configuration - raw config loaded from YAML (multilingual)."""-- language: str | List[str] = "en"- name: str- type: Literal[- "model",- "list",- "set",- "graph",- "hypergraph",- "temporal_graph",- "spatial_graph",- "spatio_temporal_graph",- ]- tags: List[str]- description: str | Dict[str, str]- output: NaiveOutputSchema | GraphOutputSchema- guideline: GuidelineSchema- identifiers: IdentifiersSchema | None = None- options: OptionsSchema | None = None- display: DisplaySchema---class TemplateCfg(BaseModel):- """Single-language version of Template configuration."""-- language: str | List[str] = "en"- name: str- type: Literal[- "model",- "list",- "set",- "graph",- "hypergraph",- "temporal_graph",- "spatial_graph",- "spatio_temporal_graph",- ]- tags: List[str]- description: str | Dict[str, str]- output: NaiveOutputSchema | GraphOutputSchema- guideline: GuidelineSchema- identifiers: IdentifiersSchema | None = None- options: OptionsSchema | None = None- display: DisplaySchema--def extract_specific_language_config(- multi: RawTemplateCfg, language: str-) -> TemplateCfg:- """Extract specific language config from multilingual config."""- lang = multi.language- if isinstance(lang, list):- lang = lang[0] if lang else language- elif lang is None:- lang = language-- return TemplateCfg(- language=lang,- name=multi.name,- type=multi.type,- tags=multi.tags or [],- )---class ConfigLoader:- """Config loader."""-- @staticmethod- def load_yaml(file_path: Union[str, Path]) -> Dict[str, Any]:- """Load YAML configuration file."""- path = Path(file_path)- if not path.exists():- raise FileNotFoundError(f"Config file not found: {file_path}")-- with open(path, "r", encoding="utf-8") as f:- return yaml.safe_load(f) or {}-- @staticmethod- def load_config(file_path: Union[str, Path]) -> RawTemplateCfg:- """Load and validate configuration."""- data = ConfigLoader.load_yaml(file_path)- return RawTemplateCfg(**data)-- @staticmethod- def load_config_from_dict(data: Dict[str, Any]) -> RawTemplateCfg:- """Load configuration from dict."""- return RawTemplateCfg(**data)-- @staticmethod- def get_text_value(- value: Union[str, Dict[str, str], None], language: str = "zh"- ) -> str | None:- """Get multilingual text value."""- if value is None:- return None- if isinstance(value, str):- return value- if isinstance(value, dict):- return value.get(language) or value.get("zh") or ""- return None-- @staticmethod- def validate_type(type_value: str) -> bool:- """Validate if type is valid."""- valid_types = {- "model",- "list",- "set",- "graph",- "hypergraph",- "temporal_graph",- "spatial_graph",- "spatio_temporal_graph",- }- return type_value in valid_types---__all__ = [- "parse_multi_lang",- "GuidelineSchema",- "GuidelineSchemaMono",- "FieldSchema",- "FieldsDefinition",- "OutputSchema",- "OutputSchemaMono",- "OptionsSchema",- "DisplaySchema",- "DisplaySchemaMono",- "IdentifiersSchema",- "TemplateSchema",- "RawTemplateCfg",- "TemplateCfg",- "ConfigLoader",-]diff --git a/hyperextract/utils/template_engine/factory.py b/hyperextract/utils/template_engine/factory.pyindex 052a394..12c9ac9 100644--- a/hyperextract/utils/template_engine/factory.py+++ b/hyperextract/utils/template_engine/factory.py@@ -8,14 +8,14 @@ from typing import TYPE_CHECKINGfrom langchain_core.language_models import BaseChatModelfrom langchain_core.embeddings import Embeddings-from .builder import (- RawTemplateCfg,+from .parsers import (+ TemplateCfg,OptionsBuilder,Options,- SchemaParser,+ OutputParser,IdentifierResolver,+ PromptParser,)-from .builder.guideline import PromptParserif TYPE_CHECKING:@@ -33,12 +33,12 @@ if TYPE_CHECKING:class TemplateFactory:@staticmethod- def get_language(config: RawTemplateCfg) -> str:+ def get_language(config: TemplateCfg) -> str:"""Get language setting."""return OptionsBuilder.get_language(config)@staticmethod- def resolve_display_extractors(config: RawTemplateCfg, schema_dict: dict = None):+ def resolve_display_extractors(config: TemplateCfg, schema_dict: dict = None):"""Generate label_extractor function based on display configuration."""display = config.displayif not display:@@ -78,14 +78,14 @@ class TemplateFactory:@classmethoddef create_model(- cls, config: RawTemplateCfg, llm_client: BaseChatModel, embedder: Embeddings+ cls, config: TemplateCfg, llm_client: BaseChatModel, embedder: Embeddings) -> "AutoModel":"""Create AutoModel template."""from hyperextract.types import AutoModellanguage = cls.get_language(config)- data_schema = SchemaParser(config, language)+ data_schema = OutputParser(config, language)config_mono = config.for_language(language)prompt, _, _ = PromptParser(config_mono, language)@@ -111,14 +111,14 @@ class TemplateFactory:@classmethoddef create_list(- cls, config: RawTemplateCfg, llm_client: BaseChatModel, embedder: Embeddings+ cls, config: TemplateCfg, llm_client: BaseChatModel, embedder: Embeddings) -> "AutoList":"""Create AutoList template."""from hyperextract.types import AutoListlanguage = cls.get_language(config)- data_schema = SchemaParser(config, language)+ data_schema = OutputParser(config, language)config_mono = config.for_language(language)prompt, _, _ = PromptParser(config_mono, language)@@ -138,14 +138,14 @@ class TemplateFactory:@classmethoddef create_set(- cls, config: RawTemplateCfg, llm_client: BaseChatModel, embedder: Embeddings+ cls, config: TemplateCfg, llm_client: BaseChatModel, embedder: Embeddings) -> "AutoSet":"""Create AutoSet template."""from hyperextract.types import AutoSetlanguage = cls.get_language(config)- data_schema = SchemaParser(config, language)+ data_schema = OutputParser(config, language)identifiers = IdentifierResolver.resolve_all(config)item_id_extractor = identifiers.get("item_id_extractor")@@ -174,23 +174,27 @@ class TemplateFactory:@classmethoddef create_graph(- cls, config: RawTemplateCfg, llm_client: BaseChatModel, embedder: Embeddings+ cls, config: TemplateCfg, llm_client: BaseChatModel, embedder: Embeddings) -> "AutoGraph":"""Create AutoGraph template."""from hyperextract.types import AutoGraphlanguage = cls.get_language(config)- entity_schema, relation_schema = SchemaParser(config, language)+ entity_schema, relation_schema = OutputParser(config, language)identifiers = IdentifierResolver.resolve_all(config)entity_key_extractor = identifiers.get("entity_key_extractor")relation_key_extractor = identifiers.get("relation_key_extractor")- entities_in_relation_extractor = identifiers.get("entities_in_relation_extractor")+ entities_in_relation_extractor = identifiers.get(+ "entities_in_relation_extractor"+ )options = OptionsBuilder.build_graph_options(config, language)config_mono = config.for_language(language)- prompt, prompt_for_entity_extraction, prompt_for_relation_extraction = PromptParser(config_mono, language)+ prompt, prompt_for_entity_extraction, prompt_for_relation_extraction = (+ PromptParser(config_mono, language)+ )return AutoGraph(entity_schema=entity_schema,@@ -226,29 +230,33 @@ class TemplateFactory:@classmethoddef create_hypergraph(- cls, config: RawTemplateCfg, llm_client: BaseChatModel, embedder: Embeddings+ cls, config: TemplateCfg, llm_client: BaseChatModel, embedder: Embeddings) -> "AutoHypergraph":return cls.create_graph(config, llm_client, embedder)@classmethoddef create_temporal_graph(- cls, config: RawTemplateCfg, llm_client: BaseChatModel, embedder: Embeddings+ cls, config: TemplateCfg, llm_client: BaseChatModel, embedder: Embeddings) -> "AutoTemporalGraph":from hyperextract.types import AutoTemporalGraphlanguage = cls.get_language(config)- entity_schema, relation_schema = SchemaParser(config, language)+ entity_schema, relation_schema = OutputParser(config, language)identifiers = IdentifierResolver.resolve_all(config)entity_key_extractor = identifiers.get("entity_key_extractor")relation_key_extractor = identifiers.get("relation_key_extractor")- entities_in_relation_extractor = identifiers.get("entities_in_relation_extractor")+ entities_in_relation_extractor = identifiers.get(+ "entities_in_relation_extractor"+ )time_in_relation_extractor = identifiers.get("time_in_relation_extractor")options = OptionsBuilder.build_temporal_graph_options(config, language)config_mono = config.for_language(language)- prompt, prompt_for_entity_extraction, prompt_for_relation_extraction = PromptParser(config_mono, language)+ prompt, prompt_for_entity_extraction, prompt_for_relation_extraction = (+ PromptParser(config_mono, language)+ )return AutoTemporalGraph(node_schema=entity_schema,@@ -286,23 +294,29 @@ class TemplateFactory:@classmethoddef create_spatial_graph(- cls, config: RawTemplateCfg, llm_client: BaseChatModel, embedder: Embeddings+ cls, config: TemplateCfg, llm_client: BaseChatModel, embedder: Embeddings) -> "AutoSpatialGraph":from hyperextract.types import AutoSpatialGraphlanguage = cls.get_language(config)- entity_schema, relation_schema = SchemaParser(config, language)+ entity_schema, relation_schema = OutputParser(config, language)identifiers = IdentifierResolver.resolve_all(config)entity_key_extractor = identifiers.get("entity_key_extractor")relation_key_extractor = identifiers.get("relation_key_extractor")- entities_in_relation_extractor = identifiers.get("entities_in_relation_extractor")- location_in_relation_extractor = identifiers.get("location_in_relation_extractor")+ entities_in_relation_extractor = identifiers.get(+ "entities_in_relation_extractor"+ )+ location_in_relation_extractor = identifiers.get(+ "location_in_relation_extractor"+ )options = OptionsBuilder.build_spatial_graph_options(config, language)config_mono = config.for_language(language)- prompt, prompt_for_entity_extraction, prompt_for_relation_extraction = PromptParser(config_mono, language)+ prompt, prompt_for_entity_extraction, prompt_for_relation_extraction = (+ PromptParser(config_mono, language)+ )return AutoSpatialGraph(entity_schema=entity_schema,@@ -340,26 +354,30 @@ class TemplateFactory:@classmethoddef create_spatio_temporal_graph(- cls, config: RawTemplateCfg, llm_client: BaseChatModel, embedder: Embeddings+ cls, config: TemplateCfg, llm_client: BaseChatModel, embedder: Embeddings) -> "AutoSpatioTemporalGraph":from hyperextract.types import AutoSpatioTemporalGraphlanguage = cls.get_language(config)- entity_schema, relation_schema = SchemaParser(config, language)+ entity_schema, relation_schema = OutputParser(config, language)identifiers = IdentifierResolver.resolve_all(config)entity_key_extractor = identifiers.get("entity_key_extractor")relation_key_extractor = identifiers.get("relation_key_extractor")- entities_in_relation_extractor = identifiers.get("entities_in_relation_extractor")+ entities_in_relation_extractor = identifiers.get(+ "entities_in_relation_extractor"+ )time_in_relation_extractor = identifiers.get("time_in_relation_extractor")- location_in_relation_extractor = identifiers.get("location_in_relation_extractor")-- options = OptionsBuilder.build_spatio_temporal_graph_options(- config, language+ location_in_relation_extractor = identifiers.get(+ "location_in_relation_extractor")+ options = OptionsBuilder.build_spatio_temporal_graph_options(config, language)+config_mono = config.for_language(language)- prompt, prompt_for_entity_extraction, prompt_for_relation_extraction = PromptParser(config_mono, language)+ prompt, prompt_for_entity_extraction, prompt_for_relation_extraction = (+ PromptParser(config_mono, language)+ )return AutoSpatioTemporalGraph(entity_schema=entity_schema,@@ -400,7 +418,7 @@ class TemplateFactory:@classmethoddef create(cls,- config: RawTemplateCfg,+ config: TemplateCfg,llm_client: BaseChatModel,embedder: Embeddings,**kwargs,@@ -483,7 +501,9 @@ class TemplateWrapper:self._autotype = autotypeself._entity_label_extractor = display_extractors.get("entity_label_extractor")- self._relation_label_extractor = display_extractors.get("relation_label_extractor")+ self._relation_label_extractor = display_extractors.get(+ "relation_label_extractor"+ )self._label_extractor = display_extractors.get("label_extractor")def __getattr__(self, name):@@ -499,8 +519,12 @@ class TemplateWrapper:"spatio_temporal_graph",):if self._entity_label_extractor and self._relation_label_extractor:- kwargs.setdefault("entity_label_extractor", self._entity_label_extractor)- kwargs.setdefault("relation_label_extractor", self._relation_label_extractor)+ kwargs.setdefault(+ "entity_label_extractor", self._entity_label_extractor+ )+ kwargs.setdefault(+ "relation_label_extractor", self._relation_label_extractor+ )else:if self._label_extractor:kwargs.setdefault("label_extractor", self._label_extractor)diff --git a/hyperextract/utils/template_engine/gallery.py b/hyperextract/utils/template_engine/gallery.pyindex d5e0bca..1353cdf 100644--- a/hyperextract/utils/template_engine/gallery.py+++ b/hyperextract/utils/template_engine/gallery.py@@ -7,7 +7,7 @@ import osfrom pathlib import Pathfrom typing import Dict, List, Optional-from .builder import RawTemplateCfg, ConfigLoader+from .parsers import RawTemplateCfg, ConfigLoaderclass Gallery:diff --git a/hyperextract/utils/template_engine/parsers/__init__.py b/hyperextract/utils/template_engine/parsers/__init__.pynew file mode 100644index 0000000..20f1bc1--- /dev/null+++ b/hyperextract/utils/template_engine/parsers/__init__.py@@ -0,0 +1,29 @@+"""Builder module - Configuration models, loaders and builders."""++from .loader import (+ TemplateCfg,+ ConfigLoader,+ _localize_data,+ localize_template,+)+from .output import OutputParser+from .guideline import GuidelineParser, PromptParser+from .identifiers import IdentifierResolver+from .options import (+ Options,+ OptionsBuilder,+)+++__all__ = [+ "TemplateCfg",+ "ConfigLoader",+ "_localize_data",+ "localize_template",+ "OutputParser",+ "GuidelineParser",+ "PromptParser",+ "IdentifierResolver",+ "Options",+ "OptionsBuilder",+]diff --git a/hyperextract/utils/template_engine/builder/guideline.py b/hyperextract/utils/template_engine/parsers/guideline.pysimilarity index 95%rename from hyperextract/utils/template_engine/builder/guideline.pyrename to hyperextract/utils/template_engine/parsers/guideline.pyindex b6badd1..d6ff501 100644--- a/hyperextract/utils/template_engine/builder/guideline.py+++ b/hyperextract/utils/template_engine/parsers/guideline.py@@ -1,7 +1,7 @@"""Extraction prompt parser from guideline."""from typing import Tuple-from .loader import parse_multi_lang, GuidelineSchemaMono+from .loader import NaiveGuidelineSchema, GraphGuidelineSchemaLABEL_MAPPING = {@@ -29,7 +29,7 @@ LABEL_MAPPING = {def GuidelineParser(- template: GuidelineSchemaMono, language: str = "en"+ template: NaiveGuidelineSchema | GraphGuidelineSchema, language: str = "en") -> Tuple[str, str, str]:"""Parse guideline and return prompts based on autotype.@@ -43,7 +43,7 @@ def GuidelineParser(- For graph types in two_stage mode: returns (main_prompt, node_prompt, edge_prompt)"""labels = LABEL_MAPPING.get(language, LABEL_MAPPING["en"])- guideline: GuidelineSchemaMono = template+ guideline: NaiveGuidelineSchema | GraphGuidelineSchema = templateprefix_prompt = (f"# {labels.get('role_and_task')}:\n{guideline.target}"diff --git a/hyperextract/utils/template_engine/builder/identifiers.py b/hyperextract/utils/template_engine/parsers/identifiers.pysimilarity index 100%rename from hyperextract/utils/template_engine/builder/identifiers.pyrename to hyperextract/utils/template_engine/parsers/identifiers.pydiff --git a/hyperextract/utils/template_engine/parsers/loader.py b/hyperextract/utils/template_engine/parsers/loader.pynew file mode 100644index 0000000..5f9c107--- /dev/null+++ b/hyperextract/utils/template_engine/parsers/loader.py@@ -0,0 +1,307 @@+"""Config loader and template configuration models."""++import yaml+from pathlib import Path+from typing import Any, Dict, List, Literal, Union+from pydantic import BaseModel+++VALID_MERGE_STRATEGIES = Literal[+ "merge_field",+ "keep_incoming",+ "keep_existing",+ "llm_balanced",+ "llm_prefer_incoming",+ "llm_prefer_existing",+]+AUTO_TYPES = Literal[+ "model",+ "list",+ "set",+ "graph",+ "hypergraph",+ "temporal_graph",+ "spatial_graph",+ "spatio_temporal_graph",+]+++# ==============================================================+# Naive Template Configuration: AutoModel, AutoList, AutoSet+# ==============================================================+class NaiveGuidelineSchema(BaseModel):+ """Naive guideline schema"""++ target: str | List[str] | Dict[str, str | List[str]]+ rules: str | List[str] | Dict[str, str | List[str]]+++class FieldSchema(BaseModel):+ """Field definition"""++ name: str+ type: Literal["str", "int", "float", "bool", "list", "dict"]+ description: str | Dict[str, str]+ required: bool = False+ default: Any | None = None+++class NaiveOutputSchema(BaseModel):+ """Naive output schema"""++ description: str | Dict[str, str]+ fields: List[FieldSchema]+++class NaiveOptionsSchema(BaseModel):+ """Naive runtime options"""++ chunk_size: int = 2048+ chunk_overlap: int = 256+ max_workers: int = 10+ verbose: bool = False+ merge_strategy: VALID_MERGE_STRATEGIES = "llm_balanced"+ fields_for_search: List[str] | None = None+++class NaiveDisplaySchema(BaseModel):+ """Naive display configuration"""++ label: str+++class NaiveIdentifierSchema(BaseModel):+ """Naive identifier configuration"""++ item_id: str | None = None+++# ==============================================================+# Graph Template Configuration: AutoGraph, AutoHyperGraph+# AutoTemporalGraph, AutoSpatialGraph, AutoSpatioTemporalGraph+# ==============================================================+++class GraphGuidelineSchema(BaseModel):+ """Graph guideline schema"""++ target: str | List[str] | Dict[str, str | List[str]]+ rules_for_entities: str | List[str] | Dict[str, str | List[str]]+ rules_for_relations: str | List[str] | Dict[str, str | List[str]]+ # AutoTemporalGraph, AutoSpatioTemporalGraph+ rules_for_time: str | List[str] | Dict[str, str | List[str]]+ # AutoSpatialGraph, AutoSpatioTemporalGraph+ rules_for_location: str | List[str] | Dict[str, str | List[str]]+++class GraphOutputSchema(BaseModel):+ """Graph output schema"""++ description: str | Dict[str, str]+ entities: NaiveOutputSchema+ relations: NaiveOutputSchema+++class GraphOptionsSchema(BaseModel):+ """Graph runtime options"""++ chunk_size: int = 2048+ chunk_overlap: int = 256+ max_workers: int = 10+ verbose: bool = False+ entity_merge_strategy: VALID_MERGE_STRATEGIES = "llm_balanced"+ relation_merge_strategy: VALID_MERGE_STRATEGIES = "llm_balanced"+ extraction_mode: str | None = None+ entity_fields_for_search: List[str] | None = None+ relation_fields_for_search: List[str] | None = None+ # AutoTemporalGraph, AutoSpatioTemporalGraph+ observation_time: str | None = None+ # AutoSpatialGraph, AutoSpatioTemporalGraph+ observation_location: str | None = None+++class GraphDisplaySchema(BaseModel):+ """Graph display configuration"""++ entity_label: str+ relation_label: str+++class GraphIdentifiersSchema(BaseModel):+ """Graph Identifier configuration"""++ entity_id: str | None = None+ relation_id: str | None = None+ relation_members: str | Dict[str, str | None, List[str]] | None = None+ # AutoTemporalGraph, AutoSpatioTemporalGraph+ time_field: str | None = None+ # AutoSpatialGraph, AutoSpatioTemporalGraph+ location_field: str | None = None+++class TemplateCfg(BaseModel):+ """Template configuration loaded from YAML."""++ language: str | List[str] = "en"+ name: str+ type: AUTO_TYPES+ tags: List[str]+ description: str | Dict[str, str]+ output: NaiveOutputSchema | GraphOutputSchema+ guideline: NaiveGuidelineSchema | GraphGuidelineSchema+ identifiers: NaiveIdentifierSchema | GraphIdentifiersSchema | None = None+ options: NaiveOptionsSchema | GraphOptionsSchema | None = None+ display: NaiveDisplaySchema | GraphDisplaySchema+++# ==============================================================+# Localization Functions+# ==============================================================+++def _localize_data(+ value: str | List[str] | Dict[str, str | List[str]] | None,+ language: str,+) -> str:+ """Get multilingual text value, supports list format++ Args:+ value: Multilingual value, supports string, list or dict format+ language: Target language code++ Returns:+ str: Converted string+ """+ if isinstance(value, str):+ return value+ if isinstance(value, list):+ return "\n".join(f"{i + 1}. {item}" for i, item in enumerate(value))+ dict_value = value.get(language)+ if isinstance(dict_value, str):+ return dict_value+ if isinstance(dict_value, list):+ return "\n".join(f"{i + 1}. {item}" for i, item in enumerate(dict_value))+++def _localize_field(field: FieldSchema, language: str) -> FieldSchema:+ """Localize a single field."""+ return FieldSchema(+ name=field.name,+ type=field.type,+ description=_localize_data(field.description, language),+ required=field.required,+ default=field.default,+ )+++def _localize_naive_output(+ output: NaiveOutputSchema, language: str+) -> NaiveOutputSchema:+ """Localize NaiveOutputSchema."""+ fields = [_localize_field(f, language) for f in output.fields]+ return NaiveOutputSchema(+ description=_localize_data(output.description, language),+ fields=fields,+ )+++def _localize_output(+ output: NaiveOutputSchema | GraphOutputSchema,+ language: str,+ autotype: AUTO_TYPES | None = None,+) -> NaiveOutputSchema | GraphOutputSchema:+ """Localize output configuration."""+ if autotype in ("model", "list", "set"):+ return _localize_naive_output(output, language)+ return GraphOutputSchema(+ description=_localize_data(output.description, language),+ entities=_localize_naive_output(output.entities, language),+ relations=_localize_naive_output(output.relations, language),+ )+++def _localize_guideline(+ guideline: NaiveGuidelineSchema | GraphGuidelineSchema,+ language: str,+ autotype: AUTO_TYPES | None = None,+) -> NaiveGuidelineSchema | GraphGuidelineSchema:+ """Localize guideline configuration."""+ if autotype in ("model", "list", "set"):+ return NaiveGuidelineSchema(+ target=_localize_data(guideline.target, language),+ rules=_localize_data(guideline.rules, language),+ )+ return GraphGuidelineSchema(+ target=_localize_data(guideline.target, language),+ rules_for_entities=_localize_data(guideline.rules_for_entities, language),+ rules_for_relations=_localize_data(guideline.rules_for_relations, language),+ rules_for_time=_localize_data(guideline.rules_for_time, language)+ if guideline.rules_for_time+ else None,+ rules_for_location=_localize_data(guideline.rules_for_location, language)+ if guideline.rules_for_location+ else None,+ )+++def localize_template(config: TemplateCfg, language: str) -> TemplateCfg:+ """Convert multilingual template config to single-language config.++ Args:+ config: Original multilingual config+ language: Target language code (e.g., 'zh', 'en')++ Returns:+ TemplateCfg: Single-language config with all multilingual fields converted to strings++ Examples:+ >>> config = ConfigLoader.load_config("template.yaml")+ >>> config_zh = localize_template(config, "zh")+ >>> print(config_zh.description) # string+ """++ return TemplateCfg(+ language=language,+ name=config.name,+ type=config.type,+ tags=config.tags,+ description=_localize_data(config.description, language),+ output=_localize_output(config.output, language),+ guideline=_localize_guideline(config.guideline, language, config.type),+ identifiers=config.identifiers,+ options=config.options,+ display=config.display,+ )+++def load_template(file_path: Union[str, Path]) -> TemplateCfg:+ """Load and validate template configuration."""+ path = Path(file_path)+ if not path.exists():+ raise FileNotFoundError(f"Config file not found: {file_path}")++ with open(path, "r", encoding="utf-8") as f:+ template = TemplateCfg(**yaml.safe_load(f))++ # Validate multi-language support+ existing_languages = (+ template.language+ if isinstance(template.language, list)+ else [template.language]+ )+ for lang in existing_languages:+ try:+ localize_template(template, lang)+ except Exception as e:+ raise ValueError(+ f"The template configuration is not valid for language {lang}: {e}"+ )++ return template+++__all__ = [+ "TemplateCfg",+ "load_template",+ "localize_template",+]diff --git a/hyperextract/utils/template_engine/builder/options.py b/hyperextract/utils/template_engine/parsers/options.pysimilarity index 98%rename from hyperextract/utils/template_engine/builder/options.pyrename to hyperextract/utils/template_engine/parsers/options.pyindex 830a195..1b0fefa 100644--- a/hyperextract/utils/template_engine/builder/options.py+++ b/hyperextract/utils/template_engine/parsers/options.py@@ -5,7 +5,7 @@ from pydantic import BaseModelfrom ontomem.merger import MergeStrategy-from .output import SchemaBuilder+from .output import OutputParserfrom .identifiers import IdentifierResolver@@ -363,7 +363,7 @@ class OptionsBuilder:@classmethoddef validate_model_config(cls, config):"""Validate AutoModel configuration."""- schema_dict = SchemaBuilder.build_schema(config)+ schema_dict = OutputParser(config)if schema_dict.get("schema") is None:raise ValueError(f"AutoModel requires schema definition: {config.name}")return schema_dict@@ -371,7 +371,7 @@ class OptionsBuilder:@classmethoddef validate_list_config(cls, config):"""Validate AutoList configuration."""- schema_dict = SchemaBuilder.build_schema(config)+ schema_dict = OutputParser(config)if schema_dict.get("item_schema") is None:raise ValueError(f"AutoList requires item_schema definition: {config.name}")return schema_dict@@ -379,7 +379,7 @@ class OptionsBuilder:@classmethoddef validate_set_config(cls, config):"""Validate AutoSet configuration."""- schema_dict = SchemaBuilder.build_schema(config)+ schema_dict = OutputParser(config)if schema_dict.get("item_schema") is None:raise ValueError(f"AutoSet requires item_schema definition: {config.name}")@@ -392,7 +392,7 @@ class OptionsBuilder:@classmethoddef validate_graph_config(cls, config):"""Validate AutoGraph/AutoHypergraph configuration."""- schema_dict = SchemaBuilder.build_schema(config)+ schema_dict = OutputParser(config)if schema_dict.get("entity_schema") is None or schema_dict.get("relation_schema") is None:raise ValueError(f"AutoGraph requires entity_schema and relation_schema definition: {config.name}")diff --git a/hyperextract/utils/template_engine/builder/output.py b/hyperextract/utils/template_engine/parsers/output.pysimilarity index 93%rename from hyperextract/utils/template_engine/builder/output.pyrename to hyperextract/utils/template_engine/parsers/output.pyindex 0c448ad..51f5779 100644--- a/hyperextract/utils/template_engine/builder/output.py+++ b/hyperextract/utils/template_engine/parsers/output.py@@ -9,7 +9,7 @@ TYPE_MAPPING = {"int": int,"float": float,"bool": bool,- "array": list,+ "list": list,}@@ -37,7 +37,7 @@ def build_field_type(field) -> Type:else:field_type_str = field.type- if field_type_str == "array":+ if field_type_str == "list":if isinstance(field, dict):item_type_str = field.get("item_type")else:@@ -64,7 +64,7 @@ def build_field_default(field) -> Any:return ...if default_val is not None:return default_val- if field_type == "array":+ if field_type == "list":return []return None@@ -193,7 +193,7 @@ def _build_graph_schemas(config, language: str) -> Tuple[Type, Type]:raise ValueError(f"No schema definition found for graph type: {config.name}")-def SchemaParser(+def OutputParser(config,language: str = "zh") -> Union[Type, Tuple[Type, Type]]:@@ -215,19 +215,7 @@ def SchemaParser(return _build_graph_schemas(config, language)-class SchemaBuilder:- """Schema Builder - kept for backward compatibility."""-- @staticmethod- def build_schema(config):- """Deprecated: Use SchemaParser instead."""- return SchemaParser(config, "zh")-__all__ = [- "SchemaParser",- "SchemaBuilder",- "build_field_type",- "build_field_default",- "build_field_description",+ "OutputParser",]diff --git a/hyperextract/utils/template_engine/template.py b/hyperextract/utils/template_engine/template.pyindex 0e02dcd..3f7975b 100644--- a/hyperextract/utils/template_engine/template.py+++ b/hyperextract/utils/template_engine/template.py@@ -9,7 +9,7 @@ from langchain_core.language_models import BaseChatModelfrom langchain_core.embeddings import Embeddingsfrom .gallery import Gallery-from .builder import RawTemplateCfg+from .parsers import RawTemplateCfgclass Template:diff --git a/scripts/migrate_yaml_configs.py b/scripts/migrate_yaml_configs.pyindex c506631..61caf49 100644--- a/scripts/migrate_yaml_configs.py+++ b/scripts/migrate_yaml_configs.py@@ -13,7 +13,7 @@ from typing import Any, Dict, List, Uniondef convert_rules_to_array(rules_value: Union[str, List[str], Dict[str, Union[str, List[str]]]]) -> Union[List[str], Dict[str, List[str]]]:- """Convert string format rules to array format."""+ """Convert string format rules to list format."""if rules_value is None:return None