Hypergraph is more powerful. Transform unstructured text into structured knowledge with LLMs. Graphs, hypergraphs, and spatio-temporal extractions — with one command.
Refactor: Remove game and movie templates; add travel domain templates
yifanfeng97e7886a3c937d
diff --git a/hyperextract/templates/en/README.md b/hyperextract/templates/en/README.mdindex db6d303..8b263a2 100644--- a/hyperextract/templates/en/README.md+++ b/hyperextract/templates/en/README.md@@ -13,17 +13,15 @@ Welcome to the **Hyper-Extract Domain Templates** library. This directory contai| :--- | :--- | :--- || **`agriculture`** | Farming, livestock, and crop management. | Crop rotation, irrigation systems. || **`biology`** | Life sciences, genetics, and taxonomy. | Protein interactions, species classification. |-| **`education`** | Knowledge points and curriculum. | Course prerequisites, learning paths. || **`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. || **`medicine`** | Western and clinical medicine. | Diagnosis, symptom mapping, pharma. |-| **`movie`** | Film, TV, and scripts. | Screenplay beats, cast & crew networks. || **`news`** | Media and trending topics. | Investigative boards, causality analysis. |+| **`travel`** | Geography, tourism, and locations. | Travel guides, spatial relationships, tourism routes. |## Usagediff --git a/hyperextract/templates/en/education/__init__.py b/hyperextract/templates/en/education/__init__.pydeleted file mode 100644index 7aee758..0000000--- a/hyperextract/templates/en/education/__init__.py+++ /dev/null@@ -1,9 +0,0 @@-from .prerequisite_map import PrerequisiteMapGraph-from .academic_lexicon import AcademicLexiconSet-from .interdisciplinary_nexus import InterdisciplinaryNexusHypergraph--__all__ = [- "PrerequisiteMapGraph",- "AcademicLexiconSet",- "InterdisciplinaryNexusHypergraph",-]diff --git a/hyperextract/templates/en/education/academic_lexicon.py b/hyperextract/templates/en/education/academic_lexicon.pydeleted file mode 100644index 0b2e05d..0000000--- a/hyperextract/templates/en/education/academic_lexicon.py+++ /dev/null@@ -1,127 +0,0 @@-from typing import Optional, List, Any-from pydantic import BaseModel, Field-from langchain_core.language_models.chat_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoSet--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================---class AcademicTerm(BaseModel):- """- A standardized academic term, concept, or definition aggregated from multiple sources.- """-- term: str = Field(- description="The primary name of the academic term/concept. Acts as the unique identifier."- )- domain: str = Field(- description="Field of study or academic domain (e.g., 'Thermodynamics', 'Linguistics')."- )- definition: str = Field(- description="A comprehensive, synthesized definition of the term."- )- synonyms: List[str] = Field(- default_factory=list, description="Alternative names or closely related terms."- )- key_expression: Optional[str] = Field(- None,- description="A formula, notation, or iconic expression associated with this term.",- )---# ==============================================================================-# 2. Prompts-# ==============================================================================--_PROMPT = (- "You are a Lexicographer and Academic Encyclopedia Editor. Your goal is to extract standardize academic definitions.\n\n"- "Extraction Rules:\n"- "- Identify unique academic terms and their highly precise definitions.\n"- "- Search for alternative names or synonyms within the text.\n"- "- If multiple descriptions of the same term exist, prioritize the one that is most mathematically or logically rigorous."-)--# ==============================================================================-# 3. Template Class-# ==============================================================================---class AcademicLexiconSet(AutoSet[AcademicTerm]):- """- Educational template for building a synthesized dictionary of academic terms through key-based information accumulation.- Automatically merges information from multiple text sources about the same term (identified by term name)- into a single comprehensive entry, enriching definitions with context from all sources.-- Example Usage:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> from hyperextract.templates.en.education.academic_lexicon import AcademicLexiconSet- >>> lexicon = AcademicLexiconSet(llm_client, embedder)- >>> lexicon.feed_text("Source 1: Photosynthesis is a process used by plants to convert light energy...") # Extract: term='photosynthesis', definition=...- >>> lexicon.feed_text("Source 2: Photosynthesis occurs in chloroplasts and involves electron transport...") # Auto-merge into existing 'photosynthesis' entry- >>> lexicon.show() # Display merged academic terms- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- *,- extraction_mode: str = "one_stage", # For AutoSet, this is standard- chunk_size: int = 2048,- chunk_overlap: int = 256,- max_workers: int = 10,- verbose: bool = False,- **kwargs: Any,- ):- """- Initialize the Academic Lexicon Template.-- Args:- llm_client (BaseChatModel): The LLM used for extraction.- embedder (Embeddings): The embedding model for semantic retrieval and knowledge graph visualization. Note: Key-based accumulation uses the term name, not embeddings for merging.- extraction_mode (str): Mode of extraction.- chunk_size (int): Size of text chunks for processing large documents.- chunk_overlap (int): Overlap between chunks.- max_workers (int): Parallel processing workers.- verbose (bool): Enable verbose logging.- **kwargs: Additional parameters for AutoSet.- """- super().__init__(- item_schema=AcademicTerm,- key_extractor=lambda x: x.term.strip().lower(),- llm_client=llm_client,- embedder=embedder,- extraction_mode=extraction_mode,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- max_workers=max_workers,- verbose=verbose,- prompt=_PROMPT,- **kwargs,- )-- def show(- self,- *,- top_k_for_search: int = 3,- top_k_for_chat: int = 3,- ) -> None:- """- Visualize the collection using OntoSight.-- Args:- top_k_for_search (int): Number of items to retrieve for search context. Default 3.- top_k_for_chat (int): Number of items to retrieve for chat context. Default 3.- """-- def item_label_extractor(item: AcademicTerm) -> str:- return f"{item.term}"-- super().show(- item_label_extractor=item_label_extractor,- top_k_for_search=top_k_for_search,- top_k_for_chat=top_k_for_chat,- )diff --git a/hyperextract/templates/en/education/interdisciplinary_nexus.py b/hyperextract/templates/en/education/interdisciplinary_nexus.pydeleted file mode 100644index 222ac30..0000000--- a/hyperextract/templates/en/education/interdisciplinary_nexus.py+++ /dev/null@@ -1,163 +0,0 @@-from typing import List, Any-from pydantic import BaseModel, Field-from langchain_core.language_models.chat_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoHypergraph--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================---class ConceptNode(BaseModel):- """- A fundamental academic concept that might belong to multiple disciplines.- """-- name: str = Field(description="Standard name of the concept.")- primary_field: str = Field(- description="The primary discipline this concept originates from."- )---class InterdisciplinaryEdge(BaseModel):- """- A hyperedge representing a connection between multiple concepts across different fields.- """-- participants: List[str] = Field(- description="List of nodes (concept names) participating in this interdisciplinary nexus."- )- unifying_theme: str = Field(- description="The overarching theme or problem that connects these concepts (e.g., 'Complexity Theory', 'Universal Design')."- )- connectivity_insight: str = Field(- description="The scientific or pedagogical value of connecting these specific dots."- )---# ==============================================================================-# 2. Prompts-# ==============================================================================--_PROMPT = (- "You are a Polymath and Interdisciplinary Researcher. Identify deep connections between concepts across different academic fields.\n\n"- "Extraction Rules:\n"- "- Identify core concepts as Nodes.\n"- "- Create Hyperedges that group multiple concepts under a unifying interdisciplinary theme.\n"- "- Focus on finding surprising but scientifically valid bridges (e.g., connecting Biology and Economics through Game Theory)."-)--_NODE_PROMPT = (- "Identify fundamental academic concepts that carry cross-disciplinary potential.\n\n"- "Rules:\n"- "- Extract nouns/concepts that are central to their respective fields.\n"- "- Identify the field of origin."-)--_EDGE_PROMPT = (- "Identify the 'Nexuses' or Hyperedges that unify a group of concepts.\n\n"- "Rules:\n"- "- A hyperedge must involve more than two nodes whenever possible.\n"- "- Describe the unifying theme and the insight gained by this connection."-)--# ==============================================================================-# 3. Template Class-# ==============================================================================---class InterdisciplinaryNexusHypergraph(- AutoHypergraph[ConceptNode, InterdisciplinaryEdge]-):- """- Educational template for mapping non-binary, multi-point academic connections.- Ideal for research synthesis, curriculum cross-linking, and holistic knowledge management.-- Example Usage:- >>> nexus = InterdisciplinaryNexusHypergraph(llm, embedder)- >>> nexus.feed_text("The concept of Entropy applies to Heat (Physics) and Information (Information Theory).")- >>> nexus.extract()- >>> # Result will contain a Hyperedge connecting 'Heat' and 'Information' via 'Entropy'.- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- *,- extraction_mode: str = "one_stage",- chunk_size: int = 2048,- chunk_overlap: int = 256,- max_workers: int = 10,- verbose: bool = False,- **kwargs: Any,- ):- """- Initialize the Interdisciplinary Nexus Template.-- Args:- llm_client (BaseChatModel): The LLM used for extraction.- embedder (Embeddings): The embedding model for deduplication.- extraction_mode (str): 'one_stage' or 'two_stage'.- chunk_size (int): Size of chunks.- chunk_overlap (int): Overlap.- max_workers (int): Workers.- verbose (bool): Logs.- **kwargs: Args for AutoHypergraph.- """- super().__init__(- node_schema=ConceptNode,- edge_schema=InterdisciplinaryEdge,- node_key_extractor=lambda x: x.name.strip().lower(),- edge_key_extractor=lambda x: (- f"{x.unifying_theme.strip().lower()}_linking_{sorted(x.participants)}"- ),- nodes_in_edge_extractor=lambda x: [- p.strip().lower() for p in x.participants- ],- llm_client=llm_client,- embedder=embedder,- extraction_mode=extraction_mode,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- max_workers=max_workers,- verbose=verbose,- prompt=_PROMPT,- prompt_for_node_extraction=_NODE_PROMPT,- prompt_for_edge_extraction=_EDGE_PROMPT,- **kwargs,- )-- def show(- self,- *,- top_k_nodes_for_search: int = 3,- top_k_edges_for_search: int = 3,- top_k_nodes_for_chat: int = 3,- top_k_edges_for_chat: int = 3,- ) -> None:- """- Visualize the graph using OntoSight.-- Args:- top_k_nodes_for_search (int): Number of nodes to retrieve for search context. Default 3.- top_k_edges_for_search (int): Number of edges to retrieve for search context. Default 3.- top_k_nodes_for_chat (int): Number of nodes to retrieve for chat context. Default 3.- top_k_edges_for_chat (int): Number of edges to retrieve for chat context. Default 3.- """-- def node_label_extractor(node: ConceptNode) -> str:- return f"{node.name}"-- def edge_label_extractor(edge: InterdisciplinaryEdge) -> str:- return f"{edge.unifying_theme}"-- super().show(- node_label_extractor=node_label_extractor,- edge_label_extractor=edge_label_extractor,- top_k_nodes_for_search=top_k_nodes_for_search,- top_k_edges_for_search=top_k_edges_for_search,- top_k_nodes_for_chat=top_k_nodes_for_chat,- top_k_edges_for_chat=top_k_edges_for_chat,- )diff --git a/hyperextract/templates/en/education/prerequisite_map.py b/hyperextract/templates/en/education/prerequisite_map.pydeleted file mode 100644index 8dd2fb3..0000000--- a/hyperextract/templates/en/education/prerequisite_map.py+++ /dev/null@@ -1,176 +0,0 @@-from typing import Optional, Any-from pydantic import BaseModel, Field-from langchain_core.language_models.chat_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoGraph--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================---class KnowledgePointNode(BaseModel):- """- A discrete unit of knowledge, concept, or skill within a specific curriculum.- """-- name: str = Field(- description="Standardized name of the knowledge point or concept."- )- level: str = Field(- description="Difficulty level: 'Primary', 'Intermediate', 'Advanced', 'Expert'."- )- concept_type: str = Field(- description="Pedagogical type: 'Definition', 'Theorem', 'Formula', 'Method', 'Application'."- )- description: Optional[str] = Field(- None, description="A brief pedagogical summary of what this concept entails."- )---class PrerequisiteRelation(BaseModel):- """- Directional dependency indicating that one concept must be learned before another.- """-- source: str = Field(- description="The prerequisite knowledge point (must be learned first)."- )- target: str = Field(description="The successor knowledge point (learned after).")- dependency_type: str = Field(- "Prerequisite",- description="Nature of link: 'Prerequisite' (strict), 'Corequisite' (together), 'Recommended' (helpful).",- )- weight: float = Field(1.0, description="Strength of dependency from 0.0 to 1.0.")---# ==============================================================================-# 2. Prompts-# ==============================================================================--_PROMPT = (- "You are a Senior Curriculum Architect and Educational Psychologist. Extract the logical structure of knowledge points from the text.\n\n"- "Rules:\n"- "- Identify atomic concepts that constitute the learning path.\n"- "- Establish clear directional dependencies (prerequisites).\n"- "- Ensure that the resulting graph reflects a sound pedagogical sequence."-)--_NODE_PROMPT = (- "You are an Educational Psychologist specializing in knowledge decomposition. Your task is to identify all discrete Knowledge Points (Nodes).\n\n"- "Extraction Rules:\n"- "- Focus on nouns or noun phrases that represent specific academic concepts, formulas, or methods.\n"- "- Assign a difficulty level and concept type based on the context.\n"- "- DO NOT identify relationships or dependencies at this stage."-)--_EDGE_PROMPT = (- "You are a Curriculum Designer. Given the identified knowledge points, map the Prerequisite Relations (Edges).\n\n"- "Extraction Rules:\n"- "- Determine if Concept A is a necessary precursor to Concept B.\n"- "- Classify the dependency as Prerequisite, Corequisite, or Recommended.\n"- "- Only create relationships between concepts identified in the provided list."-)--# ==============================================================================-# 3. Template Class-# ==============================================================================---class PrerequisiteMapGraph(AutoGraph[KnowledgePointNode, PrerequisiteRelation]):- """- Educational template for building Directed Acyclic Graphs (DAG) of knowledge dependencies.- Useful for syllabus analysis, learning path generation, and student assessment planning.-- Example Usage:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> from hyperextract.templates.en.education.prerequisite_map import PrerequisiteMapGraph- >>> llm = ChatOpenAI(model="gpt-4o")- >>> embedder = OpenAIEmbeddings()- >>> graph = PrerequisiteMapGraph(llm, embedder)- >>> graph.feed_text("To understand Calculus, one must first master Algebra and Functions.")- >>> graph.extract()- >>> print(graph.nodes)- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- *,- extraction_mode: str = "one_stage",- chunk_size: int = 2048,- chunk_overlap: int = 256,- max_workers: int = 10,- verbose: bool = False,- **kwargs: Any,- ):- """- Initialize the Prerequisite Map Template.-- Args:- llm_client (BaseChatModel): The LLM used for extraction.- embedder (Embeddings): The embedding model for node/edge deduplication.- extraction_mode (str): 'one_stage' for consolidated extraction, 'two_stage' for separate node/edge passes.- chunk_size (int): Size of text chunks for processing large documents.- chunk_overlap (int): Overlap between chunks to preserve context.- max_workers (int): Number of parallel workers for processing.- verbose (bool): Whether to print detailed logs during execution.- **kwargs: Additional parameters passed to the AutoGraph base class.- """- super().__init__(- node_schema=KnowledgePointNode,- edge_schema=PrerequisiteRelation,- node_key_extractor=lambda x: x.name.strip().lower(),- edge_key_extractor=lambda x: (- f"{x.source.strip().lower()}->{x.target.strip().lower()}"- ),- nodes_in_edge_extractor=lambda x: (- x.source.strip().lower(),- x.target.strip().lower(),- ),- llm_client=llm_client,- embedder=embedder,- extraction_mode=extraction_mode,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- max_workers=max_workers,- verbose=verbose,- prompt=_PROMPT,- prompt_for_node_extraction=_NODE_PROMPT,- prompt_for_edge_extraction=_EDGE_PROMPT,- **kwargs,- )-- def show(- self,- *,- top_k_nodes_for_search: int = 3,- top_k_edges_for_search: int = 3,- top_k_nodes_for_chat: int = 3,- top_k_edges_for_chat: int = 3,- ) -> None:- """- Visualize the graph using OntoSight.-- Args:- top_k_nodes_for_search (int): Number of nodes to retrieve for search context. Default 3.- top_k_edges_for_search (int): Number of edges to retrieve for search context. Default 3.- top_k_nodes_for_chat (int): Number of nodes to retrieve for chat context. Default 3.- top_k_edges_for_chat (int): Number of edges to retrieve for chat context. Default 3.- """-- def node_label_extractor(node: KnowledgePointNode) -> str:- return f"{node.name}"-- def edge_label_extractor(edge: PrerequisiteRelation) -> str:- return f"{edge.dependency_type}"-- super().show(- node_label_extractor=node_label_extractor,- edge_label_extractor=edge_label_extractor,- top_k_nodes_for_search=top_k_nodes_for_search,- top_k_edges_for_search=top_k_edges_for_search,- top_k_nodes_for_chat=top_k_nodes_for_chat,- top_k_edges_for_chat=top_k_edges_for_chat,- )diff --git a/hyperextract/templates/en/game/__init__.py b/hyperextract/templates/en/game/__init__.pydeleted file mode 100644index 9b7e976..0000000--- a/hyperextract/templates/en/game/__init__.py+++ /dev/null@@ -1,15 +0,0 @@-"""Game domain templates for knowledge extraction."""--from .game_item_compendium import GameItemCompendium-from .game_character_compendium import GameCharacterCompendium-from .game_monster_compendium import GameMonsterCompendium-from .patch_note_changelog import PatchNoteChangelog-from .lore_faction_network import LoreFactionNetwork--__all__ = [- "GameItemCompendium",- "GameCharacterCompendium",- "GameMonsterCompendium",- "PatchNoteChangelog",- "LoreFactionNetwork",-]diff --git a/hyperextract/templates/en/game/game_character_compendium.py b/hyperextract/templates/en/game/game_character_compendium.pydeleted file mode 100644index 5801424..0000000--- a/hyperextract/templates/en/game/game_character_compendium.py+++ /dev/null@@ -1,159 +0,0 @@-"""Game Character Compendium - Extracts unique game characters from various sources.--This template builds a comprehensive character encyclopedia by automatically-merging information from multiple sources: official lore, strategy guides,-character guides, and patch notes.-"""--from typing import Any, Optional-from pydantic import BaseModel, Field-from langchain_core.language_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoSet--# ==============================================================================-# Schema Definition-# ==============================================================================--class GameCharacterSchema(BaseModel):- """Schema for individual game characters in the compendium."""-- character_name: str = Field(- ..., description="The standard name of the character, e.g., 'Yasuo'"- )- class_role: str = Field(- ...,- description="Character class/role (e.g., 'Mage', 'Tank') and playstyle summary.",- )- affiliation: Optional[str] = Field(- None, description="Faction, team, or origin region."- )- abilities: Optional[str] = Field(- None,- description="Signature skills, ultimate ability, and key base stats.",- )- lore: Optional[str] = Field(- None, description="Background story, personality, and voice actor info."- )---# ==============================================================================-# Extraction Prompt-# ==============================================================================--_PROMPT = """You are an expert game lore specialist and character guide author.-Your task is to extract comprehensive information about game characters from the provided text.--For each character mentioned, extract:-1. **character_name**: The official name of the character-2. **character_class**: The combat role/class of the character-3. **background_story**: Origin story, lore, and character background-4. **signature_abilities**: Main and special abilities/skills this character has-5. **base_stats**: Core numerical attributes: HP, mana, attack power, defense, etc.-6. **recommended_playstyle**: Strategic guidance on how to effectively play this character-7. **origin_region**: Which region or world area the character is from-8. **faction_affiliation**: Which team, organization, or faction the character belongs to-9. **voice_actor**: The official voice actor's name(s) if mentioned--Extract only information explicitly stated in the text. If a field is not mentioned, leave it empty.-Be comprehensive and capture all character details mentioned, even if scattered across the text.--### Source Text:-"""---# ==============================================================================-# Template Class-# ==============================================================================--class GameCharacterCompendium(AutoSet[GameCharacterSchema]):- """Applicable to: Character background stories, Skill guides, Official character bio, Strategy guides-- Extracts a comprehensive game character encyclopedia by automatically- deduplicating and merging character information from multiple sources.-- Information about the same character from different sources (official lore,- strategy guides, patch notes) is automatically combined into a single- enriched character profile.-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> from hyperextract.templates.en.game import GameCharacterCompendium- >>>- >>> llm = ChatOpenAI(model="gpt-4", temperature=0)- >>> embedder = OpenAIEmbeddings()- >>>- >>> characters = GameCharacterCompendium(- ... llm_client=llm,- ... embedder=embedder- ... )- >>>- >>> # Feed multiple sources- >>> characters.feed_text(- ... "Yasuo was a swordsman of great honor from the Ionian isles. "- ... "He wields a blade with unmatched precision and speed."- ... )- >>> characters.feed_text(- ... "Yasuo's abilities include: Steel Tempest (Q), Wind Wall (W), Sweeping Blade (E), Last Breath (R). "- ... "Stats: 550 HP, 50 attack, 25 armor."- ... )- >>> characters.feed_text(- ... "As an ADC (attack-carry), Yasuo works best with items that increase attack speed "- ... "and critical chance. Position carefully in teamfights."- ... )- >>>- >>> # All info automatically merged into single Yasuo profile- >>> characters.show()- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- chunk_size: int = 2048,- chunk_overlap: int = 256,- **kwargs: Any,- ):- """Initialize the Game Character Compendium template.-- Args:- llm_client: Language model for character extraction (e.g., ChatOpenAI).- embedder: Embedding model for semantic indexing (e.g., OpenAIEmbeddings).- chunk_size: Maximum characters per text chunk (default 2048).- chunk_overlap: Overlapping characters between chunks (default 256).- **kwargs: Additional arguments passed to AutoSet parent class.- """- super().__init__(- item_schema=GameCharacterSchema,- llm_client=llm_client,- embedder=embedder,- key_extractor=lambda x: x.character_name.strip().lower(),- prompt=_PROMPT,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- **kwargs,- )-- def show(- self,- *,- top_k_for_search: int = 3,- top_k_for_chat: int = 3,- ) -> None:- """Display the game character compendium as an interactive knowledge graph.-- Args:- top_k_for_search: Number of top results for semantic search.- top_k_for_chat: Number of top results for chat context.- """-- def character_label_extractor(item: GameCharacterSchema) -> str:- """Extract display label: name with class."""- class_label = f" ({item.character_class})" if item.character_class else ""- return f"{item.character_name}{class_label}"-- super().show(- item_label_extractor=character_label_extractor,- top_k_for_search=top_k_for_search,- top_k_for_chat=top_k_for_chat,- )diff --git a/hyperextract/templates/en/game/game_item_compendium.py b/hyperextract/templates/en/game/game_item_compendium.pydeleted file mode 100644index 7d7dc6a..0000000--- a/hyperextract/templates/en/game/game_item_compendium.py+++ /dev/null@@ -1,161 +0,0 @@-"""Game Item Compendium - Extracts unique game items from various sources.--This template builds a comprehensive item library by automatically merging-information about the same item from multiple sources (guides, wikis, patch notes).-Uses AutoSet to deduplicate and combine item attributes.--Example Sources:-- Game Wiki pages describing item properties-- Official strategy guides with item recommendations-- Patch notes mentioning item changes-"""--from typing import Any, Optional-from pydantic import BaseModel, Field-from langchain_core.language_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoSet--# ==============================================================================-# Schema Definition-# ==============================================================================--class GameItemSchema(BaseModel):- """Schema for individual game items in the compendium."""-- item_name: str = Field(- ..., description="The standard name of the item"- )- category: str = Field(- ...,- description="Item classification (Weapon, Potion, Material, etc.)",- )- item_data: Optional[str] = Field(- None,- description="Stat bonuses, special effects, and crafting recipe information.",- )- description: Optional[str] = Field(- None, description="Acquisition info, suitable heroes, and lore background.",- )---# ==============================================================================-# Extraction Prompt-# ==============================================================================--_PROMPT = """You are an expert game designer and community guide author familiar with game item systems.-Your task is to extract structured information about game items from the provided text.--For each item mentioned in the text, extract:-1. **item_name**: The official or standard name of the item-2. **category**: The type/class of item (weapon, armor, consumable, etc.)-3. **item_data**: Stat bonuses, effects, and crafting recipes-4. **description**: Where to find it, recommended heroes, and background lore--Extract only information explicitly mentioned.--### Source Text:-"""---# ==============================================================================-# Template Class-# ==============================================================================--class GameItemCompendium(AutoSet[GameItemSchema]):- """Applicable to: Game Wiki pages, Strategy guides, Official item manuals, Patch notes-- Extracts a comprehensive game item compendium by automatically deduplicating- and merging information about items from multiple sources.-- This template is particularly useful for:- - Building unified item databases from scattered wiki information- - Merging item data from different strategy guides and patch notes- - Consolidating character recommendations and item synergies- - Creating rich item profiles by combining properties from multiple sources-- When multiple text chunks describe the same item (identified by exact name matching),- their attributes are intelligently merged into a single enriched entry. This allows- gradual knowledge accumulation about each item across multiple documents.-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> from hyperextract.templates.en.game import GameItemCompendium- >>>- >>> llm = ChatOpenAI(model="gpt-4", temperature=0)- >>> embedder = OpenAIEmbeddings()- >>>- >>> compendium = GameItemCompendium(- ... llm_client=llm,- ... embedder=embedder- ... )- >>>- >>> # Feed multiple sources- >>> compendium.feed_text(- ... "Endless Blade is a legendary weapon that grants +80 attack power. "- ... "It can be crafted by combining a Long Sword and a Crystal Core."- ... )- >>> compendium.feed_text(- ... "Endless Blade synergizes perfectly with Yasuo and Aatrox, "- ... "enabling powerful critical strike combos with these champions."- ... )- >>> compendium.feed_text(- ... "The Endless Blade has a dark lore: forged from the tears "- ... "of a fallen god to prevent the eternal night."- ... )- >>>- >>> # All information is automatically merged under 'Endless Blade'- >>> compendium.show() # Visualize the merged item compendium- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- chunk_size: int = 2048,- chunk_overlap: int = 256,- **kwargs: Any,- ):- """Initialize the Game Item Compendium template.-- Args:- llm_client: Language model for item extraction (e.g., ChatOpenAI).- embedder: Embedding model for semantic indexing (e.g., OpenAIEmbeddings).- chunk_size: Maximum characters per text chunk (default 2048).- chunk_overlap: Overlapping characters between chunks (default 256).- **kwargs: Additional arguments passed to AutoSet parent class.- """- super().__init__(- item_schema=GameItemSchema,- llm_client=llm_client,- embedder=embedder,- key_extractor=lambda x: x.item_name.strip().lower(),- prompt=_PROMPT,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- **kwargs,- )-- def show(- self,- *,- top_k_for_search: int = 3,- top_k_for_chat: int = 3,- ) -> None:- """Display the game item compendium as an interactive knowledge graph.-- Args:- top_k_for_search: Number of top results to retrieve for semantic search queries.- top_k_for_chat: Number of top results to show in chat/dialogue context.- """-- def item_label_extractor(item: GameItemSchema) -> str:- """Extract display label for an item: name with category."""- category_label = f" ({item.category})" if item.category else ""- return f"{item.item_name}{category_label}"-- super().show(- item_label_extractor=item_label_extractor,- top_k_for_search=top_k_for_search,- top_k_for_chat=top_k_for_chat,- )diff --git a/hyperextract/templates/en/game/game_monster_compendium.py b/hyperextract/templates/en/game/game_monster_compendium.pydeleted file mode 100644index be079bc..0000000--- a/hyperextract/templates/en/game/game_monster_compendium.py+++ /dev/null@@ -1,162 +0,0 @@-"""Game Monster Compendium - Extracts unique game monsters from various sources.--This template builds a comprehensive monster database by automatically merging-information from guides, wikis, and bestiary entries.-"""--from typing import Any, Optional-from pydantic import BaseModel, Field-from langchain_core.language_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoSet--# ==============================================================================-# Schema Definition-# ==============================================================================--class GameMonsterSchema(BaseModel):- """Schema for individual game monsters in the compendium."""-- monster_name: str = Field(- ..., description="The standard name of the monster, e.g., 'Goblin Warrior'"- )- type: str = Field(- ...,- description="Monster species and rarity classification (e.g., 'Undead / Boss', 'Beast / Common')",- )- habitat: Optional[str] = Field(- None, description="Map areas or regions where this monster typically appears"- )- abilities: Optional[str] = Field(- None,- description="Combat stats (HP/ATK), special skills, weaknesses, and encounter difficulty",- )- loot_and_lore: Optional[str] = Field(- None,- description="Items dropped, respawn mechanics, and background lore/flavor text",- )---# ==============================================================================-# Extraction Prompt-# ==============================================================================--_PROMPT = """You are an expert game bestiary and monster guide author.-Your task is to extract structured information about game monsters from the provided text.--For each monster mentioned, extract these consolidated fields:-1. **monster_name**: The official name of the monster-2. **type**: The species/race combined with rarity tier (e.g., Dragon/Legendary)-3. **habitat**: Locations where found-4. **abilities**:- - Combat stats (HP/ATK)- - Unique skills or attacks- - Elemental weaknesses- - Strategy or difficulty rating-5. **loot_and_lore**:- - Dropped items and probabilities- - Respawn timers or mechanics- - Background lore and description--Extract only information explicitly mentioned. Keep descriptions concise but complete.--### Source Text:-"""---# ==============================================================================-# Template Class-# ==============================================================================--class GameMonsterCompendium(AutoSet[GameMonsterSchema]):- """Applicable to: Monster guides, Bestiary entries, Farming guides, Patch notes-- Extracts a comprehensive game monster database by automatically deduplicating- and merging monster information from multiple sources.-- This template is particularly useful for:- - Building unified monster databases from scattered wiki information- - Merging monster data from multiple farming or hunting guides- - Consolidating stat information and drop tables- - Creating detailed monster profiles by combining data from multiple sources-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> from hyperextract.templates.en.game import GameMonsterCompendium- >>>- >>> llm = ChatOpenAI(model="gpt-4", temperature=0)- >>> embedder = OpenAIEmbeddings()- >>>- >>> monsters = GameMonsterCompendium(- ... llm_client=llm,- ... embedder=embedder- ... )- >>>- >>> # Feed multiple sources- >>> monsters.feed_text(- ... "The Goblin Warrior is a melee fighter with 150 HP and 45 attack power. "- ... "Found in the Dark Forest zone, they respawn every 5 minutes."- ... )- >>> monsters.feed_text(- ... "Goblin Warriors are weak to Fire damage. They can use Shield Bash and Cleave attacks."- ... )- >>> monsters.feed_text(- ... "When defeated, Goblin Warriors drop: Leather Armor (20% chance), "- ... "Iron Sword (5% chance), and Gold Coins (100%)."- ... )- >>>- >>> # All info automatically merged into single Goblin Warrior profile- >>> monsters.show()- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- chunk_size: int = 2048,- chunk_overlap: int = 256,- **kwargs: Any,- ):- """Initialize the Game Monster Compendium template.-- Args:- llm_client: Language model for monster extraction (e.g., ChatOpenAI).- embedder: Embedding model for semantic indexing (e.g., OpenAIEmbeddings).- chunk_size: Maximum characters per text chunk (default 2048).- chunk_overlap: Overlapping characters between chunks (default 256).- **kwargs: Additional arguments passed to AutoSet parent class.- """- super().__init__(- item_schema=GameMonsterSchema,- llm_client=llm_client,- embedder=embedder,- key_extractor=lambda x: x.monster_name.strip().lower(),- prompt=_PROMPT,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- **kwargs,- )-- def show(- self,- *,- top_k_for_search: int = 3,- top_k_for_chat: int = 3,- ) -> None:- """Display the game monster compendium as an interactive knowledge base.-- Args:- top_k_for_search: Number of top results for semantic search.- top_k_for_chat: Number of top results for chat context.- """-- def monster_label_extractor(item: GameMonsterSchema) -> str:- """Extract display label: name with type."""- type_label = f" ({item.type})" if item.type else ""- return f"{item.monster_name}{type_label}"-- super().show(- item_label_extractor=monster_label_extractor,- top_k_for_search=top_k_for_search,- top_k_for_chat=top_k_for_chat,- )diff --git a/hyperextract/templates/en/game/lore_faction_network.py b/hyperextract/templates/en/game/lore_faction_network.pydeleted file mode 100644index 8051277..0000000--- a/hyperextract/templates/en/game/lore_faction_network.py+++ /dev/null@@ -1,231 +0,0 @@-"""Lore Faction Network - Extracts faction relationships from game lore.--This template builds a political/social relationship graph showing how characters,-factions, and regions interact within the game world.-"""--from typing import Any, Optional-from pydantic import BaseModel, Field-from langchain_core.language_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoGraph--# ==============================================================================-# Schema Definitions-# ==============================================================================--class LoreEntitySchema(BaseModel):- """Schema for entities in the lore network (characters, factions, regions)."""-- entity_id: str = Field(..., description="Unique identifier for this entity")- entity_type: str = Field(- ...,- description="Type of entity: 'Hero' (character), 'Faction' (organization), or 'Region' (location)",- )- entity_name: str = Field(..., description="Name of the entity")- description: Optional[str] = Field(- None, description="Brief description of the entity's background or characteristics"- )---class LoreRelationshipSchema(BaseModel):- """Schema for relationships in the lore network."""-- source_entity: str = Field(..., description="Name of the source entity")- target_entity: str = Field(..., description="Name of the target entity")- relationship_type: str = Field(- ...,- description="Type of relationship: 'Belongs_To' (allegiance), 'At_War_With' (conflict), "- "'Betrayed' (betrayal), 'Founded' (founding), 'Ally_With' (alliance), etc.",- )- context: Optional[str] = Field(- None, description="Background context or explanation for this relationship"- )---# ==============================================================================-# Extraction Prompts - One-Stage and Two-Stage-# ==============================================================================--_PROMPT = """You are an expert game lore analyst specializing in world-building and faction relationships.-Your task is to extract entities (Nodes) and their political/social relationships (Edges) from game lore text.--Extract:-1. **Entities (Nodes)**: All characters (heroes), factions (organizations), and regions mentioned- - For characters: name, type='Hero'- - For factions: name, type='Faction'- - For regions: name, type='Region'--2. **Relationships (Edges)**: Political, military, and social connections- - Belongs_To: A character belongs to a faction or resides in a region- - At_War_With: Two factions or entities are in conflict- - Betrayed: A character/faction betrayed another- - Founded: A character founded a faction- - Ally_With: Formal alliance between factions- - Other relationship types based on context--CRITICAL: Every edge must connect two entities that are present in the extracted nodes list.-Do not create edges between entities that are not explicitly identified as nodes.--Extract only information explicitly stated in the text.--### Source Text:-"""--_NODE_PROMPT = """You are an expert entity recognition specialist for game lore.-Your task is to extract all distinct entities from the text that will serve as nodes in a lore network.--Extract three types of entities:-1. **Heroes/Characters**: Individual persons with names (e.g., "Yasuo", "Ahri")-2. **Factions/Organizations**: Groups, orders, nations, guilds (e.g., "Ionia", "Noxus", "The Watchers")-3. **Regions/Locations**: Geographic areas and places (e.g., "Shadow Isles", "Piltover", "Demacia")--For each entity, provide:-- The entity name (as appears in text)-- The entity type (Hero/Faction/Region)-- A brief description if available--Focus on completeness. Extract every entity mentioned, no matter how briefly.--### Source Text:-"""--_EDGE_PROMPT = """You are an expert relationship extraction specialist for game lore networks.-Your task is to extract relationships (edges) between the provided entities.--Given the known entities list below, extract all relationships that connect them:-- Belongs_To: Character belongs to faction; faction controls region-- At_War_With: Entities in armed conflict-- Betrayed: One entity betrayed another-- Founded: Character founded a faction-- Ally_With: Formal alliance between factions-- Opposes: Opposition without necessarily warfare--CRITICAL RULES:-1. ONLY extract edges connecting entities from the known entity list provided below-2. DO NOT invent or hallucinate new entities not in the provided list-3. If an entity appears in text but isn't in the known list, DO NOT create edges involving it-4. Focus on explicit relationship statements in the text--Extract only explicitly stated relationships. Do not infer relationships not clearly described.--### Source Text:-"""---# ==============================================================================-# Template Class-# ==============================================================================--class LoreFactionNetwork(AutoGraph[LoreEntitySchema, LoreRelationshipSchema]):- """Applicable to: Game background stories, Lore documents, Character bios, Setting guides-- Extracts a political and social relationship graph from game lore,- showing how characters, factions, and regions interact within the game world.-- This template is particularly useful for:- - Visualizing faction relationships and hierarchies- - Understanding character allegiances and conflicts- - Building world-building maps of political structures- - Analyzing geopolitical dynamics in game settings-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> from hyperextract.templates.en.game import LoreFactionNetwork- >>>- >>> llm = ChatOpenAI(model="gpt-4", temperature=0)- >>> embedder = OpenAIEmbeddings()- >>>- >>> lore_graph = LoreFactionNetwork(- ... llm_client=llm,- ... embedder=embedder,- ... extraction_mode="two_stage"- ... )- >>>- >>> lore_graph.feed_text('''- ... Yasuo is a swordsman from the region of Ionia. He belongs to the traditionalist faction.- ... Ionia is at war with Noxus for control of the eastern territories.- ... Ahri is a fox spirit who betrayed Yasuo when she sided with Noxus.- ... ''')- >>>- >>> # Nodes: Yasuo, Ionia, Noxus, Ahri- >>> # Edges: Yasuo->Ionia (Belongs_To), Ionia->Noxus (At_War_With), Ahri->Yasuo (Betrayed)- >>> lore_graph.show()- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- extraction_mode: str = "two_stage",- chunk_size: int = 2048,- chunk_overlap: int = 256,- **kwargs: Any,- ):- """Initialize the Lore Faction Network template.-- Args:- llm_client: Language model for extraction (e.g., ChatOpenAI).- embedder: Embedding model for semantic indexing (e.g., OpenAIEmbeddings).- extraction_mode: 'one_stage' (faster, simpler) or 'two_stage' (more accurate).- chunk_size: Maximum characters per text chunk (default 2048).- chunk_overlap: Overlapping characters between chunks (default 256).- **kwargs: Additional arguments passed to AutoGraph parent class.- """- super().__init__(- node_schema=LoreEntitySchema,- edge_schema=LoreRelationshipSchema,- node_key_extractor=lambda x: x.entity_name.strip().lower(),- edge_key_extractor=lambda x: (- f"{x.source_entity.strip().lower()}|"- f"{x.relationship_type.strip().lower()}|"- f"{x.target_entity.strip().lower()}"- ),- nodes_in_edge_extractor=lambda x: (- x.source_entity.strip().lower(),- x.target_entity.strip().lower(),- ),- llm_client=llm_client,- embedder=embedder,- extraction_mode=extraction_mode,- prompt=_PROMPT,- prompt_for_node_extraction=_NODE_PROMPT,- prompt_for_edge_extraction=_EDGE_PROMPT,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- **kwargs,- )-- def show(- self,- *,- top_k_for_search: int = 5,- top_k_for_chat: int = 5,- ) -> None:- """Display the lore faction network as an interactive relationship graph.-- Args:- top_k_for_search: Number of top entities to retrieve for search.- top_k_for_chat: Number of top entities to show in chat context.- """-- def node_label_extractor(node: LoreEntitySchema) -> str:- """Extract display label showing entity type."""- type_emoji = {- "Hero": "👤",- "Faction": "🏛️",- "Region": "🗺️",- }- emoji = type_emoji.get(node.entity_type, "●")- return f"{emoji} {node.entity_name}"-- def edge_label_extractor(edge: LoreRelationshipSchema) -> str:- """Extract display label for relationships."""- return edge.relationship_type.replace("_", " ")-- super().show(- node_label_extractor=node_label_extractor,- edge_label_extractor=edge_label_extractor,- top_k_for_search=top_k_for_search,- top_k_for_chat=top_k_for_chat,- )diff --git a/hyperextract/templates/en/game/patch_note_changelog.py b/hyperextract/templates/en/game/patch_note_changelog.pydeleted file mode 100644index 6ff9c6b..0000000--- a/hyperextract/templates/en/game/patch_note_changelog.py+++ /dev/null@@ -1,156 +0,0 @@-"""Patch Note Changelog - Extracts all individual changes from patch notes.--This template extracts a comprehensive changelog of all game changes, modifications,-and balance updates without deduplication, preserving every individual change entry.-"""--from typing import Any, Optional-from pydantic import BaseModel, Field-from langchain_core.language_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoList--# ==============================================================================-# Schema Definition-# ==============================================================================--class PatchChangeSchema(BaseModel):- """Schema for individual patch note entries."""-- entity_name: str = Field(- ..., description="Name of the entity modified: character name, item name, etc."- )- change_type: str = Field(- ...,- description="Type of change: 'Buff' (increase), 'Nerf' (decrease), 'Mechanic Change', 'Bug Fix', 'Rework', etc.",- )- old_value: Optional[str] = Field(- None, description="Previous value or state before modification"- )- new_value: Optional[str] = Field(- None, description="New value or state after modification"- )- patch_version: Optional[str] = Field(- None, description="Version number or patch date when this change took effect"- )- developer_note: Optional[str] = Field(- None, description="Official explanation or reasoning for the change provided by developers"- )---# ==============================================================================-# Extraction Prompt-# ==============================================================================--_PROMPT = """You are an expert patch note analyst and game balance specialist.-Your task is to extract detailed information about each individual game change from patch notes.--For each change or modification mentioned, extract:-1. **entity_name**: What is being modified (character, item, ability, system, etc.)-2. **change_type**: The nature of the change (Buff, Nerf, Mechanic Change, Bug Fix, Rework, etc.)-3. **old_value**: The previous value, stat, or mechanic before the change-4. **new_value**: The new value, stat, or mechanic after the change-5. **patch_version**: The patch version or date when this change was implemented-6. **developer_note**: Any explanation or reasoning provided for the change--CRITICAL: Extract EVERY individual change as a separate entry.-If an entity has multiple changes in a patch (e.g., both attack nerfed AND defense buffed),-create separate entries for each change to preserve complete change history.--Extract only information explicitly mentioned in the text.-Be comprehensive and capture all modifications, no matter how minor.--### Source Text:-"""---# ==============================================================================-# Template Class-# ==============================================================================--class PatchNoteChangelog(AutoList[PatchChangeSchema]):- """Applicable to: Official patch notes, Version changelogs, Balance updates-- Extracts a detailed changelog of all game modifications from patch documentation.-- Unlike AutoSet which deduplicates, this template preserves EVERY individual change- as a separate entry. This is essential for:- - Tracking complete balance history of each entity- - Analyzing multiple changes to the same entity in one patch- - Auditing game design decisions over time- - Building comprehensive patch databases without data loss-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> from hyperextract.templates.en.game import PatchNoteChangelog- >>>- >>> llm = ChatOpenAI(model="gpt-4", temperature=0)- >>> embedder = OpenAIEmbeddings()- >>>- >>> changelog = PatchNoteChangelog(- ... llm_client=llm,- ... embedder=embedder- ... )- >>>- >>> # Feed patch notes- >>> changelog.feed_text('''- ... Patch 2.3.0 - Balance Update- ... Yasuo: Attack increased from 50 to 55 (buff to late-game scaling)- ... Yasuo: Wind Wall cooldown reduced from 25s to 20s (quality of life)- ... Endless Blade: Attack bonus increased from 80 to 85- ... ''')- >>>- >>> # Each change is preserved as separate entry, not merged- >>> # So we get 3 entries total, even though Yasuo has 2 changes- >>> changelog.show()- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- chunk_size: int = 2048,- chunk_overlap: int = 256,- **kwargs: Any,- ):- """Initialize the Patch Note Changelog template.-- Args:- llm_client: Language model for change extraction (e.g., ChatOpenAI).- embedder: Embedding model for semantic indexing (e.g., OpenAIEmbeddings).- chunk_size: Maximum characters per text chunk (default 2048).- chunk_overlap: Overlapping characters between chunks (default 256).- **kwargs: Additional arguments passed to AutoList parent class.- """- super().__init__(- item_schema=PatchChangeSchema,- llm_client=llm_client,- embedder=embedder,- prompt=_PROMPT,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- **kwargs,- )-- def show(- self,- *,- top_k_for_search: int = 3,- top_k_for_chat: int = 3,- ) -> None:- """Display the patch changelog as an interactive database.-- Args:- top_k_for_search: Number of top results for semantic search.- top_k_for_chat: Number of top results for chat context.- """-- def change_label_extractor(item: PatchChangeSchema) -> str:- """Extract display label: entity with change type."""- return f"{item.entity_name} ({item.change_type})"-- super().show(- item_label_extractor=change_label_extractor,- top_k_for_search=top_k_for_search,- top_k_for_chat=top_k_for_chat,- )diff --git a/hyperextract/templates/en/movie/__init__.py b/hyperextract/templates/en/movie/__init__.pydeleted file mode 100644index 200eca4..0000000--- a/hyperextract/templates/en/movie/__init__.py+++ /dev/null@@ -1,5 +0,0 @@-from .character_arc_tracker import CharacterArcTracker-from .cinematic_trivia_set import CinematicTriviaSet-from .script_scene_graph import ScriptSceneGraph--__all__ = ["CharacterArcTracker", "CinematicTriviaSet", "ScriptSceneGraph"]diff --git a/hyperextract/templates/en/movie/character_arc_tracker.py b/hyperextract/templates/en/movie/character_arc_tracker.pydeleted file mode 100644index 4a3ed52..0000000--- a/hyperextract/templates/en/movie/character_arc_tracker.py+++ /dev/null@@ -1,86 +0,0 @@-from typing import List, Optional, Any, Tuple-from pydantic import BaseModel, Field-from langchain_core.language_models.chat_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoTemporalGraph--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================--class CharacterState(BaseModel):- """The state of a film character at a specific narrative point."""- character_name: str = Field(description="Name of the character.")- psychological_state: str = Field(description="The core emotional or psychological state of the character at this moment.")- current_goal: str = Field(description="The primary objective of the character at this moment.")- situation: str = Field(description="The external circumstances or conflicts the character is facing.")--class CharacterDevelopment(BaseModel):- """Evolution and arc shifts between character states."""- source: str = Field(description="Starting state.")- target: str = Field(description="Resulting state.")- time: str = Field(description="The point or phase in the plot where the shift occurs (e.g., 'Act II', 'Pre-climax').")- trigger_event: str = Field(description="The key plot event that triggers this shift in state.")- arc_direction: str = Field(description="Direction of the arc (e.g., Growth, Corruption, Awakening, Realization).")--# ==============================================================================-# 2. Prompts-# ==============================================================================--_PROMPT = (- "You are a sophisticated script analyst and character study expert. Your task is to track the 'character arc' from scripts or deep film reviews.\n\n"- "Extraction Guidelines:\n"- "1. **State Slicing**: Extract nodes representing the character's psychology, goals, and situation at different stages of the story.\n"- "2. **Trigger Identification**: Identify the key driving events that cause the transition between two character states.\n"- "3. **Timeline Resolution**: Clearly specify when the shift occurs (e.g., script page numbers, acts, or relative story phases).\n"-)--_NODE_PROMPT = "Identify and extract the character's internal and external states at key plot points. Record their emotions, current goals, and primary situations."-_EDGE_PROMPT = "Analyze the evolution between character states. Point out what plot events triggered the psychological journey and summarize the direction of the arc."--# ==============================================================================-# 3. Template Class-# ==============================================================================--class CharacterArcTracker(AutoTemporalGraph[CharacterState, CharacterDevelopment]):- """- Applicable to: [Character Biographies, Dramatic Scripts, Literary Adaptations, Film Reviews]-- Template for analyzing film character growth paths and psychological arcs.-- This template focuses on 'why' and 'how' a character changes, ideal for deep character studies and dramatic conflict analysis.-- Example:- >>> arc = CharacterArcTracker(llm_client=llm, embedder=embedder)- >>> text = "At the start, Jack is a timid clerk. After the explosion, he realizes the value of life and shows incredible courage in the finale."- >>> arc.feed_text(text).show()- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- *,- extraction_mode: str = "two_stage",- **kwargs: Any- ):- super().__init__(- node_schema=CharacterState,- edge_schema=CharacterDevelopment,- node_key_extractor=lambda x: f"{x.character_name}-{x.psychological_state[:10]}",- edge_key_extractor=lambda x: f"{x.source}>>{x.target}",- time_in_edge_extractor=lambda x: x.time,- nodes_in_edge_extractor=lambda x: (x.source, x.target),- llm_client=llm_client,- embedder=embedder,- prompt=_PROMPT,- prompt_for_node_extraction=_NODE_PROMPT,- prompt_for_edge_extraction=_EDGE_PROMPT,- extraction_mode=extraction_mode,- **kwargs- )-- def show(self, **kwargs):- def n_label(node: CharacterState) -> str: return f"{node.character_name}: {node.psychological_state}"- def e_label(edge: CharacterDevelopment) -> str: return f"[{edge.time}] {edge.arc_direction}"- super().show(node_label_extractor=n_label, edge_label_extractor=e_label, **kwargs)diff --git a/hyperextract/templates/en/movie/cinematic_trivia_set.py b/hyperextract/templates/en/movie/cinematic_trivia_set.pydeleted file mode 100644index 1959ad4..0000000--- a/hyperextract/templates/en/movie/cinematic_trivia_set.py+++ /dev/null@@ -1,69 +0,0 @@-from typing import List, Optional, Any-from pydantic import BaseModel, Field-from langchain_core.language_models.chat_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoSet--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================--class CinematicTrivia(BaseModel):- """Film elements, easter eggs, production trivia, or specific narrative elements."""- topic: str = Field(description="The theme or name of the trivia/element (e.g., 'Homage to 2001: A Space Odyssey', 'Fourth Wall Break').")- description: str = Field(description="Detailed content or production background of the element.")- timestamp: Optional[str] = Field(description="Specific time point in the film where the element appears (e.g., '01:23:45').")- significance: List[str] = Field(description="Artistic significance, narrative function, or special meaning to fans.")- source: List[str] = Field(description="Source of the information (e.g., Director's Commentary, IMDb, specific trivia sites).")--# ==============================================================================-# 2. Prompts-# ==============================================================================--_PROMPT = (- "You are an expert film critic and cinema encyclopedist. Your task is to extract structured film trivia and encyclopedic points from reviews and production notes.\n\n"- "Analysis Guidelines:\n"- "1. **Topic Deduplication**: Merge multiple snippets regarding the same topic (e.g., 'Stan Lee Cameo'). Ensure standardized naming.\n"- "2. **Deep Dive**: Extract not just 'what' the element is, but also the artistic intent (significance) behind it.\n"- "3. **Accumulation**: Enrich the same topic with descriptions, timestamps, and sources over multiple text feeds.\n"-)--# ==============================================================================-# 3. Template Class-# ==============================================================================--class CinematicTriviaSet(AutoSet[CinematicTrivia]):- """- Applicable to: [Production Notes, DVD Commentary, Behind-the-scenes, IMDB Trivia, Film Reviews]-- Template for building and aggregating film encyclopedias and trivia.-- This template leverages AutoSet's enrichment capabilities to aggregate scattered trivia knowledge across documents.-- Example:- >>> trivia = CinematicTriviaSet(llm_client=llm, embedder=embedder)- >>> trivia.feed_text("The director placed a hidden homage to Kubrick at 86 minutes.").feed_text("The red chair is a direct nod to The Shining.")- >>> trivia.show()- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- *,- chunk_size: int = 2048,- **kwargs: Any- ):- super().__init__(- item_schema=CinematicTrivia,- key_extractor=lambda x: x.topic.strip().lower(),- llm_client=llm_client,- embedder=embedder,- prompt=_PROMPT,- chunk_size=chunk_size,- **kwargs- )-- def show(self, **kwargs):- def label(item: CinematicTrivia) -> str: return item.topic- super().show(item_label_extractor=label, **kwargs)diff --git a/hyperextract/templates/en/movie/script_scene_graph.py b/hyperextract/templates/en/movie/script_scene_graph.pydeleted file mode 100644index 60caaf4..0000000--- a/hyperextract/templates/en/movie/script_scene_graph.py+++ /dev/null@@ -1,91 +0,0 @@-from typing import List, Optional, Any, Tuple-from pydantic import BaseModel, Field-from langchain_core.language_models.chat_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoTemporalGraph--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================--class Scene(BaseModel):- """A scene node in a screenplay."""- title: str = Field(description="Standard scene heading (e.g., 'INT. COFFEE SHOP - DAY').")- location: str = Field(description="Specific location where the scene occurs.")- time_of_day: str = Field(description="Time period (e.g., DAY, NIGHT, DUSK, DAWN).")- description: str = Field(description="Brief summary of actions or the core event within the scene.")--class SceneTransition(BaseModel):- """Transition and logical flow between scenes."""- source: str = Field(description="Source scene title.")- target: str = Field(description="Target scene title.")- time: str = Field(description="Duration or time offset passed between scenes. You MUST resolve this into an absolute duration or precise timestamp/offset.")- transition_type: str = Field(description="Type of transition (e.g., CUT TO, FADE IN, DISSOLVE).")- logic: str = Field(description="Narrative logic (e.g., Continuous Action, Time Jump, Parallel Editing).")--# ==============================================================================-# 2. Prompts-# ==============================================================================--_PROMPT = (- "You are an expert screenwriter and film director. Your task is to extract the scene flow and narrative logic from screenplays or storyboards.\n\n"- "Extraction Guidelines:\n"- "1. **Scene Identification**: Extract all independent scene nodes, recording the exact heading, location, and time of day.\n"- "2. **Rhythm Analysis**: Identify transition methods and accurately parse the passage of time between scenes.\n"- "3. **Narrative Logic**: Describe how scenes drive each other on a storytelling level.\n"-)--_NODE_PROMPT = "Extract all scenes from the script. Record the standard heading, location, time period, and a core plot summary for each."-_EDGE_PROMPT = "Establish transitions between identified scenes. Note the transition method, and accurately infer the time span and narrative logical relationship."--# ==============================================================================-# 3. Template Class-# ==============================================================================--class ScriptSceneGraph(AutoTemporalGraph[Scene, SceneTransition]):- """- Applicable to: [Movie Screenplays, Teleplays, Storyboards, Narrative Outlines]-- Template for extracting scene flow and editing rhythm from screenplays.-- This template focuses on presenting narrative tempo and scene shifts,- ideal for director-level script breakdown and visualization.-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> llm = ChatOpenAI(model="gpt-4o")- >>> embedder = OpenAIEmbeddings()- >>> script = ScriptSceneGraph(llm_client=llm, embedder=embedder)- >>> text = "SCENE 1: INT. LAB - DAY. Scientist experimenting. CUT TO: SCENE 2: EXT. STREET - NIGHT. Three hours later, he's walking."- >>> script.feed_text(text)- >>> script.show()- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- *,- extraction_mode: str = "two_stage",- **kwargs: Any- ):- super().__init__(- node_schema=Scene,- edge_schema=SceneTransition,- node_key_extractor=lambda x: x.title.strip(),- edge_key_extractor=lambda x: f"{x.source}->{x.target}",- time_in_edge_extractor=lambda x: x.time,- nodes_in_edge_extractor=lambda x: (x.source, x.target),- llm_client=llm_client,- embedder=embedder,- prompt=_PROMPT,- prompt_for_node_extraction=_NODE_PROMPT,- prompt_for_edge_extraction=_EDGE_PROMPT,- extraction_mode=extraction_mode,- **kwargs- )-- def show(self, **kwargs):- def n_label(node: Scene) -> str: return node.title- def e_label(edge: SceneTransition) -> str: return f"{edge.transition_type} ({edge.time})"- super().show(node_label_extractor=n_label, edge_label_extractor=e_label, **kwargs)diff --git a/hyperextract/templates/en/travel/__init__.py b/hyperextract/templates/en/travel/__init__.pynew file mode 100644index 0000000..d06326e--- /dev/null+++ b/hyperextract/templates/en/travel/__init__.py@@ -0,0 +1,7 @@+"""+Travel & Geography Domain Templates++This module provides knowledge extraction templates for the travel and geography domain,+including travel guides, geographic encyclopedic content, and more.+Supports extraction of geographic relationships, travel routes, and spatial features.+"""diff --git a/hyperextract/templates/zh/README.md b/hyperextract/templates/zh/README.mdindex 99713d7..fef551e 100644--- a/hyperextract/templates/zh/README.md+++ b/hyperextract/templates/zh/README.md@@ -14,20 +14,18 @@| **`general`** | 通用百科 | 人物、机构、事件、地点等基础实体的快速抽取。 || **`finance`** | 金融投资 | A股/港股研报、基金招募说明书、上市公司季报。 || **`legal`** | 法律合规 | 合同关键要素(义务、权利)、案情调查、法条引用。 |-| **`education`** | 教育学术 | K12知识点图谱、课程大纲依赖关系、学术论文脉络。 || **`medicine`** | 医学健康 | 疾病症状映射、临床诊疗路径、西药说明书结构化。 || **`food`** | 美食餐饮 | 中餐菜谱(刀工、火候)、食材配比、八大菜系特征。 || **`history`** | 历史文化 | 朝代更迭时间线、重大战役、历史人物生平关系。 || **`literature`** | 文学 | 小说人物关系网、文学流派演变、古诗词意象关联。 |-| **`game`** | 游戏娱乐 | 游戏世界观设定、任务流向树、物品合成与掉落表。 |+| **`travel`** | 旅游与地理 | 游记、地理百科、地点空间关系、旅游路线规划。 || **`agriculture`** | 农业与养殖 | 作物生长周期、病虫害防治、畜牧谱系与饲养标准。 || **`biology`** | 生物科学 | 生物分类学、蛋白质相互作用、基因调控网络。 |-| **`movie`** | 影视 | 剧本节拍器拆解、演员与幕后人员网络、影评情感。 || **`news`** | 新闻传媒 | 事件因果链、新闻专题聚类、深度报道事实板。 |-| **`tcm`** | **中医 (特色)** | 中草药方剂、经络穴位、辨证施治过程等。 |-| **`wuxia`** | **武侠/修真 (特色)** | 门派恩怨、功法境界、修仙等级体系、法宝神兵。 |+| **`tcm`** | 中医 | 中草药方剂、经络穴位、辨证施治过程等。 |+| **`wuxia`** | 武侠/修真 | 门派恩怨、功法境界、修仙等级体系、法宝神兵。 |-*(注:英文版对应的 13 个通用领域在中文版中均有映射文件夹,中医与武侠为中文版独有)*+*(注:英文版对应的 11 个通用领域在中文版中均有映射文件夹,中医与武侠为中文版独有)*## 快速上手```pythondiff --git a/hyperextract/templates/zh/education/__init__.py b/hyperextract/templates/zh/education/__init__.pydeleted file mode 100644index 7aee758..0000000--- a/hyperextract/templates/zh/education/__init__.py+++ /dev/null@@ -1,9 +0,0 @@-from .prerequisite_map import PrerequisiteMapGraph-from .academic_lexicon import AcademicLexiconSet-from .interdisciplinary_nexus import InterdisciplinaryNexusHypergraph--__all__ = [- "PrerequisiteMapGraph",- "AcademicLexiconSet",- "InterdisciplinaryNexusHypergraph",-]diff --git a/hyperextract/templates/zh/education/academic_lexicon.py b/hyperextract/templates/zh/education/academic_lexicon.pydeleted file mode 100644index eb630d6..0000000--- a/hyperextract/templates/zh/education/academic_lexicon.py+++ /dev/null@@ -1,118 +0,0 @@-from typing import Optional, List, Any-from pydantic import BaseModel, Field-from langchain_core.language_models.chat_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoSet--# ==============================================================================-# 1. Schema 定义-# ==============================================================================--class AcademicTerm(BaseModel):- """- 从多个来源聚合的标准学术词条、概念或定义。- """- term: str = Field(- description="学术词条/概念的主名称。作为唯一标识符。"- )- domain: str = Field(- description="研究领域或学科(如:'热力学'、'语言学')。"- )- definition: str = Field(- description="综合多个来源后形成的权威、详细的定义描述。"- )- synonyms: List[str] = Field(- default_factory=list,- description="同义词或高度相关的别称列表。"- )- key_expression: Optional[str] = Field(- None, description="与该词条相关的核心公式、符号或标志性表达。"- )--# ==============================================================================-# 2. Prompts 提示词-# ==============================================================================--_PROMPT = (- "你是一位学术百科全书编辑和词典编纂者。你的目标是提取并标准化学术定义。\n\n"- "提取规则:\n"- "- 识别唯一的学术术语及其高度精确的定义。\n"- "- 寻找文本中出现的同义词、简称或别称。\n"- "- 如果存在对同一术语的多个描述,优先选择数学上或逻辑上更严谨的描述,并尝试进行信息互补。"-)--# ==============================================================================-# 3. 模板类-# ==============================================================================--class AcademicLexiconSet(AutoSet[AcademicTerm]):- """- 用于构建学术名词百科集的教育模板,通过**精确的术语键值进行信息累加**。- 自动将来自多个文本源的同一术语信息合并为一条完整条目,从各源中丰富定义内容。-- 用法示例:- >>> lexicon = AcademicLexiconSet(llm_client, embedder)- >>> lexicon.feed_text("来源A:光合作用是植物利用太阳能进行的生化反应...") # 提取:term='光合作用', definition=...- >>> lexicon.feed_text("来源B:光合作用在叶绿体中进行,包含光反应和暗反应...") # 自动合并到已有的'光合作用'条目中- >>> lexicon.show() # 显示合并后的学术术语集- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- *,- extraction_mode: str = "one_stage",- chunk_size: int = 2048,- chunk_overlap: int = 256,- max_workers: int = 10,- verbose: bool = False,- **kwargs: Any,- ):- """- 初始化学术名词百科模板。-- 参数描述:- llm_client (BaseChatModel): 用于提取的语言模型客户端。- embedder (Embeddings): 用于语义检索和知识图谱可视化的嵌入模型。注意:信息累加基于术语名称(key),而非嵌入向量。- extraction_mode (str): 提取模式策略。- chunk_size (int): 文本分片大小。- chunk_overlap (int): 分片重叠大小。- max_workers (int): 并行处理进程数。- verbose (bool): 是否开启详细日志。- **kwargs: 透传给 AutoSet 基类的其他参数。- """- super().__init__(- item_schema=AcademicTerm,- key_extractor=lambda x: x.term.strip().lower(),- llm_client=llm_client,- embedder=embedder,- extraction_mode=extraction_mode,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- max_workers=max_workers,- verbose=verbose,- prompt=_PROMPT,- **kwargs,- )- def show(- self,- *,- top_k_for_search: int = 3,- top_k_for_chat: int = 3,- ) -> None:- """- Visualize the collection using OntoSight.-- Args:- top_k_for_search (int): Number of items to retrieve for search context. Default 3.- top_k_for_chat (int): Number of items to retrieve for chat context. Default 3.- """- def item_label_extractor(item: AcademicTerm) -> str:- return f"{item.term}"-- super().show(- item_label_extractor=item_label_extractor,- top_k_for_search=top_k_for_search,- top_k_for_chat=top_k_for_chat,- )diff --git a/hyperextract/templates/zh/education/interdisciplinary_nexus.py b/hyperextract/templates/zh/education/interdisciplinary_nexus.pydeleted file mode 100644index 2205b73..0000000--- a/hyperextract/templates/zh/education/interdisciplinary_nexus.py+++ /dev/null@@ -1,149 +0,0 @@-from typing import List, Any-from pydantic import BaseModel, Field-from langchain_core.language_models.chat_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoHypergraph--# ==============================================================================-# 1. Schema 定义-# ==============================================================================--class ConceptNode(BaseModel):- """- 可能属于多个学科的基础学术概念。- """- name: str = Field(description="概念的标准名称。")- primary_field: str = Field(description="该概念原生所属的主要学科。")--class InterdisciplinaryEdge(BaseModel):- """- 表示不同领域多个概念之间复杂联系的超边。- """- participants: List[str] = Field(- description="参与该跨学科连接的所有节点名称列表。"- )- unifying_theme: str = Field(- description="将这些概念连接在一起的跨学科主题(例如:'复杂性理论'、'通用设计')。"- )- connectivity_insight: str = Field(- description="将这些特定知识点连接起来所产生的科学或教学价值。"- )--# ==============================================================================-# 2. Prompts 提示词-# ==============================================================================--_PROMPT = (- "你是一位通才和跨学科研究专家。请识别不同学术领域概念之间的深层联系。\n\n"- "提取规则:\n"- "- 识别核心概念作为节点。\n"- "- 创建超边,将多个概念归纳在一个统一的跨学科主题下。\n"- "- 专注于发现令人惊讶但科学有效的桥梁连接(例如:通过博弈论连接生物学和经济学)。"-)--_NODE_PROMPT = (- "识别具有跨学科潜力的基础学术概念。\n\n"- "提取规则:\n"- "- 提取对各自领域至关重要的名词/概念。\n"- "- 标注其学科来源。"-)--_EDGE_PROMPT = (- "识别连接一组概念的“纽带”或称之为超边。\n\n"- "提取规则:\n"- "- 只要可能,一个超边应涉及两个以上的节点。\n"- "- 描述统一这些概念的主题以及这种连接提供的洞察力。"-)--# ==============================================================================-# 3. 模板类-# ==============================================================================--class InterdisciplinaryNexusHypergraph(AutoHypergraph[ConceptNode, InterdisciplinaryEdge]):- """- 用于映射多点、非二元学术联系的教育领域模板。- 理想用于研究综述、课程跨学科设计以及跨学科知识管理。-- 用法示例:- >>> nexus = InterdisciplinaryNexusHypergraph(llm, embedder)- >>> nexus.feed_text("‘熵’这一概念同时适用于热力学中的‘热’和信息论中的‘信息’。")- >>> nexus.extract()- >>> # 结果将包含一个通过“熵”这一主题连接“热”与“信息”的超边。- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- *,- extraction_mode: str = "one_stage",- chunk_size: int = 2048,- chunk_overlap: int = 256,- max_workers: int = 10,- verbose: bool = False,- **kwargs: Any,- ):- """- 初始化跨学科纽带超图模板。-- 参数描述:- llm_client (BaseChatModel): 用于提取的语言模型客户端。- embedder (Embeddings): 用于节点去重的嵌入模型。- extraction_mode (str): 提取模式。- chunk_size (int): 文本分片大小。- chunk_overlap (int): 分片重叠大小。- max_workers (int): 并行处理进程数。- verbose (bool): 是否打印日志。- **kwargs: 透传给 AutoHypergraph 基类的其他参数(如一致性检查开关)。- """- super().__init__(- node_schema=ConceptNode,- edge_schema=InterdisciplinaryEdge,- node_key_extractor=lambda x: x.name.strip().lower(),- edge_key_extractor=lambda x: (- f"{x.unifying_theme.strip().lower()}_linking_{sorted(x.participants)}"- ),- nodes_in_edge_extractor=lambda x: [p.strip().lower() for p in x.participants],- llm_client=llm_client,- embedder=embedder,- extraction_mode=extraction_mode,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- max_workers=max_workers,- verbose=verbose,- prompt=_PROMPT,- prompt_for_node_extraction=_NODE_PROMPT,- prompt_for_edge_extraction=_EDGE_PROMPT,- **kwargs,- )- def show(- self,- *,- top_k_nodes_for_search: int = 3,- top_k_edges_for_search: int = 3,- top_k_nodes_for_chat: int = 3,- top_k_edges_for_chat: int = 3,- ) -> None:- """- Visualize the graph using OntoSight.-- Args:- top_k_nodes_for_search (int): Number of nodes to retrieve for search context. Default 3.- top_k_edges_for_search (int): Number of edges to retrieve for search context. Default 3.- top_k_nodes_for_chat (int): Number of nodes to retrieve for chat context. Default 3.- top_k_edges_for_chat (int): Number of edges to retrieve for chat context. Default 3.- """- def node_label_extractor(node: ConceptNode) -> str:- return f"{node.name}"-- def edge_label_extractor(edge: InterdisciplinaryEdge) -> str:- return f"{edge.unifying_theme}"-- super().show(- node_label_extractor=node_label_extractor,- edge_label_extractor=edge_label_extractor,- top_k_nodes_for_search=top_k_nodes_for_search,- top_k_edges_for_search=top_k_edges_for_search,- top_k_nodes_for_chat=top_k_nodes_for_chat,- top_k_edges_for_chat=top_k_edges_for_chat,- )diff --git a/hyperextract/templates/zh/education/prerequisite_map.py b/hyperextract/templates/zh/education/prerequisite_map.pydeleted file mode 100644index 826435c..0000000--- a/hyperextract/templates/zh/education/prerequisite_map.py+++ /dev/null@@ -1,163 +0,0 @@-from typing import Optional, Any-from pydantic import BaseModel, Field-from langchain_core.language_models.chat_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoGraph--# ==============================================================================-# 1. Schema 定义-# ==============================================================================--class KnowledgePointNode(BaseModel):- """- 学科大纲中的原子知识单位、概念或技能。- """- name: str = Field(- description="知识点或概念的标准名称。"- )- level: str = Field(- description="难度等级:'入门'、'中级'、'高级'、'专家'。"- )- concept_type: str = Field(- description="教学类型:'定义'、'定理'、'公式'、'方法'、'应用'。"- )- description: Optional[str] = Field(- None, description="该概念的核心教学内涵简述。"- )--class PrerequisiteRelation(BaseModel):- """- 有向依赖关系,表示一个概念必须在另一个概念之前学习。- """- source: str = Field(description="先修知识点(必须先学)。")- target: str = Field(description="后续知识点(后学)。")- dependency_type: str = Field(- "Prerequisite",- description="依赖性质:'必要' (必须先学), '同步' (建议同时学), '辅助' (有助于学习)。"- )- weight: float = Field(- 1.0, description="依赖强度,范围从 0.0 到 1.0。"- )--# ==============================================================================-# 2. Prompts 提示词-# ==============================================================================--_PROMPT = (- "你是一位资深课程架构师和教育心理学家。请从文本中提取知识点的逻辑结构。\n\n"- "提取规则:\n"- "- 识别构成学习路径的原子化概念。\n"- "- 建立清晰的有向依赖关系(先修要求)。\n"- "- 确保生成的图谱符合科学的教学演进逻辑。"-)--_NODE_PROMPT = (- "你是一位擅长知识拆解的教育心理学家。你的任务是识别所有离散的知识点(节点)。\n\n"- "提取规则:\n"- "- 关注代表特定学术概念、公式或方法的名词或名词短语。\n"- "- 根据上下文分配难度等级和概念类型。\n"- "- 此阶段不要识别关系或依赖。"-)--_EDGE_PROMPT = (- "你是一位课程设计师。根据已识别的知识点,映射先修关系(边)。\n\n"- "提取规则:\n"- "- 确定概念 A 是否是学习概念 B 的必要前提。\n"- "- 将依赖关系分类为必要、同步或辅助。\n"- "- 仅在提供的概念列表之间建立关系。"-)--# ==============================================================================-# 3. 模板类-# ==============================================================================--class PrerequisiteMapGraph(AutoGraph[KnowledgePointNode, PrerequisiteRelation]):- """- 用于构建知识依赖有向无环图 (DAG) 的教育领域模板。- 适用于教学大纲分析、自动化学习路径生成和学生测评规划。-- 用法示例:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> from hyperextract.templates.zh.education.prerequisite_map import PrerequisiteMapGraph- >>> graph = PrerequisiteMapGraph(llm, embedder)- >>> graph.feed_text("在理解微积分之前,必须先掌握代数和函数。")- >>> graph.extract()- >>> print(graph.nodes) # 输出包含代数、函数、微积分及其依赖关系的节点- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- *,- extraction_mode: str = "one_stage",- chunk_size: int = 2048,- chunk_overlap: int = 256,- max_workers: int = 10,- verbose: bool = False,- **kwargs: Any,- ):- """- 初始化先修图谱模板。-- 参数描述:- llm_client (BaseChatModel): 用于提取的语言模型客户端。- embedder (Embeddings): 用于节点/边去重和合并的嵌入模型。- extraction_mode (str): 提取模式。'one_stage' 为单阶段合并提取, 'two_stage' 为节点和边分开提取。- chunk_size (int): 处理大文档时的文本切片大小。- chunk_overlap (int): 切片之间的重叠长度以保持上下文完整性。- max_workers (int): 并行处理的最大进程数。- verbose (bool): 是否在执行过程中打印详细日志。- **kwargs: 透传给 AutoGraph 基类的其他参数。- """- super().__init__(- node_schema=KnowledgePointNode,- edge_schema=PrerequisiteRelation,- node_key_extractor=lambda x: x.name.strip().lower(),- edge_key_extractor=lambda x: (- f"{x.source.strip().lower()}->{x.target.strip().lower()}"- ),- nodes_in_edge_extractor=lambda x: (x.source.strip().lower(), x.target.strip().lower()),- llm_client=llm_client,- embedder=embedder,- extraction_mode=extraction_mode,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- max_workers=max_workers,- verbose=verbose,- prompt=_PROMPT,- prompt_for_node_extraction=_NODE_PROMPT,- prompt_for_edge_extraction=_EDGE_PROMPT,- **kwargs,- )- def show(- self,- *,- top_k_nodes_for_search: int = 3,- top_k_edges_for_search: int = 3,- top_k_nodes_for_chat: int = 3,- top_k_edges_for_chat: int = 3,- ) -> None:- """- Visualize the graph using OntoSight.-- Args:- top_k_nodes_for_search (int): Number of nodes to retrieve for search context. Default 3.- top_k_edges_for_search (int): Number of edges to retrieve for search context. Default 3.- top_k_nodes_for_chat (int): Number of nodes to retrieve for chat context. Default 3.- top_k_edges_for_chat (int): Number of edges to retrieve for chat context. Default 3.- """- def node_label_extractor(node: KnowledgePointNode) -> str:- return f"{node.name}"-- def edge_label_extractor(edge: PrerequisiteRelation) -> str:- return f"{edge.dependency_type}"-- super().show(- node_label_extractor=node_label_extractor,- edge_label_extractor=edge_label_extractor,- top_k_nodes_for_search=top_k_nodes_for_search,- top_k_edges_for_search=top_k_edges_for_search,- top_k_nodes_for_chat=top_k_nodes_for_chat,- top_k_edges_for_chat=top_k_edges_for_chat,- )diff --git a/hyperextract/templates/zh/game/__init__.py b/hyperextract/templates/zh/game/__init__.pydeleted file mode 100644index 2c65399..0000000--- a/hyperextract/templates/zh/game/__init__.py+++ /dev/null@@ -1,15 +0,0 @@-"""游戏领域模板。"""--from .game_item_compendium import GameItemCompendium-from .game_character_compendium import GameCharacterCompendium-from .game_monster_compendium import GameMonsterCompendium-from .patch_note_changelog import PatchNoteChangelog-from .lore_faction_network import LoreFactionNetwork--__all__ = [- "GameItemCompendium",- "GameCharacterCompendium",- "GameMonsterCompendium",- "PatchNoteChangelog",- "LoreFactionNetwork",-]diff --git a/hyperextract/templates/zh/game/game_character_compendium.py b/hyperextract/templates/zh/game/game_character_compendium.pydeleted file mode 100644index 965725a..0000000--- a/hyperextract/templates/zh/game/game_character_compendium.py+++ /dev/null@@ -1,149 +0,0 @@-"""游戏角色百科 - 从多个来源自动合并游戏角色信息。--该模板通过合并来自官方背景故事、策略指南、角色指南和补丁说明的多个来源的信息-来提取全面的游戏角色百科。-"""--from typing import Any, Optional-from pydantic import BaseModel, Field-from langchain_core.language_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoSet--# ==============================================================================-# Schema 定义-# ==============================================================================---class GameCharacterSchema(BaseModel):- """游戏角色百科中单个角色的数据结构。"""-- character_name: str = Field(..., description="角色的标准名称,如'亚索'")- class_role: str = Field(- ...,- description="角色职业/定位(如'战士'、'法师')及玩法风格简述。",- )- affiliation: Optional[str] = Field(- None, description="所属阵营、团队或出身地区。"- )- abilities: Optional[str] = Field(- None,- description="招牌技能、终极技能及核心基础数值属性。",- )- lore: Optional[str] = Field(- None, description="背景故事、性格特质、配音演员等设定信息。"- )---# ==============================================================================-# 提取 Prompt-# ==============================================================================--_PROMPT = """你是一位游戏背景设定专家和角色指南作者。-你的任务是从文本中提取游戏角色的全面信息。--对于文本中提到的每个角色,提取:-1. **character_name**:角色的官方名称-2. **class_role**:角色的职业定位与玩法概述-3. **affiliation**:角色所属的组织、阵营或家乡-4. **abilities**:角色的核心技能、大招说明及关键数值-5. **lore**:角色的背景故事、身世细节、配音等设定--仅提取文本中明确说明的信息。如果某个字段未提及,空置即可。-全面捕捉所有角色详情,即使它们分散在文本中。--### 源文本:-"""---# ==============================================================================-# 模板类-# ==============================================================================---class GameCharacterCompendium(AutoSet[GameCharacterSchema]):- """适用于:角色背景故事、技能指南、官方角色资料、策略指南-- 通过自动去重和合并来自多个来源的角色信息来提取全面的游戏角色百科。-- 来自不同来源(官方背景、策略指南、补丁说明)关于同一角色的信息会自动- 组合成单个富集的角色档案。-- 示例:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> from hyperextract.templates.zh.game import GameCharacterCompendium- >>>- >>> llm = ChatOpenAI(model="gpt-4", temperature=0)- >>> embedder = OpenAIEmbeddings()- >>>- >>> characters = GameCharacterCompendium(- ... llm_client=llm,- ... embedder=embedder- ... )- >>>- >>> # 输入多个来源- >>> characters.feed_text(- ... "亚索是来自印度群岛的一位荣誉剑士。"- ... "他以无与伦比的精准度和速度挥舞刀刃。"- ... )- >>> characters.feed_text(- ... "亚索的能力包括:钢铁飓风(Q)、风之障壁(W)、"- ... "逐风剑术(E)、最后通牒(R)。"- ... "属性:550生命值,50攻击力,25护甲。"- ... )- >>>- >>> # 所有信息自动合并为单个亚索档案- >>> characters.show()- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- chunk_size: int = 2048,- chunk_overlap: int = 256,- **kwargs: Any,- ):- """初始化游戏角色百科模板。-- 参数:- llm_client:语言模型客户端,用于角色提取(如 ChatOpenAI)- embedder:嵌入模型,用于语义索引(如 OpenAIEmbeddings)- chunk_size:单个文本块的最大字符数(默认2048)- chunk_overlap:相邻块之间的重叠字符数(默认256)- **kwargs:传递给 AutoSet 父类的其他参数- """- super().__init__(- item_schema=GameCharacterSchema,- llm_client=llm_client,- embedder=embedder,- key_extractor=lambda x: x.character_name.strip().lower(),- prompt=_PROMPT,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- **kwargs,- )-- def show(- self,- *,- top_k_for_search: int = 3,- top_k_for_chat: int = 3,- ) -> None:- """展示游戏角色百科为交互式知识图谱。-- 参数:- top_k_for_search:语义搜索返回的前 K 个结果数- top_k_for_chat:对话上下文中显示的前 K 个结果数- """-- def character_label_extractor(item: GameCharacterSchema) -> str:- """提取展示标签:角色名称带职业"""- class_label = f" ({item.class_role})" if item.class_role else ""- return f"{item.character_name}{class_label}"-- super().show(- item_label_extractor=character_label_extractor,- top_k_for_search=top_k_for_search,- top_k_for_chat=top_k_for_chat,- )diff --git a/hyperextract/templates/zh/game/game_item_compendium.py b/hyperextract/templates/zh/game/game_item_compendium.pydeleted file mode 100644index 544a4ea..0000000--- a/hyperextract/templates/zh/game/game_item_compendium.py+++ /dev/null@@ -1,138 +0,0 @@-"""游戏物品图鉴 - 从多个来源自动合并游戏物品信息。--该模板通过自动合并来自攻略、Wiki、补丁说明等多个来源的物品信息来构建完整的物品库。-使用 AutoSet 按物品名称精确匹配去重并融合属性信息。-"""--from typing import Any, Optional-from pydantic import BaseModel, Field-from langchain_core.language_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoSet--# ==============================================================================-# Schema 定义-# ==============================================================================--class GameItemSchema(BaseModel):- """游戏物品图鉴中单个物品的数据结构。"""-- item_name: str = Field(..., description="物品的标准名称")- category: str = Field(..., description="物品分类:'武器'、'防具'、'消耗品'、'材料'等")- item_data: Optional[str] = Field(- None, description="物品数值属性、合成配方及具体的伤害/防御效果。"- )- description: Optional[str] = Field(- None, description="获取方式(掉落/商店)、适用职业及背景设定故事。"- )---# ==============================================================================-# 提取 Prompt-# ==============================================================================--_PROMPT = """你是一位游戏设计师和游戏攻略作者,对游戏物品系统非常熟悉。-你的任务是从文本中提取游戏物品的结构化信息。--对于文本中提到的每个物品,提取:-1. **item_name**:物品的标准名称-2. **category**:物品的类型(武器、防具、消耗品等)-3. **item_data**:物品提供的属性加成、各种效果及合成公式信息-4. **description**:物品的来源渠道、推荐适用的职业角色及背景传说--仅提取文本中明确提及的信息。如果某个字段没有描述,空置即可。-重点是全面捕捉所有提到的物品及其详细信息。--### 源文本:-"""---# ==============================================================================-# 模板类-# ==============================================================================--class GameItemCompendium(AutoSet[GameItemSchema]):- """适用于:游戏 Wiki 页面、策略指南、官方物品手册、补丁说明-- 通过自动去重和合并来自多个来源的物品信息来提取游戏物品图鉴。-- 当多个文本块描述同一物品(通过精确名称匹配识别)时,其属性被智能合并为单一条目。- 这允许跨多个文档逐步积累关于每个物品的知识。-- 示例:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> from hyperextract.templates.zh.game import GameItemCompendium- >>>- >>> llm = ChatOpenAI(model="gpt-4", temperature=0)- >>> embedder = OpenAIEmbeddings()- >>>- >>> compendium = GameItemCompendium(- ... llm_client=llm,- ... embedder=embedder- ... )- >>>- >>> # 输入多个来源- >>> compendium.feed_text(- ... "无尽之刃是一件传奇武器,提供+80攻击力。"- ... "可以通过长剑和魔晶合成获得。"- ... )- >>> compendium.feed_text(- ... "无尽之刃与亚索和亚托克斯完美契合,"- ... "能够启动这些英雄的强大暴击连击。"- ... )- >>>- >>> # 所有信息自动在"无尽之刃"下合并- >>> compendium.show()- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- chunk_size: int = 2048,- chunk_overlap: int = 256,- **kwargs: Any,- ):- """初始化游戏物品图鉴模板。-- 参数:- llm_client:语言模型客户端,用于物品提取(如 ChatOpenAI)- embedder:嵌入模型,用于语义索引(如 OpenAIEmbeddings)- chunk_size:单个文本块的最大字符数(默认2048)- chunk_overlap:相邻块之间的重叠字符数(默认256)- **kwargs:传递给 AutoSet 父类的其他参数- """- super().__init__(- item_schema=GameItemSchema,- llm_client=llm_client,- embedder=embedder,- key_extractor=lambda x: x.item_name.strip().lower(),- prompt=_PROMPT,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- **kwargs,- )-- def show(- self,- *,- top_k_for_search: int = 3,- top_k_for_chat: int = 3,- ) -> None:- """展示游戏物品图鉴为交互式知识图谱。-- 参数:- top_k_for_search:语义搜索返回的前 K 个结果数- top_k_for_chat:对话上下文中显示的前 K 个结果数- """-- def item_label_extractor(item: GameItemSchema) -> str:- """提取展示标签:物品名称带分类"""- category_label = f" ({item.category})" if item.category else ""- return f"{item.item_name}{category_label}"-- super().show(- item_label_extractor=item_label_extractor,- top_k_for_search=top_k_for_search,- top_k_for_chat=top_k_for_chat,- )diff --git a/hyperextract/templates/zh/game/game_monster_compendium.py b/hyperextract/templates/zh/game/game_monster_compendium.pydeleted file mode 100644index 543ed86..0000000--- a/hyperextract/templates/zh/game/game_monster_compendium.py+++ /dev/null@@ -1,89 +0,0 @@-"""游戏怪物百科 - 从多个来源自动合并游戏怪物信息。--该模板通过合并来自攻略、Wiki、怪物掉落手册的多个来源的信息来构建-全面的游戏怪物数据库。-"""--from typing import Any, Optional-from pydantic import BaseModel, Field-from langchain_core.language_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoSet--# ==============================================================================-# Schema 定义-# ==============================================================================--class GameMonsterSchema(BaseModel):- """游戏怪物百科中单个怪物的数据结构。"""-- monster_name: str = Field(..., description="怪物的标准名称,如'哥布林战士'")- type: str = Field(..., description="怪物种族分类及强度:'哥布林/普通'、'龙/首领'")- habitat: Optional[str] = Field(None, description="通常出现的地图区域")- abilities: Optional[str] = Field(None, description="战斗数值、特殊技能、弱点及难度评估等综合战斗信息")- loot_and_lore: Optional[str] = Field(None, description="掉落物品、复活机制及背景故事")---# ==============================================================================-# 提取 Prompt-# ==============================================================================--_PROMPT = """你是一位游戏怪物图鉴作者。从文本中提取怪物的核心信息。--提取目标:-1. **monster_name**:怪物官方名称-2. **type**:种族及稀有度(如:亡灵/精英)-3. **habitat**:出没地点-4. **abilities**:合并战斗属性(HP/攻击)、技能、弱点和打法建议-5. **loot_and_lore**:合并掉落列表、刷新时间和背景描述--仅提取明确提及的信息。--### 源文本:-"""---# ==============================================================================-# 模板类-# ==============================================================================--class GameMonsterCompendium(AutoSet[GameMonsterSchema]):- """适用于:怪物指南、图鉴条目、刷怪指南-- 通过自动去重和合并来自多个来源的怪物信息来提取全面的游戏怪物数据库。- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- chunk_size: int = 2048,- chunk_overlap: int = 256,- **kwargs: Any,- ):- super().__init__(- item_schema=GameMonsterSchema,- llm_client=llm_client,- embedder=embedder,- key_extractor=lambda x: x.monster_name.strip().lower(),- prompt=_PROMPT,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- **kwargs,- )-- def show(- self,- *,- top_k_for_search: int = 3,- top_k_for_chat: int = 3,- ) -> None:- def monster_label_extractor(item: GameMonsterSchema) -> str:- type_label = f" ({item.type})" if item.type else ""- return f"{item.monster_name}{type_label}"-- super().show(- item_label_extractor=monster_label_extractor,- top_k_for_search=top_k_for_search,- top_k_for_chat=top_k_for_chat,- )diff --git a/hyperextract/templates/zh/game/lore_faction_network.py b/hyperextract/templates/zh/game/lore_faction_network.pydeleted file mode 100644index 22f7c6d..0000000--- a/hyperextract/templates/zh/game/lore_faction_network.py+++ /dev/null@@ -1,226 +0,0 @@-"""世界观势力网 - 从游戏背景故事中提取势力关系。--该模板构建政治/社会关系图,显示游戏世界中角色、阵营和地区之间的互动。-"""--from typing import Any, Optional-from pydantic import BaseModel, Field-from langchain_core.language_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoGraph--# ==============================================================================-# Schema 定义-# ==============================================================================--class LoreEntitySchema(BaseModel):- """背景故事网络中的实体(角色、阵营、地区)。"""-- entity_id: str = Field(..., description="该实体的唯一标识符")- entity_type: str = Field(- ...,- description="实体的类型:'英雄'(角色)、'阵营'(组织)或'地区'(地点)",- )- entity_name: str = Field(..., description="实体的名称")- description: Optional[str] = Field(None, description="对该实体的背景或特征的简要描述")---class LoreRelationshipSchema(BaseModel):- """背景故事网络中的关系。"""-- source_entity: str = Field(..., description="关系的来源实体名称")- target_entity: str = Field(..., description="关系的目标实体名称")- relationship_type: str = Field(- ...,- description="关系类型:'隶属'(忠诚)、'敌对'(冲突)、"- "'背叛'(背叛)、'建立'(建立)、'盟友'(联盟)等",- )- context: Optional[str] = Field(None, description="该关系的背景信息或解释")---# ==============================================================================-# 提取 Prompt-# ==============================================================================--_PROMPT = """你是一位游戏背景故事分析专家,擅长世界构建和势力关系。-你的任务是从游戏背景故事文本中提取实体(节点)及其政治/社会关系(边)。--提取:-1. **实体(节点)**:提到的所有角色(英雄)、阵营(组织)和地区- - 对于角色:名称,类型='英雄'- - 对于阵营:名称,类型='阵营'- - 对于地区:名称,类型='地区'--2. **关系(边)**:政治、军事和社会联系- - 隶属:一个角色隶属于一个阵营或居住在一个地区- - 敌对:两个阵营或实体处于冲突中- - 背叛:一个角色/阵营背叛了另一个- - 建立:一个角色建立了一个阵营- - 盟友:阵营之间的正式联盟- - 其他基于背景的关系类型--关键:每条边必须连接提取的节点列表中存在的两个实体。-不创建不是显式识别为节点的实体之间的边。--仅提取文本中明确说明的信息。--### 源文本:-"""--_NODE_PROMPT = """你是一位游戏背景故事实体识别专家。-你的任务是从文本中提取所有不同的实体,这些实体将成为背景故事网络的节点。--提取三种类型的实体:-1. **英雄/角色**:具有名字的个人(如"亚索"、"阿狸")-2. **阵营/组织**:团体、组织、国家、公会(如"印度群岛"、"诺克萨斯"、"监视者")-3. **地区/地点**:地理区域和地方(如"暗影岛"、"皮尔特沃夫"、"德玛西亚")--对于每个实体,提供:-- 实体名称(如文中所示)-- 实体类型(英雄/阵营/地区)-- 如果有的话,简要描述--重点放在完整性上。提取每个提到的实体,无论多么短暂。--### 源文本:-"""--_EDGE_PROMPT = """你是一位游戏背景故事网络关系提取专家。-你的任务是提取已提供实体之间的关系(边)。--给定下面的已知实体列表,提取连接它们的所有关系:-- 隶属:角色属于阵营;阵营控制地区-- 敌对:实体进行武装冲突-- 背叛:一个实体背叛了另一个-- 建立:角色建立了一个阵营-- 盟友:阵营之间的正式联盟-- 反对:反对而不一定是战争--关键规则:-1. 仅提取连接已提供实体列表中的实体的边-2. 不要发明或虚构不在提供的列表中的新实体-3. 如果实体出现在文本但不在已知列表中,不创建涉及它的边-4. 关注文本中的显式关系陈述--仅提取明确陈述的关系。不推断文中未清楚描述的关系。--### 源文本:-"""---# ==============================================================================-# 模板类-# ==============================================================================--class LoreFactionNetwork(AutoGraph[LoreEntitySchema, LoreRelationshipSchema]):- """适用于:游戏背景故事、背景文档、角色传记、设定指南-- 从游戏背景故事中提取政治和社会关系图,显示游戏世界中- 角色、阵营和地区如何相互作用。-- 该模板特别适用于:- - 可视化阵营关系和层级- - 理解角色忠诚度和冲突- - 构建世界构建图- - 分析游戏背景中的地缘政治动态-- 示例:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> from hyperextract.templates.zh.game import LoreFactionNetwork- >>>- >>> llm = ChatOpenAI(model="gpt-4", temperature=0)- >>> embedder = OpenAIEmbeddings()- >>>- >>> lore_graph = LoreFactionNetwork(- ... llm_client=llm,- ... embedder=embedder,- ... extraction_mode="two_stage"- ... )- >>>- >>> lore_graph.feed_text('''- ... 亚索是来自Ionia地区的剑士。他属于传统主义阵营。- ... 印度群岛与诺克萨斯为争夺东方领土而交战。- ... 阿狸是一只狐狸精,当她转向诺克萨斯一方时背叛了亚索。- ... ''')- >>>- >>> # 节点:亚索、印度群岛、诺克萨斯、阿狸- >>> # 边:亚索->印度群岛(隶属)、印度群岛->诺克萨斯(敌对)、阿狸->亚索(背叛)- >>> lore_graph.show()- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- extraction_mode: str = "two_stage",- chunk_size: int = 2048,- chunk_overlap: int = 256,- **kwargs: Any,- ):- """初始化世界观势力网模板。-- 参数:- llm_client:语言模型客户端,用于提取(如 ChatOpenAI)- embedder:嵌入模型,用于语义索引(如 OpenAIEmbeddings)- extraction_mode:'one_stage'(更快、更简单)或'two_stage'(更准确)- chunk_size:单个文本块的最大字符数(默认2048)- chunk_overlap:相邻块之间的重叠字符数(默认256)- **kwargs:传递给 AutoGraph 父类的其他参数- """- super().__init__(- node_schema=LoreEntitySchema,- edge_schema=LoreRelationshipSchema,- node_key_extractor=lambda x: x.entity_name.strip().lower(),- edge_key_extractor=lambda x: (- f"{x.source_entity.strip().lower()}|"- f"{x.relationship_type.strip().lower()}|"- f"{x.target_entity.strip().lower()}"- ),- nodes_in_edge_extractor=lambda x: (- x.source_entity.strip().lower(),- x.target_entity.strip().lower(),- ),- llm_client=llm_client,- embedder=embedder,- extraction_mode=extraction_mode,- prompt=_PROMPT,- prompt_for_node_extraction=_NODE_PROMPT,- prompt_for_edge_extraction=_EDGE_PROMPT,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- **kwargs,- )-- def show(- self,- *,- top_k_for_search: int = 5,- top_k_for_chat: int = 5,- ) -> None:- """展示世界观势力网为交互式关系图。-- 参数:- top_k_for_search:搜索检索的前 K 个实体数- top_k_for_chat:对话上下文中显示的前 K 个实体数- """-- def node_label_extractor(node: LoreEntitySchema) -> str:- """提取展示标签,显示实体类型"""- type_emoji = {- "英雄": "👤",- "阵营": "🏛️",- "地区": "🗺️",- }- emoji = type_emoji.get(node.entity_type, "●")- return f"{emoji} {node.entity_name}"-- def edge_label_extractor(edge: LoreRelationshipSchema) -> str:- """提取关系的展示标签"""- return edge.relationship_type.replace("_", " ")-- super().show(- node_label_extractor=node_label_extractor,- edge_label_extractor=edge_label_extractor,- top_k_for_search=top_k_for_search,- top_k_for_chat=top_k_for_chat,- )diff --git a/hyperextract/templates/zh/game/patch_note_changelog.py b/hyperextract/templates/zh/game/patch_note_changelog.pydeleted file mode 100644index 9654899..0000000--- a/hyperextract/templates/zh/game/patch_note_changelog.py+++ /dev/null@@ -1,146 +0,0 @@-"""版本更新日志 - 从补丁说明提取所有单独的游戏改动。--该模板提取游戏补丁的全面变更日志,所有修改、平衡更新和错误修复,-无去重,保留每个独立的变更条目。-"""--from typing import Any, Optional-from pydantic import BaseModel, Field-from langchain_core.language_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoList--# ==============================================================================-# Schema 定义-# ==============================================================================--class PatchChangeSchema(BaseModel):- """补丁说明中单个变更条目的数据结构。"""-- entity_name: str = Field(..., description="被修改的对象名称:角色名称、物品名称等")- change_type: str = Field(- ...,- description="变更类型:'增强'(提升)、'削弱'(下降)、'机制调整'、'错误修复'、'重做'等",- )- old_value: Optional[str] = Field(None, description="修改前的数值或状态")- new_value: Optional[str] = Field(None, description="修改后的数值或状态")- patch_version: Optional[str] = Field(None, description="该变更生效的版本号或补丁日期")- developer_note: Optional[str] = Field(None, description="开发者提供的变更理由或说明")---# ==============================================================================-# 提取 Prompt-# ==============================================================================--_PROMPT = """你是一位补丁说明分析专家和游戏平衡设计师。-你的任务是从补丁说明中提取每个单独的游戏变更的详细信息。--对于提到的每个变更或修改,提取:-1. **entity_name**:被修改的对象(角色、物品、能力、系统等)-2. **change_type**:变更的性质(增强、削弱、机制调整、错误修复、重做等)-3. **old_value**:变更前的数值、属性或机制-4. **new_value**:变更后的数值、属性或机制-5. **patch_version**:该变更实施的补丁版本或日期-6. **developer_note**:对变更的解释或理由(如提供)--关键:将每个单独的变更作为单个条目提取。-如果一个对象在一个补丁中有多个变更(例如,既被削弱攻击力又增强防御力),-为每个变更创建单独的条目以保留完整的变更历史。--仅提取文本中明确提及的信息。-全面捕捉所有修改,无论多么细微。--### 源文本:-"""---# ==============================================================================-# 模板类-# ==============================================================================--class PatchNoteChangelog(AutoList[PatchChangeSchema]):- """适用于:官方补丁说明、版本变更日志、平衡更新-- 从补丁文档中提取游戏修改的详细变更日志。-- 与进行去重的 AutoSet 不同,该模板保留每个单独的变更作为单个条目。- 这对于以下方面至关重要:- - 追踪每个对象的完整平衡历史- - 分析同一补丁中对同一对象的多个变更- - 审查游戏设计决定的演变- - 构建全面的补丁数据库而不丢失数据-- 示例:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> from hyperextract.templates.zh.game import PatchNoteChangelog- >>>- >>> llm = ChatOpenAI(model="gpt-4", temperature=0)- >>> embedder = OpenAIEmbeddings()- >>>- >>> changelog = PatchNoteChangelog(- ... llm_client=llm,- ... embedder=embedder- ... )- >>>- >>> # 输入补丁说明- >>> changelog.feed_text('''- ... 补丁 2.3.0 - 平衡更新- ... 亚索:攻击力从50增加到55(增强后期伤害)- ... 亚索:风之障壁冷却时间从25秒降低到20秒(生活质量改进)- ... 无尽之刃:攻击力加成从80增加到85- ... ''')- >>>- >>> # 每个变更都作为单独条目保留,不合并- >>> # 即使亚索有2个变更,总共得到3条条目- >>> changelog.show()- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- chunk_size: int = 2048,- chunk_overlap: int = 256,- **kwargs: Any,- ):- """初始化版本更新日志模板。-- 参数:- llm_client:语言模型客户端,用于变更提取(如 ChatOpenAI)- embedder:嵌入模型,用于语义索引(如 OpenAIEmbeddings)- chunk_size:单个文本块的最大字符数(默认2048)- chunk_overlap:相邻块之间的重叠字符数(默认256)- **kwargs:传递给 AutoList 父类的其他参数- """- super().__init__(- item_schema=PatchChangeSchema,- llm_client=llm_client,- embedder=embedder,- prompt=_PROMPT,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- **kwargs,- )-- def show(- self,- *,- top_k_for_search: int = 3,- top_k_for_chat: int = 3,- ) -> None:- """展示补丁变更日志为交互式数据库。-- 参数:- top_k_for_search:语义搜索返回的前 K 个结果数- top_k_for_chat:对话上下文中显示的前 K 个结果数- """-- def change_label_extractor(item: PatchChangeSchema) -> str:- """提取展示标签:对象名称带变更类型"""- return f"{item.entity_name} ({item.change_type})"-- super().show(- item_label_extractor=change_label_extractor,- top_k_for_search=top_k_for_search,- top_k_for_chat=top_k_for_chat,- )diff --git a/hyperextract/templates/zh/movie/__init__.py b/hyperextract/templates/zh/movie/__init__.pydeleted file mode 100644index 4bc7ed1..0000000--- a/hyperextract/templates/zh/movie/__init__.py+++ /dev/null@@ -1,9 +0,0 @@-from .character_arc_tracker import CharacterArcTracker-from .cinematic_trivia_set import CinematicTriviaSet-from .script_scene_graph import ScriptSceneGraph--__all__ = [- "CharacterArcTracker",- "CinematicTriviaSet",- "ScriptSceneGraph",-]diff --git a/hyperextract/templates/zh/movie/character_arc_tracker.py b/hyperextract/templates/zh/movie/character_arc_tracker.pydeleted file mode 100644index 71d1302..0000000--- a/hyperextract/templates/zh/movie/character_arc_tracker.py+++ /dev/null@@ -1,86 +0,0 @@-from typing import List, Optional, Any, Tuple-from pydantic import BaseModel, Field-from langchain_core.language_models.chat_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoTemporalGraph--# ==============================================================================-# 1. Schema 定义-# ==============================================================================--class CharacterState(BaseModel):- """电影人物在特定时刻的状态节点。"""- character_name: str = Field(description="人物名称。")- psychological_state: str = Field(description="人物此时的心理状态或核心情绪。")- current_goal: str = Field(description="人物此时的核心目标。")- situation: str = Field(description="人物所处的外部处境或冲突。")--class CharacterDevelopment(BaseModel):- """人物状态的演变与弧光转变。"""- source: str = Field(description="起始状态。")- target: str = Field(description="转变后的状态。")- time: str = Field(description="发生转变的时间点或剧情阶段(如‘第二幕’、‘决战前夕’)。")- trigger_event: str = Field(description="导致这一状态转变的关键剧情事件。")- arc_direction: str = Field(description="弧光方向(如:成长、堕落、觉醒、发现)。")--# ==============================================================================-# 2. 提示词 (Prompts)-# ==============================================================================--_PROMPT = (- "你是一位资深的剧本分析师和角色研究专家。你的任务是从剧本或长篇影评中追踪角色的‘人物弧光’。\n\n"- "提取要求:\n"- "1. **状态切片**:提取人物在故事不同阶段的心理、目标和处境节点。\n"- "2. **转变触发**:识别导致人物在两个状态之间发生转变的关键驱动事件。\n"- "3. **时间线解析**:明确转变发生的时间节点(如剧本页码、幕数或相对时间)。\n"-)--_NODE_PROMPT = "请识别并提取角色在剧本关键节点的内部与外部状态。记录其情绪、当下的目标以及面临的主要处境。"-_EDGE_PROMPT = "分析角色状态之间的演变。请指出是什么剧情事件触发了角色的心路历程转变,并归纳其弧光的发展方向。"--# ==============================================================================-# 3. 模板类-# ==============================================================================--class CharacterArcTracker(AutoTemporalGraph[CharacterState, CharacterDevelopment]):- """- 适用于:[角色传记, 戏剧脚本, 文学改编, 影评]-- 用于分析电影角色成长路径与心理弧光的时序图谱模板。-- 该模板专注于呈现“为什么变”和“怎么变”,适合深度角色研究与戏剧冲突分析。-- 示例:- >>> arc = CharacterArcTracker(llm_client=llm, embedder=embedder)- >>> text = "故事开始时,杰克是个胆怯的职员。在经历那场爆炸后,他意识到生命的可贵,在决战中展现了惊人的勇气。"- >>> arc.feed_text(text).show()- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- *,- extraction_mode: str = "two_stage",- **kwargs: Any- ):- super().__init__(- node_schema=CharacterState,- edge_schema=CharacterDevelopment,- node_key_extractor=lambda x: f"{x.character_name}-{x.psychological_state[:10]}",- edge_key_extractor=lambda x: f"{x.source}>>{x.target}",- time_in_edge_extractor=lambda x: x.time,- nodes_in_edge_extractor=lambda x: (x.source, x.target),- llm_client=llm_client,- embedder=embedder,- prompt=_PROMPT,- prompt_for_node_extraction=_NODE_PROMPT,- prompt_for_edge_extraction=_EDGE_PROMPT,- extraction_mode=extraction_mode,- **kwargs- )-- def show(self, **kwargs):- def n_label(node: CharacterState) -> str: return f"{node.character_name}: {node.psychological_state}"- def e_label(edge: CharacterDevelopment) -> str: return f"[{edge.time}] {edge.arc_direction}"- super().show(node_label_extractor=n_label, edge_label_extractor=e_label, **kwargs)diff --git a/hyperextract/templates/zh/movie/cinematic_trivia_set.py b/hyperextract/templates/zh/movie/cinematic_trivia_set.pydeleted file mode 100644index 0ac707c..0000000--- a/hyperextract/templates/zh/movie/cinematic_trivia_set.py+++ /dev/null@@ -1,69 +0,0 @@-from typing import List, Optional, Any-from pydantic import BaseModel, Field-from langchain_core.language_models.chat_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoSet--# ==============================================================================-# 1. Schema 定义-# ==============================================================================--class CinematicTrivia(BaseModel):- """电影要素、彩蛋、制作花絮或特殊叙事元素。"""- topic: str = Field(description="电影要素或彩蛋的主题名称(如‘致敬《2001太空漫游》’、‘打破第四面墙’)。")- description: str = Field(description="该要素的具体表现或花絮内容详情。")- timestamp: Optional[str] = Field(description="元素在电影中出现的具体时间点(如 '01:23:45')。")- significance: List[str] = Field(description="该元素的艺术意义、叙事功能或对影迷的特殊含义。")- source: List[str] = Field(description="该知识点的来源(如评论音轨、特定网站、IMDb)。")--# ==============================================================================-# 2. 提示词 (Prompts)-# ==============================================================================--_PROMPT = (- "你是一位资深的影评人和电影百科专家。你的任务是从影评、制作手册和花絮文本中提取结构化的电影百科知识点。\n\n"- "分析指南:\n"- "1. **主题去重**:将关于同一个知识点(如‘斯坦·李客串’)的多个片段合并。LLM 应确保名称标准化。\n"- "2. **深度挖掘**:不仅提取是什么,还要提取这一设计背后的艺术意图(significance)。\n"- "3. **信息累加**:通过多次读取文本,不断丰富同一个主题下的描述、时间点和来源记录。\n"-)--# ==============================================================================-# 3. 模板类-# ==============================================================================--class CinematicTriviaSet(AutoSet[CinematicTrivia]):- """- 适用于:[制作笔记, 评论音轨, 幕后花絮, 影迷趣闻, 长篇影评]-- 用于构建和聚合电影百科知识、场景彩蛋与艺术表现元素的集合模板。-- 该模板利用 AutoSet 的富集特性,能够跨文档聚合零散的影迷百科知识。-- 示例:- >>> trivia = CinematicTriviaSet(llm_client=llm, embedder=embedder)- >>> trivia.feed_text("导演在86分钟处设置了一个致敬库布里克的隐藏镜头。").feed_text("那个红色的椅子其实是致敬《闪灵》。")- >>> trivia.show()- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- *,- chunk_size: int = 2048,- **kwargs: Any- ):- super().__init__(- item_schema=CinematicTrivia,- key_extractor=lambda x: x.topic.strip().lower(),- llm_client=llm_client,- embedder=embedder,- prompt=_PROMPT,- chunk_size=chunk_size,- **kwargs- )-- def show(self, **kwargs):- def label(item: CinematicTrivia) -> str: return item.topic- super().show(item_label_extractor=label, **kwargs)diff --git a/hyperextract/templates/zh/movie/script_scene_graph.py b/hyperextract/templates/zh/movie/script_scene_graph.pydeleted file mode 100644index a639693..0000000--- a/hyperextract/templates/zh/movie/script_scene_graph.py+++ /dev/null@@ -1,90 +0,0 @@-from typing import List, Optional, Any, Tuple-from pydantic import BaseModel, Field-from langchain_core.language_models.chat_models import BaseChatModel-from langchain_core.embeddings import Embeddings-from hyperextract.types import AutoTemporalGraph--# ==============================================================================-# 1. Schema 定义-# ==============================================================================--class Scene(BaseModel):- """电影剧本中的场景节点。"""- title: str = Field(description="场景标题(如 'INT. COFFEE SHOP - DAY')。")- location: str = Field(description="场景发生的具体地点。")- time_of_day: str = Field(description="场景发生的时间段(如 DAY, NIGHT, DUSK)。")- description: str = Field(description="场景的简要动作描述或核心事件。")--class SceneTransition(BaseModel):- """场景间的转场与逻辑演变。"""- source: str = Field(description="起始场景标题。")- target: str = Field(description="目标场景标题。")- time: str = Field(description="场景间逝去的时间描述。你必须将其解析为绝对的持续时间或精确的时间偏移。")- transition_type: str = Field(description="转场方式(如 CUT TO, FADE IN, CROSSFADE)。")- logic: str = Field(description="场景间的叙事关联(如 动作延续、时间跳跃、平行剪辑)。")--# ==============================================================================-# 2. 提示词 (Prompts)-# ==============================================================================--_PROMPT = (- "你是一位资深的电影编剧和导演。你的任务是从剧本或分镜脚本中提取场景流及其叙事逻辑。\n\n"- "提取要求:\n"- "1. **场景识别**:提取所有独立的场景节点,完整记录其标题、地点和光影时间。\n"- "2. **节奏分析**:识别场景间的转场方式,并准确解析场景间的时间流逝。\n"- "3. **叙事逻辑**:描述场景之间是如何在故事层面上相互驱动的。\n"-)--_NODE_PROMPT = "请从剧本中提取所有场景(Scene)。记录每个场景的标准标题、地点、时间段及核心情节摘要。"-_EDGE_PROMPT = "在已识别的场景间建立联系(Transition)。请指出转场手段,并精确推断场景间的时间跨度与叙事逻辑关系。"--# ==============================================================================-# 3. 模板类-# ==============================================================================--class ScriptSceneGraph(AutoTemporalGraph[Scene, SceneTransition]):- """- 适用于:[电影剧本, 电视剧本, 故事板, 叙事大纲]-- 用于提取电影剧本中场景流与剪辑节奏的时序图谱模板。-- 该模板专注于呈现电影的叙事节奏和场景变换,适合导演视角下的剧本拆解与可视化。-- 示例:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> llm = ChatOpenAI(model="gpt-4o")- >>> embedder = OpenAIEmbeddings()- >>> script = ScriptSceneGraph(llm_client=llm, embedder=embedder)- >>> text = "场景1:INT. LAB - DAY。科学家正在实验。CUT TO: 场景2:EXT. STREET - NIGHT。三小时后,他出现在街头。"- >>> script.feed_text(text)- >>> script.show()- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- *,- extraction_mode: str = "two_stage",- **kwargs: Any- ):- super().__init__(- node_schema=Scene,- edge_schema=SceneTransition,- node_key_extractor=lambda x: x.title.strip(),- edge_key_extractor=lambda x: f"{x.source}->{x.target}",- time_in_edge_extractor=lambda x: x.time,- nodes_in_edge_extractor=lambda x: (x.source, x.target),- llm_client=llm_client,- embedder=embedder,- prompt=_PROMPT,- prompt_for_node_extraction=_NODE_PROMPT,- prompt_for_edge_extraction=_EDGE_PROMPT,- extraction_mode=extraction_mode,- **kwargs- )-- def show(self, **kwargs):- def n_label(node: Scene) -> str: return node.title- def e_label(edge: SceneTransition) -> str: return f"{edge.transition_type} ({edge.time})"- super().show(node_label_extractor=n_label, edge_label_extractor=e_label, **kwargs)diff --git a/hyperextract/templates/zh/travel/__init__.py b/hyperextract/templates/zh/travel/__init__.pynew file mode 100644index 0000000..f15395c--- /dev/null+++ b/hyperextract/templates/zh/travel/__init__.py@@ -0,0 +1,6 @@+"""+Travel & Geography Domain Templates (中文版)++此模块提供与旅游和地理领域相关的知识抽取模板,包括游记、地理百科等内容。+支持提取地点关系、旅游路线、地理特征等结构化知识。+"""