Skip to content

Hypergraph is more powerful. Transform unstructured text into structured knowledge with LLMs. Graphs, hypergraphs, and spatio-temporal extractions — with one command.

Add initial template files for various domains in English and Chinese

yifanfeng97502d24abf081
diff --git a/README.md b/README.md
index 6fea8e1..3f0f554 100644
--- a/README.md
+++ b/README.md
@@ -1,244 +1,121 @@
-# Hyper-Extract 🧠✨
+# Hyper-Extract: From Text to Actionable Knowledge Structures 🚀
-> **An Intelligent, LLM-Powered Knowledge Extraction Framework**
->
-> Transform unstructured text into structured Auto containers with the power of Large Language Models.
+[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
+[![Python](https://img.shields.io/badge/python-3.10%2B-blue)](pyproject.toml)
----
-
-## 🎯 Vision
+**Hyper-Extract** is a next-generation knowledge extraction framework designed to transform unstructured text into **searchable, queryable, and actionable** structured knowledge.
-**Hyper-Extract** provides a powerful framework for intelligent knowledge extraction. Rather than treating data structures as passive containers, we empower them with **LLM-driven intelligence** to actively extract, merge, and index knowledge from unstructured text.
+Unlike traditional extraction tools that only output static data, Hyper-Extract automatically converts extracted structures (Lists, Graphs, Hypergraphs) into an interactive knowledge base. You can directly chat with the structure, perform precise semantic searches, and realize "Extraction as an Application."
-Every Auto container in Hyper-Extract follows a unified lifecycle:
-
-1. **Extract** - Intelligent extraction from text with automatic chunking and merging
-2. **Merge** - Automatic aggregation with configurable merge strategies
-3. **Index** - Semantic vector search capabilities
-4. **Serialize** - Persist and reload knowledge with full fidelity
+[中文版自述文件 (README_ZH.md)](README_ZH.md)
---
-## ✨ Key Features
-
-### 🤖 LLM-Native Design
-- **Deep LangChain Integration**: Every container is initialized with LLM and embedder instances
-- **Structured Output**: Leverage `with_structured_output` for type-safe Pydantic schema extraction
-- **Intelligent Merging**: First-priority merge strategy for chunk-based extraction
+## 🌟 Key Highlights
-### 🏗️ Unified Architecture
-- **Abstract Base Class**: `BaseAutoType[T]` provides consistent interface across all knowledge types
-- **Generic Type Support**: Full Python typing with `Generic[T]` for schema flexibility
-- **Lifecycle Management**: Standardized `extract` → `merge` → `search` → `dump/load` pipeline
-
-### 🔍 Semantic Search
-- **FAISS Integration**: Fast vector similarity search for knowledge retrieval
-- **Automatic Indexing**: Build and maintain indices with lazy loading and dirty tracking
-- **Field-Level Search**: Search across all schema fields with metadata preservation
-
-### 📦 Multiple Knowledge Types (Roadmap)
-- ✅ **AutoModel**: Universal schema-agnostic knowledge extraction
-- ✅ **AutoList**: Collection-based extraction for lists of items
-- ✅ **AutoSet**: Unique collection with automatic deduplication
-- 🚧 **AutoGraph**: Knowledge graph construction (nodes + edges)
-- 🚧 **AutoHypergraph**: Hypergraph representation for complex multi-entity relations
-- 🚧 **ExtractionExperience**: Meta-learning from extraction patterns
+- **📂 Universal Structure Support**:
+ - **Foundational**: List, Set, General Knowledge Graph.
+ - **Dynamics**: Temporal Graph (time-series events), Spatial Graph (geographical topology), Spatio-Temporal Graph.
+ - **Complex Relations**: Hypergraph (N-ary relations), perfect for modeling group interactions and holistic context.
+- **💬 Actionable Knowledge (RAG 2.0)**:
+ - Extraction is just the beginning. Hyper-Extract automatically builds vector indices for every extracted entity and relationship.
+ - **Chat with Structure**: Query your graph or list directly to get answers backed by structured logic.
+- **🛠️ Production-Ready SOTA Algorithms**:
+ - Built-in implementations of cutting-edge extraction and RAG paradigms: `Auto-Gen`, `Hyper-RAG`, `Light-RAG`, `GraphRAG`, `CogRAG`, and more.
+- **🎭 Massive Domain Templates**:
+ - 20+ out-of-the-box templates covering: Finance, Medicine, Law, Gaming, Agriculture, Cybersecurity, Physics, Literature, etc.
---
-## 🛠️ Installation
-
-### Prerequisites
-- Python 3.10+
-- OpenAI API key (or compatible LLM provider)
-
-### Install with uv (Recommended)
-```bash
-# Clone the repository
-git clone https://github.com/your-username/hyper-extract.git
-cd hyper-extract
+## 🚀 Quick Start
-# Install dependencies with uv
-uv sync
-```
+### Installation
-### Install with pip
```bash
-pip install -r requirements.txt
+pip install hyperextract
```
----
-
-## 🚀 Quick Start
+### Build an "Intelligent Knowledge Graph" in 3 Steps
-### 1. Define Your Knowledge Schema
+Hyper-Extract makes complex extraction and interaction dead simple:
```python
from pydantic import BaseModel, Field
-from typing import List
-
-class ArticleSchema(BaseModel):
- """Schema for article knowledge extraction"""
- title: str = Field(default="", description="Article title")
- author: str = Field(default="", description="Author name")
- summary: str = Field(default="", description="Article summary")
- key_points: List[str] = Field(default_factory=list, description="Key points")
- topics: List[str] = Field(default_factory=list, description="Topic tags")
-```
-
-### 2. Initialize Auto Container
-
-```python
+from hyperextract.graphs import AutoGraph
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
-from hyperextract import AutoModel
-
-# Initialize LLM and embedder
-llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
-embedder = OpenAIEmbeddings(model="text-embedding-3-small")
-
-# Create Auto container
-a_article = AutoModel(
- data_schema=ArticleSchema,
- llm_client=llm,
- embedder=embedder,
- chunk_size=2000, # Auto-split long texts
- max_workers=5, # Concurrent processing
- verbose=True
-)
-```
-
-### 3. Extract Knowledge from Text
-
-```python
-article_text = """
-Title: The Future of AI
-Author: Dr. Jane Smith
-
-Artificial intelligence is transforming industries...
-[Your long article text here]
-"""
-
-# Extract with automatic chunking and merging
-result = a_article.extract(article_text)
-print(f"Extraction completed: {result}")
-
-# Access extracted data
-print(f"Title: {a_article.data.title}")
-print(f"Author: {a_article.data.author}")
-print(f"Key points: {a_article.data.key_points}")
-```
-
-### 4. Semantic Search
-
-```python
-# Build vector index
-a_article.build_index()
-# Search with natural language
-results = a_article.search("What are the main topics?", top_k=3)
-for result in results:
- print(result)
-```
-
-### 5. Save and Load
+# 1. Define your world view (Schema)
+class entity(BaseModel):
+ name: str = Field(description="Name of the entity")
+ type: str = Field(description="Category, e.g., Person, Company, Location")
+
+class edge(BaseModel):
+ source: str = Field(description="Source entity name")
+ target: str = Field(description="Target entity name")
+ relation: str = Field(description="The relationship between them")
+
+# 2. Initialize and Build from Text
+llm = ChatOpenAI(model="gpt-4o")
+embedder = OpenAIEmbeddings()
+
+graph_kb = AutoGraph(
+ node_schema=entity,
+ edge_schema=edge,
+ # Unique key extractors for deduplication and linking
+ node_key_extractor=lambda x: x.name,
+ edge_key_extractor=lambda x: f"{x.source}_{x.relation}_{x.target}",
+ nodes_in_edge_extractor=lambda x: (x.source, x.target),
+ llm_client=llm,
+ embedder=embedder
+)
-```python
-# Save to folder (includes data + FAISS index)
-a_article.dump("./output/my_article")
+text = "Apple Inc. was founded by Steve Jobs in California, and it is the maker of the iPhone."
+graph_kb.feed_text(text) # Extract knowledge
+graph_kb.build_index() # Build vector index for Q&A
-# Load from folder
-a_article.load("./output/my_article")
+# 3. Chat with the Structure (Actionable!)
+answer = graph_kb.chat("What is the relationship between Jobs and Apple?")
+print(answer.content)
```
---
-## 🏛️ Architecture
+## 🎨 Domain Templates
-### Design Principles
+The `hyperextract/templates` directory provides a wealth of domain-specific definitions that you can import directly without writing prompts from scratch:
-1. **Template Method Pattern**: `BaseAutoType` defines the extraction skeleton, subclasses customize behavior
-2. **First-Priority Merge**: `model_copy(update=model_dump(exclude_none=True))` for conflict resolution
-3. **Lazy Indexing**: Build FAISS indices only when needed, track with `_index_dirty` flag
-4. **Type Safety**: Leverage Pydantic for runtime validation and IDE support
+| Category | Templates | Description |
+| :--- | :--- | :--- |
+| **General** | `General`, `IText2KG` | Versatile extraction for most daily knowledge. |
+| **Science** | `Physics`, `Chemistry`, `Biology` | Capture experiments, elements, and reactions. |
+| **Industry** | `Finance`, `Legal`, `Cybersecurity` | Extract compliance, risks, and entity webs. |
+| **Entertainment** | `Game`, `Movie`, `Music` | Perfect for story plots and character networks. |
+| ... | | 20+ more domains in the [templates folder](hyperextract/templates) |
---
-## 📚 Examples
+## 🏗️ Core Components
-Check out the `examples/` directory for complete working examples:
-
-- [`auto_model_demo.py`](examples/auto_model_demo.py) - Full AutoModel walkthrough
-- More examples coming soon!
+- **`hyperextract.core`**: Core abstraction layer handling long-text chunking, parallel processing, and knowledge aggregation.
+- **`hyperextract.graphs`**: Various graph components including spatial, temporal, and standard graphs.
+- **`hyperextract.hypergraphs`**: Powerful Hypergraph-based RAG implementations for complex multi-entity logic.
+- **`hyperextract.utils`**: Essential utilities for logging and merging strategies.
---
-## 🗺️ Roadmap
-
-### Phase 1: Foundation (Current) ✅
-- [x] Abstract `BaseAutoType` class
-- [x] `AutoModel` implementation
-- [x] LangChain integration with structured output
-- [x] FAISS vector search
-- [x] Serialization (dump/load)
-
-### Phase 2: Specialized Knowledge Types 🚧
-- [ ] `AutoGraph` - Full knowledge graph construction
-- [ ] `AutoHypergraph` - Hypergraph for complex relations
-- [ ] `AutoTree` - Hierarchical tree structures
+## 📚 Implemented Algorithms & Paper Demos
-### Phase 3: Evolution & Learning 🔮
-- [ ] `evolve()` implementation with reasoning
-- [ ] Extraction experience learning
-- [ ] Confidence scoring and quality metrics
-- [ ] Active learning for schema refinement
-
-### Phase 4: Advanced Features 🚀
-- [ ] Multi-modal extraction (images, tables, PDFs)
-- [ ] Incremental updates and versioning
-- [ ] Distributed processing for massive datasets
-- [ ] Integration with graph databases (Neo4j, NetworkX)
+- **Auto-Graph**: Schema-adaptive graph extraction.
+- **Hyper-RAG**: Retrieval Augmented Generation via Hypergraphs.
+- **Light-RAG**: Lightweight and efficient graph retrieval.
+- **IText2KG / IText2KG-Star**: Iterative Knowledge Graph generation.
+- **CogRAG**: Cognition-driven hierarchical retrieval.
---
## 🤝 Contributing
-We welcome contributions! Whether it's:
-
-- 🐛 Bug reports and fixes
-- 💡 Feature suggestions
-- 📖 Documentation improvements
-- 🧪 New knowledge type implementations
-
-Please open an issue or submit a PR. Check out our [contributing guidelines](CONTRIBUTING.md) (coming soon).
-
----
-
-## 📄 License
-
-This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
-
----
-
-## 🙏 Acknowledgments
-
-- Built with [LangChain](https://github.com/langchain-ai/langchain) for LLM orchestration
-- Powered by [Pydantic](https://github.com/pydantic/pydantic) for data validation
-- Vector search by [FAISS](https://github.com/facebookresearch/faiss)
-- Inspired by the vision of self-evolving knowledge systems
-
----
-
-## 📬 Contact
-
-- **GitHub Issues**: [Create an issue](https://github.com/yifanfeng97/hyper-extract/issues)
-- **Email**: [email protected]
-
----
-
-<div align="center">
-
-**⭐ Star this repo if you find it useful! ⭐**
-
-*Building the future of intelligent knowledge extraction, one container at a time.*
+We welcome Issues and Pull Requests!
-</div>
+- **License**: [MIT LICENSE](LICENSE)
+- **Support**: If you find this project helpful, please give us a ⭐️!
diff --git a/README_ZH.md b/README_ZH.md
new file mode 100644
index 0000000..77a4432
--- /dev/null
+++ b/README_ZH.md
@@ -0,0 +1,121 @@
+# Hyper-Extract: 从文本到可交互的知识结构 🚀
+
+[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
+[![Python](https://img.shields.io/badge/python-3.10%2B-blue)](pyproject.toml)
+
+**Hyper-Extract** 是一个下一代知识提取框架,旨在将非结构化文本转化为**可搜索、可查询、可问答**的结构化知识。
+
+区别于传统的只负责“提取”的工具,Hyper-Extract 将提取出的结构(如列表、图谱、超图)自动转化为可交互的知识库。你可以直接与提取出的结构进行对话,进行精确的语义搜索,实现“提取即应用”。
+
+[English README](README.md)
+
+---
+
+## 🌟 核心特性
+
+- **📂 全模态结构支持**:
+ - **基础结构**: List (列表), Set (集合), Graph (通用图谱)。
+ - **时空动力学**: Temporal Graph (时序图), Spatial Graph (地理图), Spatio-Temporal Graph (时空图)。
+ - **复杂关联**: Hypergraph (超图/多元图),支持多对多复杂关系建模。
+- **💬 结构化知识问答 (RAG 2.0)**:
+ - 提取不仅仅是终点。Hyper-Extract 自动为提取出的实体和关系建立向量索引。
+ - **Chat with Structure**: 直接针对图谱或集合进行问答,获得具有结构化逻辑支撑的答案。
+- **🛠️ 工业级算法复现**:
+ - 内置了多种 SOTA 提取与检索算法的复现,包括 `Auto-Gen`, `Hyper-RAG`, `Light-RAG`, `GraphRAG`, `CogRAG` 等。
+- **🎭 领域专家模版库**:
+ - 提供了 20+ 个领域的开箱即用模版,涵盖:金融、医疗、法律、游戏、农业、网络安全、物理、文学等。
+
+---
+
+## 🚀 快速上手
+
+### 安装
+
+```bash
+pip install hyperextract
+```
+
+### 3步实现“对话知识图谱”
+
+Hyper-Extract 让复杂结构的提取和使用变得异常简单:
+
+```python
+from pydantic import BaseModel, Field
+from hyperextract.graphs import AutoGraph
+from langchain_openai import ChatOpenAI, OpenAIEmbeddings
+
+# 1. 定义你想要提取的结构 (Schema)
+class entity(BaseModel):
+ name: str = Field(description="实体名称")
+ type: str = Field(description="类别,如:人、公司、地点")
+
+class edge(BaseModel):
+ source: str = Field(description="源实体")
+ target: str = Field(description="目标实体")
+ relation: str = Field(description="它们之间的关系")
+
+# 2. 初始化提取器并从文本构建图谱
+llm = ChatOpenAI(model="gpt-4o")
+embedder = OpenAIEmbeddings()
+
+graph_kb = AutoGraph(
+ node_schema=entity,
+ edge_schema=edge,
+ # 唯一键提取规则,用于去重和关联
+ node_key_extractor=lambda x: x.name,
+ edge_key_extractor=lambda x: f"{x.source}_{x.relation}_{x.target}",
+ nodes_in_edge_extractor=lambda x: (x.source, x.target),
+ llm_client=llm,
+ embedder=embedder
+)
+
+text = "苹果公司由史蒂夫·乔布斯在加利福尼亚州创立,它是著名的iPhone制造商。"
+graph_kb.feed_text(text) # 提取知识
+graph_kb.build_index() # 构建向量索引 (用于后续问答)
+
+# 3. 针对提取出的结构进行问答 (Actionable!)
+answer = graph_kb.chat("乔布斯和苹果公司是什么关系?")
+print(answer.content)
+```
+
+---
+
+## 🎨 领域模版 (Templates)
+
+本项目在 `hyperextract/templates` 下提供了丰富的领域定义,你可以直接导入使用,无需从头编写 Prompt 或 Schema:
+
+| 领域 | 包含模版 | 描述 |
+| :--- | :--- | :--- |
+| **通用** | `General`, `IText2KG` | 适用于大多数日常知识提取。 |
+| **科学** | `Physics`, `Chemistry`, `Biology` | 捕捉科学实验、元素、反应过程。 |
+| **行业** | `Finance`, `Legal`, `Cybersecurity` | 提取合规、风险点、实体关联。 |
+| **娱乐** | `Game`, `Movie`, `Music` | 完美支持游戏剧情、角色关系网。 |
+| ... | | 更多 20+ 领域见 [templates 目录](hyperextract/templates) |
+
+---
+
+## 🏗️ 核心组件
+
+- **`hyperextract.core`**: 核心抽象层,管理长文本切片、并行处理与知识聚合。
+- **`hyperextract.graphs`**: 各类图谱组件(包括时空、地理、标准图谱)。
+- **`hyperextract.hypergraphs`**: 强大的超图 RAG 实现,处理超出一对一关系的复杂逻辑。
+- **`hyperextract.utils`**: 日志、合并策略等实用工具。
+
+---
+
+## 📚 已复现论文/算法
+
+- **Auto-Graph**: 自动 Schema 适应的图提取。
+- **Hyper-RAG**: 基于超图的检索增强生成。
+- **Light-RAG**: 轻量化、高效率的图检索。
+- **IText2KG / IText2KG-Star**: 迭代式知识图谱生成。
+- **CogRAG**: 认知驱动的层次化检索。
+
+---
+
+## 🤝 贡献与反馈
+
+欢迎提交 Issue 或 Pull Request 来完善这个项目!
+
+- **开源协议**: [MIT LICENSE](LICENSE)
+- **Star我们**: 如果这个项目对你有帮助,请给一个 ⭐️ 以示支持!
diff --git a/hyperextract/templates/__init__.py b/hyperextract/templates/__init__.py
index e69de29..7f2a477 100644
--- a/hyperextract/templates/__init__.py
+++ b/hyperextract/templates/__init__.py
@@ -0,0 +1,6 @@
+from . import en, zh
+
+__all__ = [
+ "en",
+ "zh",
+]
diff --git a/hyperextract/templates/en/README.md b/hyperextract/templates/en/README.md
new file mode 100644
index 0000000..c2aa374
--- /dev/null
+++ b/hyperextract/templates/en/README.md
@@ -0,0 +1,50 @@
+# Hyper-Extract Domain Templates (English)
+
+Welcome to the **Hyper-Extract Domain Templates** library. This directory contains a robust, flat collection of pre-defined schemas, prompts, and extraction models tailored for specific industries and expertise areas.
+
+## Design Philosophy
+- **Flat Discovery**: No deep nesting. Find your domain directly in the top-level folders.
+- **Intuitive Naming**: Folders are named after common industry terminology (e.g., `finance`, `medicine`, `game`).
+- **Schema-Driven**: Each template provides a professional Pydantic schema to ensure high-quality extraction.
+
+## Domain Index
+
+| Folder | Description | Potential Use Cases |
+| :--- | :--- | :--- |
+| **`agriculture`** | Farming, livestock, and crop management. | Crop rotation, irrigation systems. |
+| **`art`** | Fine arts, museum collections, and provenance. | Artwork catalogs, historical art movements. |
+| **`automotive`** | Vehicles, manufacturing, and maintenance. | Car specs, maintenance logs. |
+| **`biology`** | Life sciences, genetics, and taxonomy. | Protein interactions, species classification. |
+| **`business`** | General corporate profiles and strategy. | Company bios, strategic goals. |
+| **`chemistry`** | Molecular structures and reactions. | Chemical compounds, lab experiments. |
+| **`construction`** | Building, BIM, and project planning. | Construction milestones, blueprint entities. |
+| **`cybersecurity`** | Threat intelligence and network defense. | STIX models, attack vectors. |
+| **`education`** | Knowledge points and curriculum. | Course prerequisites, learning paths. |
+| **`environment`** | Climate, ecology, and sustainability. | Weather patterns, carbon footprint tracking. |
+| **`fashion`** | Garments, trends, and collections. | Design lookbooks, seasonal trends. |
+| **`finance`** | Banking, stocks, and investments. | Earnings reports, stock analysis. |
+| **`food`** | Culinary, recipes, and nutrition. | Menu planning, recipe breakdown. |
+| **`game`** | Game lore, mechanics, and quests. | NPC relations, quest trees, item crafting. |
+| **`general`** | Basic encyclopedic knowledge. | General Person/Org/Event extraction. |
+| **`history`** | Events, timelines, and figures. | War campaigns, historical biographies. |
+| **`legal`** | Law, contracts, and compliance. | Contract obligations, court rulings. |
+| **`literature`** | Fiction, poetry, and character arcs. | Character maps, literary themes. |
+| **`marketing`** | Campaigns, SEO, and personas. | Customer journeys, brand archetypes. |
+| **`medicine`** | Western and clinical medicine. | Diagnosis, symptom mapping, pharma. |
+| **`movie`** | Film, TV, and scripts. | Screenplay beats, cast & crew networks. |
+| **`music`** | Theory, albums, and discography. | Genre evolution, tracklists. |
+| **`news`** | Media and trending topics. | Investigative boards, causality analysis. |
+| **`physics`** | Particle physics, astronomy, and circuits. | Celestial systems, circuit paths. |
+| **`politics`** | Governance, policy, and geopolitics. | Legislative tracking, election maps. |
+| **`real_estate`** | Property, leasing, and zoning. | Property listings, floor plans. |
+| **`recruitment`** | HR, resumes, and hiring. | Skill mapping, interview assessment. |
+| **`software`** | Architecture, APIs, and DevOps. | Microservices, software dependencies. |
+| **`sports`** | Tournaments, matches, and stats. | Match event logs, player profiles. |
+| **`supply_chain`**| Logistics and inventory flow. | Supplier tiering, logistics routes. |
+| **`travel`** | Tourism and itineraries. | Trip planning, attraction reviews. |
+
+## Usage
+Simply import the template you need:
+```python
+from hyperextract.templates.en.finance import StockGraph
+```
diff --git a/hyperextract/templates/en/__init__.py b/hyperextract/templates/en/__init__.py
index e69de29..0050835 100644
--- a/hyperextract/templates/en/__init__.py
+++ b/hyperextract/templates/en/__init__.py
@@ -0,0 +1,9 @@
+from .general.knowledge_graph import KnowledgeGraph
+from .general.concept_map import ConceptMap
+from .general.logic_graph import LogicGraph
+
+__all__ = [
+ "KnowledgeGraph",
+ "ConceptMap",
+ "LogicGraph",
+]
diff --git a/hyperextract/templates/en/graphs/__init__.py b/hyperextract/templates/en/agriculture/__init__.py
similarity index 100%
rename from hyperextract/templates/en/graphs/__init__.py
rename to hyperextract/templates/en/agriculture/__init__.py
diff --git a/hyperextract/templates/en/hypergraph/__init__.py b/hyperextract/templates/en/art/__init__.py
similarity index 100%
rename from hyperextract/templates/en/hypergraph/__init__.py
rename to hyperextract/templates/en/art/__init__.py
diff --git a/hyperextract/templates/en/sets/__init__.py b/hyperextract/templates/en/automotive/__init__.py
similarity index 100%
rename from hyperextract/templates/en/sets/__init__.py
rename to hyperextract/templates/en/automotive/__init__.py
diff --git a/hyperextract/templates/en/trees/__init__.py b/hyperextract/templates/en/biology/__init__.py
similarity index 100%
rename from hyperextract/templates/en/trees/__init__.py
rename to hyperextract/templates/en/biology/__init__.py
diff --git a/hyperextract/templates/zh/graphs/__init__.py b/hyperextract/templates/en/business/__init__.py
similarity index 100%
rename from hyperextract/templates/zh/graphs/__init__.py
rename to hyperextract/templates/en/business/__init__.py
diff --git a/hyperextract/templates/zh/hypergraph/__init__.py b/hyperextract/templates/en/chemistry/__init__.py
similarity index 100%
rename from hyperextract/templates/zh/hypergraph/__init__.py
rename to hyperextract/templates/en/chemistry/__init__.py
diff --git a/hyperextract/templates/zh/sets/__init__.py b/hyperextract/templates/en/construction/__init__.py
similarity index 100%
rename from hyperextract/templates/zh/sets/__init__.py
rename to hyperextract/templates/en/construction/__init__.py
diff --git a/hyperextract/templates/zh/trees/__init__.py b/hyperextract/templates/en/cybersecurity/__init__.py
similarity index 100%
rename from hyperextract/templates/zh/trees/__init__.py
rename to hyperextract/templates/en/cybersecurity/__init__.py
diff --git a/hyperextract/trees/base.py b/hyperextract/templates/en/education/__init__.py
similarity index 100%
rename from hyperextract/trees/base.py
rename to hyperextract/templates/en/education/__init__.py
diff --git a/hyperextract/templates/en/environment/__init__.py b/hyperextract/templates/en/environment/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/fashion/__init__.py b/hyperextract/templates/en/fashion/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/finance/__init__.py b/hyperextract/templates/en/finance/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/food/__init__.py b/hyperextract/templates/en/food/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/game/__init__.py b/hyperextract/templates/en/game/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/general/__init__.py b/hyperextract/templates/en/general/__init__.py
new file mode 100644
index 0000000..aa993f8
--- /dev/null
+++ b/hyperextract/templates/en/general/__init__.py
@@ -0,0 +1,23 @@
+"""General purpose knowledge graph templates.
+
+This module provides foundational templates for general information extraction:
+- KnowledgeGraph: Factual entity-relationship mapping for news and biographies.
+- ConceptMap: Semantic definitions and taxonomies for technical/educational content.
+- LogicGraph: Analysis of reasoning, arguments, and causal chains in analytical text.
+"""
+
+from .knowledge_graph import KnowledgeGraph, Entity, Relation
+from .concept_map import ConceptMap, Concept, ConceptRelation
+from .logic_graph import LogicGraph, LogicNode, LogicRelation
+
+__all__ = [
+ "KnowledgeGraph",
+ "Entity",
+ "Relation",
+ "ConceptMap",
+ "Concept",
+ "ConceptRelation",
+ "LogicGraph",
+ "LogicNode",
+ "LogicRelation",
+]
diff --git a/hyperextract/templates/en/general/concept_map.py b/hyperextract/templates/en/general/concept_map.py
new file mode 100644
index 0000000..690d32e
--- /dev/null
+++ b/hyperextract/templates/en/general/concept_map.py
@@ -0,0 +1,69 @@
+from typing import List, Optional
+from pydantic import BaseModel, Field
+from hyperextract.graphs import AutoGraph
+
+# ==============================================================================
+# 1. Schema Definitions
+# ==============================================================================
+
+class Concept(BaseModel):
+ """A conceptual node representing a term, idea, or theory."""
+ term: str = Field(description="The technical term or concept name.")
+ definition: str = Field(description="A formal definition or explanation of the concept.")
+ examples: Optional[List[str]] = Field(default_factory=list, description="Examples that illustrate this concept.")
+ attributes: Optional[List[str]] = Field(default_factory=list, description="Key properties or attributes of the concept.")
+
+class ConceptRelation(BaseModel):
+ """A semantic relationship between two concepts."""
+ source: str = Field(description="The source concept.")
+ target: str = Field(description="The target concept.")
+ relation_type: str = Field(
+ description="Type of relationship (e.g., is-a, part-of, related-to, used-for, instance-of)."
+ )
+
+# ==============================================================================
+# 2. Prompts
+# ==============================================================================
+
+CONCEPT_MAP_PROMPT = (
+ "You are an expert in semantic modeling. Extract a concept map from the text, focusing on "
+ "definitions, terminologies, and their hierarchical or associative relationships.\n\n"
+ "Guidelines:\n"
+ "- Identify core terms and provide their precise definitions based on the text.\n"
+ "- Use standard semantic relations like 'is-a' (inheritance) or 'part-of' (composition).\n"
+ "- Capture illustrative examples if mentioned."
+)
+
+CONCEPT_MAP_NODE_PROMPT = (
+ "Extract all foundational concepts and technical terms from the text. "
+ "For each concept, provide its term, a precise definition, a list of key attributes, "
+ "and any specific examples mentioned in the source."
+)
+
+CONCEPT_MAP_EDGE_PROMPT = (
+ "Establish semantic relationships between the provided concepts. "
+ "Focus on hierarchical taxonomies (is-a, part-of) and functional associations (used-for, instance-of). "
+ "Ensure edges logically connect the defined concepts."
+)
+
+# ==============================================================================
+# 3. Template Class
+# ==============================================================================
+
+class ConceptMap(AutoGraph[Concept, ConceptRelation]):
+ """
+ A template for building conceptual graphs and taxonomies.
+ Ideal for technical documentation, educational materials, and glossaries.
+ """
+ def __init__(self, **kwargs):
+ super().__init__(
+ node_schema=Concept,
+ edge_schema=ConceptRelation,
+ node_key_extractor=lambda x: x.term.strip(),
+ edge_key_extractor=lambda x: f"{x.source.strip()}--({x.relation_type.lower()})-->{x.target.strip()}",
+ nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),
+ prompt=CONCEPT_MAP_PROMPT,
+ prompt_for_node_extraction=CONCEPT_MAP_NODE_PROMPT,
+ prompt_for_edge_extraction=CONCEPT_MAP_EDGE_PROMPT,
+ **kwargs
+ )
diff --git a/hyperextract/templates/en/general/knowledge_graph.py b/hyperextract/templates/en/general/knowledge_graph.py
new file mode 100644
index 0000000..3d3a3bd
--- /dev/null
+++ b/hyperextract/templates/en/general/knowledge_graph.py
@@ -0,0 +1,71 @@
+from typing import List, Optional
+from pydantic import BaseModel, Field
+from hyperextract.graphs import AutoGraph
+
+# ==============================================================================
+# 1. Schema Definitions
+# ==============================================================================
+
+class Entity(BaseModel):
+ """A general entity representing a person, organization, location, or object."""
+ name: str = Field(description="The primary name of the entity.")
+ category: str = Field(
+ description="Category of the entity (e.g., Person, Organization, Location, Event, Object)."
+ )
+ description: Optional[str] = Field(
+ description="A concise summary of the entity and its role in the text."
+ )
+
+class Relation(BaseModel):
+ """A factual relationship between two entities."""
+ source: str = Field(description="The name of the source entity.")
+ target: str = Field(description="The name of the target entity.")
+ relation: str = Field(description="The type of relationship (e.g., Works for, Located in, Born in, Acquired).")
+ details: Optional[str] = Field(description="Additional context or details about this relationship.")
+
+# ==============================================================================
+# 2. Prompts
+# ==============================================================================
+
+KNOWLEDGE_GRAPH_PROMPT = (
+ "You are an expert knowledge extraction system. Your task is to extract a factual knowledge graph "
+ "from the provided text. Focus on identifying key entities (People, Organizations, Locations, and relevant Objects) "
+ "and the explicit relationships between them.\n\n"
+ "Guidelines:\n"
+ "- Extract distinct entitles and their factual properties.\n"
+ "- Map relationships that describe how entities interact or are connected.\n"
+ "- Use clear, concise language for descriptions and relations."
+)
+
+KNOWLEDGE_GRAPH_NODE_PROMPT = (
+ "Extract all key entities from the text. Focus on identifying People, Organizations, Locations, and important Objects. "
+ "Provide a name, a category, and a concise description for each entity."
+)
+
+KNOWLEDGE_GRAPH_EDGE_PROMPT = (
+ "Identify factual relationships between the following listed entities based on the text. "
+ "Focus on interactions like 'works for', 'located in', 'acquired', or 'partnered with'. "
+ "Do not hallucinate entities not in the provided list."
+)
+
+# ==============================================================================
+# 3. Template Class
+# ==============================================================================
+
+class KnowledgeGraph(AutoGraph[Entity, Relation]):
+ """
+ A foundational knowledge graph template for factual extraction.
+ Best for news, biographies, and descriptive encyclopedic content.
+ """
+ def __init__(self, **kwargs):
+ super().__init__(
+ node_schema=Entity,
+ edge_schema=Relation,
+ node_key_extractor=lambda x: x.name.strip(),
+ edge_key_extractor=lambda x: f"{x.source.strip()}--[{x.relation.lower()}]-->{x.target.strip()}",
+ nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),
+ prompt=KNOWLEDGE_GRAPH_PROMPT,
+ prompt_for_node_extraction=KNOWLEDGE_GRAPH_NODE_PROMPT,
+ prompt_for_edge_extraction=KNOWLEDGE_GRAPH_EDGE_PROMPT,
+ **kwargs
+ )
diff --git a/hyperextract/templates/en/general/logic_graph.py b/hyperextract/templates/en/general/logic_graph.py
new file mode 100644
index 0000000..56362ab
--- /dev/null
+++ b/hyperextract/templates/en/general/logic_graph.py
@@ -0,0 +1,67 @@
+from typing import List, Optional
+from pydantic import BaseModel, Field
+from hyperextract.graphs import AutoGraph
+
+# ==============================================================================
+# 1. Schema Definitions
+# ==============================================================================
+
+class LogicNode(BaseModel):
+ """A node representing a claim, evidence, or premise in an argument."""
+ statement: str = Field(description="The central claim, fact, or observation.")
+ node_type: str = Field(
+ description="Type of node: Claim (main point), Evidence (supporting data), Premise (underlying assumption)."
+ )
+ source_attribution: Optional[str] = Field(description="Where or who this logic point originates from.")
+
+class LogicRelation(BaseModel):
+ """The logical connection between two statements."""
+ source: str = Field(description="The source statement.")
+ target: str = Field(description="The target statement.")
+ inference: str = Field(
+ description="The logical link: Supports, Contradicts, Proves, Leads to, Explains."
+ )
+
+# ==============================================================================
+# 2. Prompts
+# ==============================================================================
+
+LOGIC_GRAPH_PROMPT = (
+ "You are a logical analyst. Extract the reasoning structure from the text into a directed graph.\n\n"
+ "Guidelines:\n"
+ "- Identify the main claims (conclusions) and the evidence or premises that lead to them.\n"
+ "- Explicitly map how one statement supports or contradicts another.\n"
+ "- Do not just extract facts; extract the 'argument' and 'reasoning' flow."
+)
+
+LOGIC_GRAPH_NODE_PROMPT = (
+ "Extract the individual building blocks of the argument. Identify core claims, supporting evidence, "
+ "and underlying premises. For each, determine its type and note any source attribution mentioned."
+)
+
+LOGIC_GRAPH_EDGE_PROMPT = (
+ "Map the logical flow between the extracted claims and evidence. Focus on how statements "
+ "Support, Contradict, or Lead to one another. Ensure every edge represents a step in the reasoning chain."
+)
+
+# ==============================================================================
+# 3. Template Class
+# ==============================================================================
+
+class LogicGraph(AutoGraph[LogicNode, LogicRelation]):
+ """
+ A template for analyzing reasoning, arguments, and causal chains.
+ Ideal for analytical reports, debate transcripts, and scientific reasoning.
+ """
+ def __init__(self, **kwargs):
+ super().__init__(
+ node_schema=LogicNode,
+ edge_schema=LogicRelation,
+ node_key_extractor=lambda x: x.statement.strip(),
+ edge_key_extractor=lambda x: f"{x.source.strip()}--({x.inference.lower()})-->{x.target.strip()}",
+ nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),
+ prompt=LOGIC_GRAPH_PROMPT,
+ prompt_for_node_extraction=LOGIC_GRAPH_NODE_PROMPT,
+ prompt_for_edge_extraction=LOGIC_GRAPH_EDGE_PROMPT,
+ **kwargs
+ )
diff --git a/hyperextract/templates/en/history/__init__.py b/hyperextract/templates/en/history/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/legal/__init__.py b/hyperextract/templates/en/legal/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/literature/__init__.py b/hyperextract/templates/en/literature/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/marketing/__init__.py b/hyperextract/templates/en/marketing/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/medicine/__init__.py b/hyperextract/templates/en/medicine/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/movie/__init__.py b/hyperextract/templates/en/movie/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/music/__init__.py b/hyperextract/templates/en/music/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/news/__init__.py b/hyperextract/templates/en/news/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/physics/__init__.py b/hyperextract/templates/en/physics/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/politics/__init__.py b/hyperextract/templates/en/politics/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/real_estate/__init__.py b/hyperextract/templates/en/real_estate/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/recruitment/__init__.py b/hyperextract/templates/en/recruitment/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/software/__init__.py b/hyperextract/templates/en/software/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/sports/__init__.py b/hyperextract/templates/en/sports/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/supply_chain/__init__.py b/hyperextract/templates/en/supply_chain/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/en/travel/__init__.py b/hyperextract/templates/en/travel/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/README.md b/hyperextract/templates/zh/README.md
new file mode 100644
index 0000000..c634969
--- /dev/null
+++ b/hyperextract/templates/zh/README.md
@@ -0,0 +1,53 @@
+# Hyper-Extract 领域知识模板 (中文版)
+
+欢迎使用 **Hyper-Extract 领域模板库**。这里提供了一系列针对中文语境和国内行业标准优化的提取模板。
+
+## 设计理念
+- **直觉导航**:采用扁平化目录结构,拒绝深层嵌套。
+- **行业深度**:每个模板均由特定领域的知识结构(Schema)和提示词(Prompt)驱动。
+- **文化融合**:在保持与国际标准接轨的同时,特别加入了如中医(TCM)、武侠(Wuxia)等中国特色文化领域。
+
+## 领域索引
+
+| 目录名称 | 说明 | 应用场景示例 |
+| :--- | :--- | :--- |
+| **`tcm`** | **中医 (特色)** | 中草药方剂、经络穴位、辨证施治过程等。 |
+| **`wuxia`** | **武侠/修真 (特色)** | 门派恩怨、功法境界、修仙等级体系、法宝神兵。 |
+| **`general`** | 通用百科 | 人物、机构、事件、地点等基础实体的快速抽取。 |
+| **`finance`** | 金融投资 | A股/港股研报、基金招募说明书、上市公司季报。 |
+| **`legal`** | 法律合规 | 合同关键要素(义务、权利)、案情调查、法条引用。 |
+| **`education`** | 教育学术 | K12知识点图谱、课程大纲依赖关系、学术论文脉络。 |
+| **`business`** | 商业通用 | 公司全画像、股权穿透结构、商业战略目标。 |
+| **`medicine`** | 医学健康 | 疾病症状映射、临床诊疗路径、西药说明书结构化。 |
+| **`food`** | 美食餐饮 | 中餐菜谱(刀工、火候)、食材配比、八大菜系特征。 |
+| **`history`** | 历史文化 | 朝代更迭时间线、重大战役、历史人物生平关系。 |
+| **`literature`** | 文学 | 小说人物关系网、文学流派演变、古诗词意象关联。 |
+| **`software`** | 软件与IT | 系统架构图、接口定义、代码依赖关系、DevOps流程。 |
+| **`game`** | 游戏娱乐 | 游戏世界观设定、任务流向树、物品合成与掉落表。 |
+| **`sports`** | 体育竞技 | 赛事文字直播提取、球员身价与转会网络、战术阵型。 |
+| **`travel`** | 旅游出行 | 游记攻略结构化、景点关系图、旅行行程规划。 |
+| **`recruitment`**| 招聘简历 | 简历经历解析、技能标签映射、岗位/人才画像匹配。 |
+| **`marketing`** | 市场营销 | 用户旅程地图 (CJM)、品牌定位分析、营销活动链路。 |
+| **`supply_chain`**| 物流/供应链 | 供应链上下游追溯、物流节点关系、库存流转图。 |
+| **`agriculture`** | 农业与养殖 | 作物生长周期、病虫害防治、畜牧谱系与饲养标准。 |
+| **`art`** | 艺术与博物馆 | 艺术品流传有序图、艺术流派、博物馆馆藏关系。 |
+| **`automotive`** | 汽车工业 | 汽车参数配置、维保手册提取、零部件组成。 |
+| **`biology`** | 生物科学 | 生物分类学、蛋白质相互作用、基因调控网络。 |
+| **`chemistry`** | 化学科学 | 分子结构、化学反应方程式路径、材料物化特性。 |
+| **`physics`** | 物理与天文 | 天体运行系统、量子物理现象、电路逻辑连接图。 |
+| **`construction`**| 建筑工程 | 建筑信息模型 (BIM) 实体、施工进度节点、材料明细。 |
+| **`cybersecurity`**| 网络安全 | 攻击路径图、威胁情报 STIX 模型、系统漏洞分析。 |
+| **`environment`** | 环境与气候 | 气象变化趋势、碳排放追踪、生态系统食物网。 |
+| **`fashion`** | 时尚设计 | 时装系列设计元素、流行趋势周期、单品构成。 |
+| **`movie`** | 影视 | 剧本节拍器拆解、演员与幕后人员网络、影评情感。 |
+| **`music`** | 音乐 | 乐理结构、专辑曲目分类、流派演进。 |
+| **`news`** | 新闻传媒 | 事件因果链、新闻专题聚类、深度报道事实板。 |
+| **`politics`** | 政治与政府 | 政策影响分析、地缘政治关系网、选举数据地图。 |
+| **`real_estate`** | 房地产 | 房源户型特征、租赁协议要素、土地规划关系。 |
+
+*(注:英文版对应的 31 个通用领域在中文版中均有映射文件夹,中医与武侠为中文版独有)*
+
+## 快速上手
+```python
+from hyperextract.templates.zh.tcm import HerbGraph
+```
diff --git a/hyperextract/templates/zh/__init__.py b/hyperextract/templates/zh/__init__.py
index e69de29..0050835 100644
--- a/hyperextract/templates/zh/__init__.py
+++ b/hyperextract/templates/zh/__init__.py
@@ -0,0 +1,9 @@
+from .general.knowledge_graph import KnowledgeGraph
+from .general.concept_map import ConceptMap
+from .general.logic_graph import LogicGraph
+
+__all__ = [
+ "KnowledgeGraph",
+ "ConceptMap",
+ "LogicGraph",
+]
diff --git a/hyperextract/templates/zh/agriculture/__init__.py b/hyperextract/templates/zh/agriculture/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/art/__init__.py b/hyperextract/templates/zh/art/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/automotive/__init__.py b/hyperextract/templates/zh/automotive/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/biology/__init__.py b/hyperextract/templates/zh/biology/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/business/__init__.py b/hyperextract/templates/zh/business/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/chemistry/__init__.py b/hyperextract/templates/zh/chemistry/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/construction/__init__.py b/hyperextract/templates/zh/construction/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/cybersecurity/__init__.py b/hyperextract/templates/zh/cybersecurity/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/education/__init__.py b/hyperextract/templates/zh/education/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/environment/__init__.py b/hyperextract/templates/zh/environment/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/fashion/__init__.py b/hyperextract/templates/zh/fashion/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/finance/__init__.py b/hyperextract/templates/zh/finance/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/food/__init__.py b/hyperextract/templates/zh/food/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/game/__init__.py b/hyperextract/templates/zh/game/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/general/__init__.py b/hyperextract/templates/zh/general/__init__.py
new file mode 100644
index 0000000..8a8e6be
--- /dev/null
+++ b/hyperextract/templates/zh/general/__init__.py
@@ -0,0 +1,23 @@
+"""领域通用知识图谱模板。
+
+本模块提供基础的信息提取模板,适用于多种场景:
+- KnowledgeGraph: 事实实体-关系映射,适用于新闻、传记和百科。
+- ConceptMap: 语义定义与分类体系,适用于技术文档和教育材料。
+- LogicGraph: 推理分析、论证过程及因果链,适用于分析性文本。
+"""
+
+from .knowledge_graph import KnowledgeGraph, Entity, Relation
+from .concept_map import ConceptMap, Concept, ConceptRelation
+from .logic_graph import LogicGraph, LogicNode, LogicRelation
+
+__all__ = [
+ "KnowledgeGraph",
+ "Entity",
+ "Relation",
+ "ConceptMap",
+ "Concept",
+ "ConceptRelation",
+ "LogicGraph",
+ "LogicNode",
+ "LogicRelation",
+]
diff --git a/hyperextract/templates/zh/general/concept_map.py b/hyperextract/templates/zh/general/concept_map.py
new file mode 100644
index 0000000..af793dd
--- /dev/null
+++ b/hyperextract/templates/zh/general/concept_map.py
@@ -0,0 +1,66 @@
+from typing import List, Optional
+from pydantic import BaseModel, Field
+from hyperextract.graphs import AutoGraph
+
+# ==============================================================================
+# 1. Schema 定义 (Schema Definitions)
+# ==============================================================================
+
+class Concept(BaseModel):
+ """一个代表术语、想法或理论的概念节点。"""
+ term: str = Field(description="技术术语或概念的名称。")
+ definition: str = Field(description="该概念的正式定义或解释。")
+ examples: Optional[List[str]] = Field(default_factory=list, description="说明该概念的示例。")
+ attributes: Optional[List[str]] = Field(default_factory=list, description="该概念的关键特征或属性。")
+
+class ConceptRelation(BaseModel):
+ """两个概念之间的语义关系。"""
+ source: str = Field(description="源概念。")
+ target: str = Field(description="目标概念。")
+ relation_type: str = Field(
+ description="关系类型(例如:是一种 (is-a), 属于 (part-of), 相关于, 用于, 为...的实例)。"
+ )
+
+# ==============================================================================
+# 2. 提示词 (Prompts)
+# ==============================================================================
+
+CONCEPT_MAP_PROMPT = (
+ "你是一位语义建模专家。请从文本中提取概念图(Concept Map),重点关注术语定义及其层级或关联关系。\n\n"
+ "提取指南:\n"
+ "- 识别核心术语,并基于文本提供精确定义。\n"
+ "- 使用标准的语义关系词,如“是一种”(继承关系)或“属于”(组成关系)。\n"
+ "- 如果文本提到了说明性的示例,请一并捕获。"
+)
+
+CONCEPT_MAP_NODE_PROMPT = (
+ "请从文本中提取所有基础概念和技术术语。对于每个概念,提供其术语名称、精确定义、关键属性列表,"
+ "以及文本中提到的任何具体示例。"
+)
+
+CONCEPT_MAP_EDGE_PROMPT = (
+ "在提供的概念之间建立语义关系。重点关注层级分类(是一种、属于)以及功能性关联(用于、为...的实例)。"
+ "确保边逻辑上连接了已定义的各个概念。"
+)
+
+# ==============================================================================
+# 3. 模板类 (Template Class)
+# ==============================================================================
+
+class ConceptMap(AutoGraph[Concept, ConceptRelation]):
+ """
+ 用于构建概念图谱和分类体系的模板。
+ 适用于技术文档、教育材料、术语表解析等场景。
+ """
+ def __init__(self, **kwargs):
+ super().__init__(
+ node_schema=Concept,
+ edge_schema=ConceptRelation,
+ node_key_extractor=lambda x: x.term.strip(),
+ edge_key_extractor=lambda x: f"{x.source.strip()}--({x.relation_type.lower()})-->{x.target.strip()}",
+ nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),
+ prompt=CONCEPT_MAP_PROMPT,
+ prompt_for_node_extraction=CONCEPT_MAP_NODE_PROMPT,
+ prompt_for_edge_extraction=CONCEPT_MAP_EDGE_PROMPT,
+ **kwargs
+ )
diff --git a/hyperextract/templates/zh/general/knowledge_graph.py b/hyperextract/templates/zh/general/knowledge_graph.py
new file mode 100644
index 0000000..f853d4c
--- /dev/null
+++ b/hyperextract/templates/zh/general/knowledge_graph.py
@@ -0,0 +1,68 @@
+from typing import List, Optional
+from pydantic import BaseModel, Field
+from hyperextract.graphs import AutoGraph
+
+# ==============================================================================
+# 1. Schema 定义 (Schema Definitions)
+# ==============================================================================
+
+class Entity(BaseModel):
+ """通用实体,代表人物、组织、地点、物体或核心概念。"""
+ name: str = Field(description="实体的名称。")
+ category: str = Field(
+ description="实体的类别(例如:人物、组织、地理位置、概念、事件、物体)。"
+ )
+ description: Optional[str] = Field(
+ description="该实体的简要描述及其在文本中的作用。"
+ )
+
+class Relation(BaseModel):
+ """两个实体之间的事实关系。"""
+ source: str = Field(description="源实体的名。")
+ target: str = Field(description="目标实体的名称。")
+ relation: str = Field(description="关系类型(例如:任职于、位于、创立、收购)。")
+ details: Optional[str] = Field(description="关于该关系的额外上下文或详细描述。")
+
+# ==============================================================================
+# 2. 提示词 (Prompts)
+# ==============================================================================
+
+KNOWLEDGE_GRAPH_PROMPT = (
+ "你是一个专业的知识提取专家。你的任务是从提供的文本中提取一个事实知识图谱。"
+ "重点识别关键实体(人物、组织、地理位置、重要物体)以及它们之间明确的关系。\n\n"
+ "提取指南:\n"
+ "- 准确性:从文本中提取明确的实体及其事实属性。\n"
+ "- 关系映射:描述实体之间如何互动或连接。\n"
+ "- 简洁性:使用清晰、简洁的语言进行描述和关系定义。"
+)
+
+KNOWLEDGE_GRAPH_NODE_PROMPT = (
+ "请从文本中提取所有关键实体。重点识别人物、组织、地理位置以及重要的物体。"
+ "为每个实体提供名称、类别以及简明扼要的描述。"
+)
+
+KNOWLEDGE_GRAPH_EDGE_PROMPT = (
+ "基于文本识别以下已知实体之间的事实关系。重点关注如“任职于”、“位于”、“创立”或“收购”等互动。"
+ "请勿虚构不在列表中的实体。"
+)
+
+# ==============================================================================
+# 3. 模板类 (Template Class)
+# ==============================================================================
+
+class KnowledgeGraph(AutoGraph[Entity, Relation]):
+ """
+ 通用事实知识图谱模板,适用于新闻报道、百科条目及传记。
+ """
+ def __init__(self, **kwargs):
+ super().__init__(
+ node_schema=Entity,
+ edge_schema=Relation,
+ node_key_extractor=lambda x: x.name.strip(),
+ edge_key_extractor=lambda x: f"{x.source.strip()}--[{x.relation.lower()}]-->{x.target.strip()}",
+ nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),
+ prompt=KNOWLEDGE_GRAPH_PROMPT,
+ prompt_for_node_extraction=KNOWLEDGE_GRAPH_NODE_PROMPT,
+ prompt_for_edge_extraction=KNOWLEDGE_GRAPH_EDGE_PROMPT,
+ **kwargs
+ )
diff --git a/hyperextract/templates/zh/general/logic_graph.py b/hyperextract/templates/zh/general/logic_graph.py
new file mode 100644
index 0000000..85718a7
--- /dev/null
+++ b/hyperextract/templates/zh/general/logic_graph.py
@@ -0,0 +1,65 @@
+from typing import List, Optional
+from pydantic import BaseModel, Field
+from hyperextract.graphs import AutoGraph
+
+# ==============================================================================
+# 1. Schema 定义 (Schema Definitions)
+# ==============================================================================
+
+class LogicNode(BaseModel):
+ """代表论点中的主张、证据或前提的节点。"""
+ statement: str = Field(description="核心主张、事实或观察结果。")
+ node_type: str = Field(
+ description="节点类型:主张 (Claim), 证据 (Evidence), 前提 (Premise)。"
+ )
+ source_attribution: Optional[str] = Field(description="该逻辑点的来源或出处。")
+
+class LogicRelation(BaseModel):
+ """两个陈述之间的逻辑连接。"""
+ source: str = Field(description="源陈述。")
+ target: str = Field(description="目标陈述。")
+ inference: str = Field(
+ description="逻辑链路:支持 (Supports), 反驳 (Contradicts), 证明, 导致, 解释。"
+ )
+
+# ==============================================================================
+# 2. 提示词 (Prompts)
+# ==============================================================================
+
+LOGIC_GRAPH_PROMPT = (
+ "你是一位逻辑分析师。请将文本中的论证结构提取并转化为一个有向图。\n\n"
+ "提取指南:\n"
+ "- 识别主要主张(结论)以及引向这些结论的证据或前提。\n"
+ "- 明确映射一个陈述是如何支持或反驳另一个陈述的。\n"
+ "- 不仅要提取事实,更要提取“论证”和“推理”的流向。"
+)
+
+LOGIC_GRAPH_NODE_PROMPT = (
+ "请提取论证中的各个基本构成要素。识别核心主张、支持性证据和底层前提。对于每一项,确定其类型并记录提及的任何来源出处。"
+)
+
+LOGIC_GRAPH_EDGE_PROMPT = (
+ "映射提取出的主张与证据之间的逻辑流向。重点关注各个陈述之间是如何相互 支持、反驳 或 导致 彼此的。确保每条边都代表推理链中的一个步骤。"
+)
+
+# ==============================================================================
+# 3. 模板类 (Template Class)
+# ==============================================================================
+
+class LogicGraph(AutoGraph[LogicNode, LogicRelation]):
+ """
+ 用于分析论文推理、论证和因果链的模板。
+ 适用于分析报告、辩论内容、科研推理及逻辑分析。
+ """
+ def __init__(self, **kwargs):
+ super().__init__(
+ node_schema=LogicNode,
+ edge_schema=LogicRelation,
+ node_key_extractor=lambda x: x.statement.strip(),
+ edge_key_extractor=lambda x: f"{x.source.strip()}--({x.inference.lower()})-->{x.target.strip()}",
+ nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),
+ prompt=LOGIC_GRAPH_PROMPT,
+ prompt_for_node_extraction=LOGIC_GRAPH_NODE_PROMPT,
+ prompt_for_edge_extraction=LOGIC_GRAPH_EDGE_PROMPT,
+ **kwargs
+ )
diff --git a/hyperextract/templates/zh/history/__init__.py b/hyperextract/templates/zh/history/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/legal/__init__.py b/hyperextract/templates/zh/legal/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/literature/__init__.py b/hyperextract/templates/zh/literature/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/marketing/__init__.py b/hyperextract/templates/zh/marketing/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/medicine/__init__.py b/hyperextract/templates/zh/medicine/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/movie/__init__.py b/hyperextract/templates/zh/movie/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/music/__init__.py b/hyperextract/templates/zh/music/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/news/__init__.py b/hyperextract/templates/zh/news/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/physics/__init__.py b/hyperextract/templates/zh/physics/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/politics/__init__.py b/hyperextract/templates/zh/politics/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/real_estate/__init__.py b/hyperextract/templates/zh/real_estate/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/recruitment/__init__.py b/hyperextract/templates/zh/recruitment/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/software/__init__.py b/hyperextract/templates/zh/software/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/sports/__init__.py b/hyperextract/templates/zh/sports/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/supply_chain/__init__.py b/hyperextract/templates/zh/supply_chain/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/tcm/__init__.py b/hyperextract/templates/zh/tcm/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/travel/__init__.py b/hyperextract/templates/zh/travel/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/templates/zh/wuxia/__init__.py b/hyperextract/templates/zh/wuxia/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hyperextract/trees/__init__.py b/hyperextract/trees/__init__.py
deleted file mode 100644
index b0ce327..0000000
--- a/hyperextract/trees/__init__.py
+++ /dev/null
@@ -1,10 +0,0 @@
-"""Tree structures for hierarchical data extraction.
-
-This module provides tree-based Auto types for extracting hierarchical
-and nested data structures from unstructured text.
-"""
-
-# Tree implementations will be added here as they are developed
-# from .base import AutoTree
-
-__all__ = []