Hypergraph is more powerful. Transform unstructured text into structured knowledge with LLMs. Graphs, hypergraphs, and spatio-temporal extractions — with one command.
Remove unused templates for construction, cybersecurity, fashion, marketing, music, politics, real estate, recruitment, software, sports, supply chain, and travel from the hyperextract project.
yifanfeng974e86348d7b8a
diff --git a/README.md b/README.mdindex 714be00..8dfb8c5 100644--- a/README.md+++ b/README.md@@ -88,9 +88,9 @@ The `hyperextract/templates` directory provides a wealth of domain-specific defi| :--- | :--- | :--- || **General** | `General`, `IText2KG` | Versatile extraction for most daily knowledge. || **Science** | `Physics`, `Chemistry`, `Biology` | Capture experiments, elements, and reactions. |-| **Industry** | `Finance`, `Legal`, `Cybersecurity` | Extract compliance, risks, and entity webs. |-| **Entertainment** | `Game`, `Movie`, `Music` | Perfect for story plots and character networks. |-| ... | | 20+ more domains in the [templates folder](hyperextract/templates) |+| **Industry** | `Finance`, `Legal` | Extract compliance, risks, and entity webs. |+| **Entertainment** | `Game`, `Movie`, `Food` | Perfect for story plots, character networks, and recipes. |+| ... | | 15+ domains in the [templates folder](hyperextract/templates) |---diff --git a/README_ZH.md b/README_ZH.mdindex 12a29b3..cfc5c0d 100644--- a/README_ZH.md+++ b/README_ZH.md@@ -88,9 +88,9 @@ print(answer.content)| :--- | :--- | :--- || **通用** | `General`, `IText2KG` | 适用于大多数日常知识提取。 || **科学** | `Physics`, `Chemistry`, `Biology` | 捕捉科学实验、元素、反应过程。 |-| **行业** | `Finance`, `Legal`, `Cybersecurity` | 提取合规、风险点、实体关联。 |-| **娱乐** | `Game`, `Movie`, `Music` | 完美支持游戏剧情、角色关系网。 |-| ... | | 更多 20+ 领域见 [templates 目录](hyperextract/templates) |+| **行业** | `Finance`, `Legal` | 提取合规、风险点、实体关联。 |+| **娱乐** | `Game`, `Movie`, `Food` | 完美支持游戏剧情、角色关系网、食谱制作。 |+| ... | | 更多 15+ 领域见 [templates 目录](hyperextract/templates) |---diff --git a/hyperextract/templates/en/README.md b/hyperextract/templates/en/README.mdindex c2aa374..b00231e 100644--- a/hyperextract/templates/en/README.md+++ b/hyperextract/templates/en/README.md@@ -12,16 +12,10 @@ Welcome to the **Hyper-Extract Domain Templates** library. This directory contai| Folder | Description | Potential Use Cases || :--- | :--- | :--- || **`agriculture`** | Farming, livestock, and crop management. | Crop rotation, irrigation systems. |-| **`art`** | Fine arts, museum collections, and provenance. | Artwork catalogs, historical art movements. |-| **`automotive`** | Vehicles, manufacturing, and maintenance. | Car specs, maintenance logs. || **`biology`** | Life sciences, genetics, and taxonomy. | Protein interactions, species classification. |-| **`business`** | General corporate profiles and strategy. | Company bios, strategic goals. || **`chemistry`** | Molecular structures and reactions. | Chemical compounds, lab experiments. |-| **`construction`** | Building, BIM, and project planning. | Construction milestones, blueprint entities. |-| **`cybersecurity`** | Threat intelligence and network defense. | STIX models, attack vectors. || **`education`** | Knowledge points and curriculum. | Course prerequisites, learning paths. || **`environment`** | Climate, ecology, and sustainability. | Weather patterns, carbon footprint tracking. |-| **`fashion`** | Garments, trends, and collections. | Design lookbooks, seasonal trends. || **`finance`** | Banking, stocks, and investments. | Earnings reports, stock analysis. || **`food`** | Culinary, recipes, and nutrition. | Menu planning, recipe breakdown. || **`game`** | Game lore, mechanics, and quests. | NPC relations, quest trees, item crafting. |@@ -29,19 +23,10 @@ Welcome to the **Hyper-Extract Domain Templates** library. This directory contai| **`history`** | Events, timelines, and figures. | War campaigns, historical biographies. || **`legal`** | Law, contracts, and compliance. | Contract obligations, court rulings. || **`literature`** | Fiction, poetry, and character arcs. | Character maps, literary themes. |-| **`marketing`** | Campaigns, SEO, and personas. | Customer journeys, brand archetypes. || **`medicine`** | Western and clinical medicine. | Diagnosis, symptom mapping, pharma. || **`movie`** | Film, TV, and scripts. | Screenplay beats, cast & crew networks. |-| **`music`** | Theory, albums, and discography. | Genre evolution, tracklists. || **`news`** | Media and trending topics. | Investigative boards, causality analysis. || **`physics`** | Particle physics, astronomy, and circuits. | Celestial systems, circuit paths. |-| **`politics`** | Governance, policy, and geopolitics. | Legislative tracking, election maps. |-| **`real_estate`** | Property, leasing, and zoning. | Property listings, floor plans. |-| **`recruitment`** | HR, resumes, and hiring. | Skill mapping, interview assessment. |-| **`software`** | Architecture, APIs, and DevOps. | Microservices, software dependencies. |-| **`sports`** | Tournaments, matches, and stats. | Match event logs, player profiles. |-| **`supply_chain`**| Logistics and inventory flow. | Supplier tiering, logistics routes. |-| **`travel`** | Tourism and itineraries. | Trip planning, attraction reviews. |## UsageSimply import the template you need:diff --git a/hyperextract/templates/en/__init__.py b/hyperextract/templates/en/__init__.pyindex ada7ed1..db5ed8b 100644--- a/hyperextract/templates/en/__init__.py+++ b/hyperextract/templates/en/__init__.py@@ -2,20 +2,10 @@ from .general.knowledge_graph import KnowledgeGraphfrom .general.concept_map import ConceptMapfrom .general.logic_graph import LogicGraphfrom .agriculture.crop import CropStatusGraph-from .agriculture.supply_chain import AgriSupplyChainGraphfrom .agriculture.soil import SoilNutritionGraph-from .art.history import ArtHistoryGraph-from .art.style import ArtStyleGraph-from .art.exhibition import ExhibitionGraph-from .automotive.vehicle import VehicleSpecGraph-from .automotive.diagnosis import VehicleDiagnosisGraph-from .automotive.market import AutoMarketGraphfrom .biology.taxonomy import TaxonomyGraphfrom .biology.network import BiologicalNetworkfrom .biology.metabolic import MetabolicHypergraph-from .business.equity import EquityStructureGraph-from .business.strategy import StrategicChainGraph-from .business.ecosystem import MarketEcosystemHyperfrom .chemistry.molecular import MolecularStructureGraphfrom .chemistry.reaction import ChemicalReactionHyperfrom .chemistry.protocol import LabProtocolTemporal@@ -25,20 +15,10 @@ __all__ = ["ConceptMap","LogicGraph","CropStatusGraph",- "AgriSupplyChainGraph","SoilNutritionGraph",- "ArtHistoryGraph",- "ArtStyleGraph",- "ExhibitionGraph",- "VehicleSpecGraph",- "VehicleDiagnosisGraph",- "AutoMarketGraph","TaxonomyGraph","BiologicalNetwork","MetabolicHypergraph",- "EquityStructureGraph",- "StrategicChainGraph",- "MarketEcosystemHyper","MolecularStructureGraph","ChemicalReactionHyper","LabProtocolTemporal",diff --git a/hyperextract/templates/en/art/__init__.py b/hyperextract/templates/en/art/__init__.pydeleted file mode 100644index 96cb725..0000000--- a/hyperextract/templates/en/art/__init__.py+++ /dev/null@@ -1,9 +0,0 @@-from .provenance import ProvenanceGraph-from .movement import ArtMovementGraph-from .exhibition import ExhibitionGraph--__all__ = [- "ProvenanceGraph",- "ArtMovementGraph",- "ExhibitionGraph",-]diff --git a/hyperextract/templates/en/art/exhibition.py b/hyperextract/templates/en/art/exhibition.pydeleted file mode 100644index 1ac4a8c..0000000--- a/hyperextract/templates/en/art/exhibition.py+++ /dev/null@@ -1,152 +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 ExhibitionEntity(BaseModel):- """An element of an art exhibition (Curator, Theme, Work, Venue, Sponsor)."""-- name: str = Field(description="Name of the exhibition, artist, or curator.")- type: str = Field(- description="Type: 'Exhibition', 'Theme', 'Artwork', 'Curator', 'Venue', 'Partner'."- )- details: Optional[str] = Field(- description="Exhibition dates, conceptual notes, or location."- )---class ExhibitionRelation(BaseModel):- """Connectivity within an exhibition's planning and execution."""-- source: str = Field(description="The organizing or controlling entity.")- target: str = Field(description="The related work or participant.")- relation_type: str = Field(- description="Type: 'Curated by', 'Featured in', 'Hosted at', 'Sponsored by', 'Thematically linked to'."- )- context: Optional[str] = Field(- description="Specific room, loan conditions, or thematic sub-group."- )---# ==============================================================================-# 2. Prompts-# ==============================================================================--EXHIBITION_GRAPH_PROMPT = (- "You are a museum curator and exhibition designer. Map the structure of an art exhibition.\n\n"- "Guidelines:\n"- "- Identify the exhibition title, its central themes, and the participating artists/works.\n"- "- Connect works to their thematic sections and the curators responsible.\n"- "- Capture logistics like venues and sponsors."-)--EXHIBITION_NODE_PROMPT = "Extract exhibition components: titles, venues, themes, specific artworks, and key personnel (curators, designers)."--EXHIBITION_EDGE_PROMPT = "Link items within the exhibition. Show which artworks belong to which theme and identify the hosting venue and sponsors."--# ==============================================================================-# 3. Template Class-# ==============================================================================---class ExhibitionGraph(AutoGraph[ExhibitionEntity, ExhibitionRelation]):- """- Template for curatorial planning and exhibition analysis.-- Tracks the relationships between artworks, themes, curators, and venues.-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> llm = ChatOpenAI()- >>> embedder = OpenAIEmbeddings()- >>> graph = ExhibitionGraph(llm_client=llm, embedder=embedder)- >>> text = "The 'Surrealist Dreams' exhibition was curated by Alice Smith at the Tate Modern."- >>> graph.feed_text(text)- >>> print(graph.edges) # Exhibition connections- """-- 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 ExhibitionGraph template.-- Args:- llm_client: The language model client for extraction.- embedder: The embedding model for deduplication.- extraction_mode: "one_stage" or "two_stage".- chunk_size: Max characters per chunk.- chunk_overlap: Overlap between chunks.- max_workers: Parallel processing workers.- verbose: Enable progress logging.- **kwargs: Extra arguments for AutoGraph.- """- super().__init__(- node_schema=ExhibitionEntity,- edge_schema=ExhibitionRelation,- node_key_extractor=lambda x: x.name.strip(),- edge_key_extractor=lambda x: (- f"{x.source.strip()}--({x.relation_type.lower()})-->{x.target.strip()}"- ),- nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),- 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=EXHIBITION_GRAPH_PROMPT,- prompt_for_node_extraction=EXHIBITION_NODE_PROMPT,- prompt_for_edge_extraction=EXHIBITION_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: ExhibitionEntity) -> str:- info = f" ({node.type})" if getattr(node, "type", None) else ""- return f"{node.name}{info}"-- def edge_label_extractor(edge: ExhibitionRelation) -> str:- return f"{edge.relation_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/art/movement.py b/hyperextract/templates/en/art/movement.pydeleted file mode 100644index 1558901..0000000--- a/hyperextract/templates/en/art/movement.py+++ /dev/null@@ -1,157 +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 MovementEntity(BaseModel):- """An art movement, style, artist, or influential work."""-- name: str = Field(- description="Name of the movement (e.g., Impressionism) or Artist."- )- category: str = Field(- description="Category: 'Movement', 'Style', 'Artist', 'Manifesto', 'Masterpiece'."- )- attributes: Optional[str] = Field(- description="Key characteristics, materials, or timeframe."- )---class ArtInfluenceEdge(BaseModel):- """Influence, derivation, or membership relations in art history."""-- source: str = Field(description="The precursor or movement.")- target: str = Field(description="The follower or specific work/artist.")- relation: str = Field(- description="Relation: 'Influenced', 'Founder of', 'Member of', 'Reaction against', 'Derived from'."- )- details: Optional[str] = Field(- description="Specific stylistic techniques or historical events."- )---# ==============================================================================-# 2. Prompts-# ==============================================================================--MOVEMENT_GRAPH_PROMPT = (- "You are an art historian specializing in the evolution of artistic styles. Extract a graph of art movements and their influences.\n\n"- "Guidelines:\n"- "- Identify distinct art movements and the artists associated with them.\n"- "- Map how one movement influenced another (e.g., Post-Impressionism reacting to Impressionism).\n"- "- Capture the core philosophies and visual characteristics defined in manifestos or works."-)--MOVEMENT_NODE_PROMPT = "Extract art movements, styles, associated artists, and pivotal artworks. Describe their visual language and key theories."--MOVEMENT_EDGE_PROMPT = (- "Define connections between movements and individuals. Use relations like 'Reaction against' or 'Influenced'. "- "Note specific techniques passed between generations."-)--# ==============================================================================-# 3. Template Class-# ==============================================================================---class ArtMovementGraph(AutoGraph[MovementEntity, ArtInfluenceEdge]):- """- Template for mapping art movements, stylistic influences, and artist school affiliations.-- Useful for educational applications and art historical analysis.-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> llm = ChatOpenAI()- >>> embedder = OpenAIEmbeddings()- >>> graph = ArtMovementGraph(llm_client=llm, embedder=embedder)- >>> text = "Impressionism, led by Monet, was later challenged by the structured approach of Post-Impressionism."- >>> graph.feed_text(text)- >>> print(graph.nodes) # Movement and Artist details- """-- 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 ArtMovementGraph template.-- Args:- llm_client: The language model client for extraction.- embedder: The embedding model for deduplication.- extraction_mode: "one_stage" or "two_stage".- chunk_size: Max characters per chunk.- chunk_overlap: Overlap between chunks.- max_workers: Parallel processing workers.- verbose: Enable progress logging.- **kwargs: Extra arguments for AutoGraph.- """- super().__init__(- node_schema=MovementEntity,- edge_schema=ArtInfluenceEdge,- node_key_extractor=lambda x: x.name.strip(),- edge_key_extractor=lambda x: (- f"{x.source.strip()}--({x.relation.lower()})-->{x.target.strip()}"- ),- nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),- 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=MOVEMENT_GRAPH_PROMPT,- prompt_for_node_extraction=MOVEMENT_NODE_PROMPT,- prompt_for_edge_extraction=MOVEMENT_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: MovementEntity) -> str:- info = f" ({node.category})" if getattr(node, "category", None) else ""- return f"{node.name}{info}"-- def edge_label_extractor(edge: ArtInfluenceEdge) -> str:- return f"{edge.relation}"-- 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/art/provenance.py b/hyperextract/templates/en/art/provenance.pydeleted file mode 100644index 584c3fc..0000000--- a/hyperextract/templates/en/art/provenance.py+++ /dev/null@@ -1,158 +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 ArtEntity(BaseModel):- """An entity in the art world (e.g., Artwork, Artist, Museum, Collector, Auction House)."""-- name: str = Field(description="Name of the artwork, person, or organization.")- category: str = Field(- description="Category: 'Artwork', 'Artist', 'Collector', 'Institution', 'Location'."- )- description: Optional[str] = Field(- description="Medium, creation date, or historical status."- )---class ProvenanceEdge(BaseModel):- """The transfer of ownership or location of an artwork."""-- source: str = Field(description="Previous owner or starting location.")- target: str = Field(description="New owner or destination.")- transfer_type: str = Field(- description="Type: 'Acquired by', 'Sold to', 'Donated to', 'Lent to', 'Commissioned by'."- )- specification: Optional[str] = Field(- description="Date of transfer, sale price, or auction details."- )---# ==============================================================================-# 2. Prompts-# ==============================================================================--PROVENANCE_GRAPH_PROMPT = (- "You are a fine arts historian and provenance researcher. Extract an artwork's ownership history graph.\n\n"- "Guidelines:\n"- "- Identify the core artwork and all its historical owners (Collectors, Museums, Kings).\n"- "- Map the chronological sequence of transfers (Sales, Inheritances, Looting, Donations).\n"- "- Capture specific dates and monetary values if mentioned."-)--PROVENANCE_NODE_PROMPT = (- "Extract art entities: identify the artwork itself, the artists, collectors, museums, and auction houses. "- "Note the medium of the artwork and roles of the people/institutions."-)--PROVENANCE_EDGE_PROMPT = (- "Establish the chain of title. Connect previous owners to current owners using transfer types like 'Sold to' or 'Donated to'. "- "Include time periods and transaction details in the specification."-)--# ==============================================================================-# 3. Template Class-# ==============================================================================---class ProvenanceGraph(AutoGraph[ArtEntity, ProvenanceEdge]):- """- Template for tracking the ownership history (provenance) of artworks and artifacts.-- Essential for art authentication, museum archives, and historical research.-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> llm = ChatOpenAI(model="gpt-4o")- >>> embedder = OpenAIEmbeddings()- >>> graph = ProvenanceGraph(llm_client=llm, embedder=embedder)- >>> text = "The painting was acquired by the Louvre in 1815 from the Borghese collection."- >>> graph.feed_text(text)- >>> print(graph.edges) # Extracted ownership transfer- """-- 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 ProvenanceGraph template.-- Args:- llm_client: The language model client for extraction.- embedder: The embedding model for deduplication.- extraction_mode: "one_stage" or "two_stage".- chunk_size: Max characters per chunk.- chunk_overlap: Overlap between chunks.- max_workers: Parallel processing workers.- verbose: Enable progress logging.- **kwargs: Extra arguments for AutoGraph.- """- super().__init__(- node_schema=ArtEntity,- edge_schema=ProvenanceEdge,- node_key_extractor=lambda x: x.name.strip(),- edge_key_extractor=lambda x: (- f"{x.source.strip()}--({x.transfer_type.lower()})-->{x.target.strip()}"- ),- nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),- 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=PROVENANCE_GRAPH_PROMPT,- prompt_for_node_extraction=PROVENANCE_NODE_PROMPT,- prompt_for_edge_extraction=PROVENANCE_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: ArtEntity) -> str:- info = f" ({node.category})" if getattr(node, "category", None) else ""- return f"{node.name}{info}"-- def edge_label_extractor(edge: ProvenanceEdge) -> str:- return f"{edge.transfer_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/automotive/__init__.py b/hyperextract/templates/en/automotive/__init__.pydeleted file mode 100644index 0184d1b..0000000--- a/hyperextract/templates/en/automotive/__init__.py+++ /dev/null@@ -1,9 +0,0 @@-from .car_spec import CarSpecGraph-from .maintenance import CarMaintenanceGraph-from .manufacturing import AutomotiveMfgGraph--__all__ = [- "CarSpecGraph",- "CarMaintenanceGraph",- "AutomotiveMfgGraph",-]diff --git a/hyperextract/templates/en/automotive/car_spec.py b/hyperextract/templates/en/automotive/car_spec.pydeleted file mode 100644index 70a20c6..0000000--- a/hyperextract/templates/en/automotive/car_spec.py+++ /dev/null@@ -1,141 +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 CarComponent(BaseModel):- """A vehicle component or specification category (Engine, Battery, ADAS, Transmission)."""- name: str = Field(description="Name of the car model or specific component.")- category: str = Field(- description="Category: 'Model', 'Powertrain', 'Chassis', 'Safety System', 'Infotainment'."- )- specification: Optional[str] = Field(description="Detailed specs (e.g., Horsepower, Capacity, Version).")--class CarSystemRelation(BaseModel):- """The hierarchy or technical relationship between car systems."""- source: str = Field(description="Parent system or vehicle model.")- target: str = Field(description="Sub-component or feature.")- relation_type: str = Field(- description="Type: 'Equipped with', 'Powered by', 'Integrated with', 'Compatible with'."- )- performance_note: Optional[str] = Field(description="Benchmark data or integration details.")--# ==============================================================================-# 2. Prompts-# ==============================================================================--CAR_SPEC_GRAPH_PROMPT = (- "You are an automotive engineer and technical reviewer. Extract a technical specification graph for a vehicle.\n\n"- "Guidelines:\n"- "- Identify the vehicle model and its primary systems (Engine, Motor, Battery, ADAS).\n"- "- Map the hierarchy of components (e.g., Battery contains Cells, Engine uses Turbocharger).\n"- "- Capture quantifiable specs like 0-60 mph, Range, Peak Power, and Torque."-)--CAR_SPEC_NODE_PROMPT = (- "Extract car models and technical components. Focus on names and their measurable specifications (e.g., 500hp, 80kWh)."-)--CAR_SPEC_EDGE_PROMPT = (- "Define technical dependencies. Show which components belong to which car system. Use relations like 'Powered by' or 'Equipped with'."-)--# ==============================================================================-# 3. Template Class-# ==============================================================================--class CarSpecGraph(AutoGraph[CarComponent, CarSystemRelation]):- """- Template for extracting vehicle technical data and specification hierarchies.-- Ideal for competitive analysis, e-commerce car data, and technical documentation.-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> llm = ChatOpenAI()- >>> embedder = OpenAIEmbeddings()- >>> graph = CarSpecGraph(llm_client=llm, embedder=embedder)- >>> text = "The Tesla Model 3 Performance features a dual-motor AWD system delivering 510 hp."- >>> graph.feed_text(text)- >>> print(graph.nodes) # Vehicle and component specs- """- 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 CarSpecGraph template.-- Args:- llm_client: The language model client for extraction.- embedder: The embedding model for deduplication.- extraction_mode: "one_stage" or "two_stage".- chunk_size: Max characters per chunk.- chunk_overlap: Overlap between chunks.- max_workers: Parallel processing workers.- verbose: Enable progress logging.- **kwargs: Extra arguments for AutoGraph.- """- super().__init__(- node_schema=CarComponent,- edge_schema=CarSystemRelation,- node_key_extractor=lambda x: x.name.strip(),- edge_key_extractor=lambda x: f"{x.source.strip()}--({x.relation_type.lower()})-->{x.target.strip()}",- nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),- 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=CAR_SPEC_GRAPH_PROMPT,- prompt_for_node_extraction=CAR_SPEC_NODE_PROMPT,- prompt_for_edge_extraction=CAR_SPEC_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: CarComponent) -> str:- info = f" ({ node.category })" if getattr(node, "category", None) else ""- return f"{ node.name }{info}"-- def edge_label_extractor(edge: CarSystemRelation) -> str:- return f"{ edge.relation_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/automotive/maintenance.py b/hyperextract/templates/en/automotive/maintenance.pydeleted file mode 100644index 603c387..0000000--- a/hyperextract/templates/en/automotive/maintenance.py+++ /dev/null@@ -1,137 +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 MaintenanceItem(BaseModel):- """A maintenance task or vehicle part (Oil Change, Brake Pad, Timing Belt)."""- item_name: str = Field(description="Name of the part or maintenance service.")- category: str = Field(description="Category: 'Fluid', 'Wearable Part', 'Inspection', 'Software'.")- interval: Optional[str] = Field(description="Suggested mileage or time interval (e.g., 5,000 miles).")--class MaintenanceSequence(BaseModel):- """The dependency or sequence of maintenance actions."""- source: str = Field(description="Prerequisite component or initial state.")- target: str = Field(description="Maintenance task or replacement part.")- action: str = Field(description="Action: 'Replace', 'Inspect', 'Flush', 'Calibrate'.")- precaution: Optional[str] = Field(description="Safety warnings or required tools.")--# ==============================================================================-# 2. Prompts-# ==============================================================================--MAINTENANCE_GRAPH_PROMPT = (- "You are a master mechanic and service consultant. Extract a vehicle maintenance and repair graph.\n\n"- "Guidelines:\n"- "- Identify specific maintenance items and parts mentioned in the manual or log.\n"- "- Map the conditions that trigger maintenance (e.g., Mileage, Warning Light, Visual Inspection).\n"- "- Link parts to their respective systems and required actions."-)--MAINTENANCE_NODE_PROMPT = (- "Extract maintenance tasks, parts, and fluid types. Include recommended intervals if specified."-)--MAINTENANCE_EDGE_PROMPT = (- "Connect triggers to actions. Show which parts need replacement or inspection. Note specific precautions for each task."-)--# ==============================================================================-# 3. Template Class-# ==============================================================================--class CarMaintenanceGraph(AutoGraph[MaintenanceItem, MaintenanceSequence]):- """- Template for vehicle service manuals, repair guides, and ownership logs.-- Helps organize maintenance schedules and part compatibility information.-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> llm = ChatOpenAI()- >>> embedder = OpenAIEmbeddings()- >>> graph = CarMaintenanceGraph(llm_client=llm, embedder=embedder)- >>> text = "Change engine oil and filter every 10,000 km using synthetic 0W-20."- >>> graph.feed_text(text)- >>> print(graph.nodes) # Maintenance items- """- 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 CarMaintenanceGraph template.-- Args:- llm_client: The language model client for extraction.- embedder: The embedding model for deduplication.- extraction_mode: "one_stage" or "two_stage".- chunk_size: Max characters per chunk.- chunk_overlap: Overlap between chunks.- max_workers: Parallel processing workers.- verbose: Enable progress logging.- **kwargs: Extra arguments for AutoGraph.- """- super().__init__(- node_schema=MaintenanceItem,- edge_schema=MaintenanceSequence,- node_key_extractor=lambda x: x.item_name.strip(),- edge_key_extractor=lambda x: f"{x.source.strip()}--({x.action.lower()})-->{x.target.strip()}",- nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),- 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=MAINTENANCE_GRAPH_PROMPT,- prompt_for_node_extraction=MAINTENANCE_NODE_PROMPT,- prompt_for_edge_extraction=MAINTENANCE_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: MaintenanceItem) -> str:- info = f" ({ node.category })" if getattr(node, "category", None) else ""- return f"{ node.item_name }{info}"-- def edge_label_extractor(edge: MaintenanceSequence) -> str:- return f"{ edge.action }"-- 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/automotive/manufacturing.py b/hyperextract/templates/en/automotive/manufacturing.pydeleted file mode 100644index 5304cdc..0000000--- a/hyperextract/templates/en/automotive/manufacturing.py+++ /dev/null@@ -1,141 +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 ManufacturingEntity(BaseModel):- """An entity in the automotive supply chain or production line (Supplier, Factory, Assembly Step)."""- name: str = Field(description="Name of the company, factory, or production process.")- category: str = Field(- description="Category: 'Supplier', 'Factory', 'Process', 'Material', 'Quality Check'."- )- specification: Optional[str] = Field(description="Production capacity, certifications, or lead times.")--class SupplyChainRelation(BaseModel):- """Connectivity between players and steps in automotive manufacturing."""- source: str = Field(description="The upstream supplier or process.")- target: str = Field(description="The downstream factory or product.")- relation_type: str = Field(- description="Type: 'Supplies to', 'Assembled at', 'Processed by', 'Certified for'."- )- logistics_details: Optional[str] = Field(description="Incoterms, transit times, or volume commitments.")--# ==============================================================================-# 2. Prompts-# ==============================================================================--MFG_GRAPH_PROMPT = (- "You are a supply chain analyst for a major auto manufacturer. Extract the manufacturing and supply chain graph.\n\n"- "Guidelines:\n"- "- Identify the tiers of suppliers (Tier 1, Tier 2) and the components they provide.\n"- "- Map the assembly sequence from raw materials to the final vehicle roll-out.\n"- "- Capture geographic locations of factories and specific logistics constraints."-)--MFG_NODE_PROMPT = (- "Extract suppliers, manufacturing plants, and critical production steps. Note their roles in the vehicle production cycle."-)--MFG_EDGE_PROMPT = (- "Define the material and process flow. Connect suppliers to assembly plants and plants to the final car delivery."-)--# ==============================================================================-# 3. Template Class-# ==============================================================================--class AutomotiveMfgGraph(AutoGraph[ManufacturingEntity, SupplyChainRelation]):- """- Template for automotive production lines, supply chain logistics, and supplier management.-- Helps visualize dependencies in the global automotive manufacturing ecosystem.-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> llm = ChatOpenAI()- >>> embedder = OpenAIEmbeddings()- >>> graph = AutomotiveMfgGraph(llm_client=llm, embedder=embedder)- >>> text = "CATL supplies battery cells to the Tesla Gigafactory in Berlin for Model Y assembly."- >>> graph.feed_text(text)- >>> print(graph.edges) # Supply chain flow- """- 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 AutomotiveMfgGraph template.-- Args:- llm_client: The language model client for extraction.- embedder: The embedding model for deduplication.- extraction_mode: "one_stage" or "two_stage".- chunk_size: Max characters per chunk.- chunk_overlap: Overlap between chunks.- max_workers: Parallel processing workers.- verbose: Enable progress logging.- **kwargs: Extra arguments for AutoGraph.- """- super().__init__(- node_schema=ManufacturingEntity,- edge_schema=SupplyChainRelation,- node_key_extractor=lambda x: x.name.strip(),- edge_key_extractor=lambda x: f"{x.source.strip()}--({x.relation_type.lower()})-->{x.target.strip()}",- nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),- 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=MFG_GRAPH_PROMPT,- prompt_for_node_extraction=MFG_NODE_PROMPT,- prompt_for_edge_extraction=MFG_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: ManufacturingEntity) -> str:- info = f" ({ node.category })" if getattr(node, "category", None) else ""- return f"{ node.name }{info}"-- def edge_label_extractor(edge: SupplyChainRelation) -> str:- return f"{ edge.relation_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/business/__init__.py b/hyperextract/templates/en/business/__init__.pydeleted file mode 100644index 8da251c..0000000--- a/hyperextract/templates/en/business/__init__.py+++ /dev/null@@ -1,9 +0,0 @@-from .equity import EquityStructureGraph-from .strategy import StrategicChainGraph-from .ecosystem import MarketEcosystemHyper--__all__ = [- "EquityStructureGraph",- "StrategicChainGraph",- "MarketEcosystemHyper",-]diff --git a/hyperextract/templates/en/business/ecosystem.py b/hyperextract/templates/en/business/ecosystem.pydeleted file mode 100644index 789d3ca..0000000--- a/hyperextract/templates/en/business/ecosystem.py+++ /dev/null@@ -1,148 +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 AutoHypergraph--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================---class IndustryParticipant(BaseModel):- """- An entity (Company, Regulatory Body, NGO) within an industrial ecosystem.- """-- name: str = Field(- description="Name of the actor (e.g., 'TSMC', 'European Commission')."- )- rank: Optional[str] = Field(- None,- description="Market position: 'Tier 1 Supplier', 'Market Leader', 'Challenger'.",- )- technological_focus: Optional[str] = Field(- None, description="Primary tech or domain (e.g., '5G', 'Lithography')."- )---class CollectiveAlliance(BaseModel):- """- A hyperedge representing a consortium, alliance, market cartel, or joint standard-setting body.- """-- alliance_id: str = Field(- description="Name or identifier of the alliance (e.g., 'CHIPS Alliance')."- )- participants: List[str] = Field(- description="Names of all entities collaborating or competing in this group."- )- shared_goal: str = Field(- description="The objective: 'Standardization', 'Anti-monopoly Review', 'Joint R&D'."- )- governance: Optional[str] = Field(- None, description="Rules of participation or leading entity."- )---# ==============================================================================-# 2. Prompts-# ==============================================================================--ECOSYSTEM_CONSOLIDATED_PROMPT = (- "You are a market strategist and antitrust expert. Extract market ecosystem dynamics.\n\n"- "Rules:\n"- "- Use Hyperedges to link multiple entities (3+) participating in a joint venture or alliance.\n"- "- Capture non-binary group relations like cartels, industrial clusters, and regulatory coalitions.\n"- "- Define the shared goal of these groups clearly."-)--ECOSYSTEM_NODE_PROMPT = (- "You are a market analyst. Your task is to identify all participants (Nodes) within an industrial ecosystem.\n\n"- "Extraction Rules:\n"- "- Identify companies, NGOs, and regulatory bodies mentioned.\n"- "- Capture their market rank and primary technological focus area.\n"- "- Focus on naming actors that collaborate or compete as a group.\n"- "- DO NOT identify alliances, joint ventures, or consortia at this stage."-)--ECOSYSTEM_EDGE_PROMPT = (- "You are a market analyst. Given the industrial participants, extract the collective relationships (Hyperedges).\n\n"- "Extraction Rules:\n"- "- Group multiple participants (3+) into alliances, standard bodies, or joint ventures.\n"- "- Define the shared goal (e.g., 'R&D', 'Anti-monopoly Review') for the entire group.\n"- "- Record any mentioned governance structures or leading participants.\n"- "- Ensure every group member is selected from the provided participants list."-)--# ==============================================================================-# 3. Template Class-# ==============================================================================---class MarketEcosystemHyper(AutoHypergraph[IndustryParticipant, CollectiveAlliance]):- """- Hypergraph template for industrial clusters, ecosystem coalitions, and complex market alliances.- """-- 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,- ):- super().__init__(- node_schema=IndustryParticipant,- edge_schema=CollectiveAlliance,- node_key_extractor=lambda x: x.name.strip(),- edge_key_extractor=lambda x: x.alliance_id.strip(),- nodes_in_edge_extractor=lambda x: tuple(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=ECOSYSTEM_CONSOLIDATED_PROMPT,- prompt_for_node_extraction=ECOSYSTEM_NODE_PROMPT,- prompt_for_edge_extraction=ECOSYSTEM_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: IndustryParticipant) -> str:- return f"{ node.name }"-- def edge_label_extractor(edge: CollectiveAlliance) -> str:- return f"{ edge.alliance_id }"-- 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/business/equity.py b/hyperextract/templates/en/business/equity.pydeleted file mode 100644index 84109b0..0000000--- a/hyperextract/templates/en/business/equity.py+++ /dev/null@@ -1,156 +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 StakeholderNode(BaseModel):- """- A legal or natural person holding equity or control in a business.- """-- name: str = Field(- description="Full registry name of the company or individual's full name."- )- type: str = Field(- description="Type: 'Natural Person', 'Public Company', 'Private Company', 'State-Owned Enterprise', 'Venture Capital'."- )- jurisdiction: Optional[str] = Field(- None, description="Country or region of incorporation/residence."- )- is_ubo: bool = Field(- False,- description="Whether this entity is identified as an Ultimate Beneficial Owner.",- )---class OwnershipRelation(BaseModel):- """- A stakeholding or control link between two entities.- """-- source: str = Field(description="The shareholder or parent entity.")- target: str = Field(- description="The company being owned or controlled (subsidiary)."- )- stake_percentage: Optional[float] = Field(- None, description="Percentage of ownership (0.0 to 100.0)."- )- control_type: str = Field(- "Equity",- description="Nature of link: 'Equity Acquisition', 'Voting Rights', 'Nominee Shareholding', 'Direct Control'.",- )- as_of_date: Optional[str] = Field(- None, description="The date or fiscal period when this ownership was recorded."- )---# ==============================================================================-# 2. Prompts-# ==============================================================================--EQUITY_CONSOLIDATED_PROMPT = (- "You are a corporate paralegal and financial analyst. Extract complex ownership structures.\n\n"- "Rules:\n"- "- Prioritize identifying the percentage of shares held by each entity.\n"- "- Distinguish between direct shareholders and Ultimate Beneficial Owners (UBO).\n"- "- Map the hierarchy from the parent organization down to the smallest subsidiary."-)--EQUITY_NODE_PROMPT = (- "You are a corporate paralegal and financial analyst. Your task is to identify all stakeholders (Nodes) within a corporate structure.\n\n"- "Extraction Rules:\n"- "- Identify companies, investment funds, government bodies, and individual persons.\n"- "- Classify each as 'Natural Person', 'Public Company', 'Private Company', etc.\n"- "- Flag entities identified as Ultimate Beneficial Owners (UBO) where explicit.\n"- "- DO NOT extract ownership percentages or control links at this stage."-)--EQUITY_EDGE_PROMPT = (- "You are a corporate paralegal and financial analyst. Given the list of stakeholders, map the ownership and control relationships (Edges).\n\n"- "Extraction Rules:\n"- "- Extract the exact percentage of equity held between a shareholder (source) and a company (target).\n"- "- Specify the nature of control (e.g., Voting Rights, Direct Control, Nominee Shareholding).\n"- "- Create edges only between entities found in the provided stakeholder list.\n"- "- Capture the 'as of' date or historical period for the ownership record."-)--# ==============================================================================-# 3. Template Class-# ==============================================================================---class EquityStructureGraph(AutoGraph[StakeholderNode, OwnershipRelation]):- """- Precision template for corporate registries, M&A analysis, and KYC/UBO tracking.- """-- 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,- ):- super().__init__(- node_schema=StakeholderNode,- edge_schema=OwnershipRelation,- node_key_extractor=lambda x: x.name.strip(),- edge_key_extractor=lambda x: (- f"{x.source.strip()}->{x.target.strip()}_at_{x.stake_percentage}%"- ),- nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),- 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=EQUITY_CONSOLIDATED_PROMPT,- prompt_for_node_extraction=EQUITY_NODE_PROMPT,- prompt_for_edge_extraction=EQUITY_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: StakeholderNode) -> str:- info = f" ({ node.type })" if getattr(node, "type", None) else ""- return f"{ node.name }{info}"-- def edge_label_extractor(edge: OwnershipRelation) -> str:- return f"{edge.control_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/business/strategy.py b/hyperextract/templates/en/business/strategy.pydeleted file mode 100644index 8171d6a..0000000--- a/hyperextract/templates/en/business/strategy.py+++ /dev/null@@ -1,153 +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 AutoTemporalGraph--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================---class StrategicNode(BaseModel):- """- An organizational entity, business division, or strategic objective.- """-- name: str = Field(- description="Name of the strategic unit or goal (e.g., 'Azure', 'Carbon Neutrality')."- )- scope: str = Field(- description="Scope: 'Global', 'Regional', 'Product-specific', 'Corporate-wide'."- )- importance: Optional[str] = Field(- None, description="Criticality: 'Core Business', 'Emerging Market', 'Legacy'."- )---class StrategicPivot(BaseModel):- """- A temporal transition representing a change in strategic focus, investment, or divestiture.- """-- source: str = Field(description="The original area of focus or acting entity.")- target: str = Field(description="The new target, direction, or goal.")- action: str = Field(- description="Strategic action: 'Pivot to', 'Acquire', 'Divest', 'Merge', 'Sunset', 'Scale'."- )- timestamp: str = Field(- description="When the shift occurred (e.g., 'Q4 2022', '2025-01-01')."- )- rationale: Optional[str] = Field(- None,- description="The 'Why' behind the move (market pressure, CEO change, tech shift).",- )- budget: Optional[str] = Field(- None, description="Financial commitment mentioned alongside the pivot."- )---# ==============================================================================-# 2. Prompts-# ==============================================================================--STRATEGY_CONSOLIDATED_PROMPT = (- "You are a management consultant and industry analyst. Extract the evolution of corporate strategy.\n\n"- "Rules:\n"- "- Focus on 'Pivots': movements from one business area to another.\n"- "- Link specific actions to concrete timestamps.\n"- "- Capture the underlying reasoning (rationale) for each strategic change."-)--STRATEGY_NODE_PROMPT = (- "You are a management consultant. Your task is to identify strategic entities and objectives (Nodes).\n\n"- "Extraction Rules:\n"- "- Identify business divisions, specific products, and overarching corporate goals (e.g., 'Sustainability').\n"- "- Determine the scope and organizational importance of each unit.\n"- "- Focus on nouns and noun phrases representing strategic focus areas.\n"- "- DO NOT extract strategic moves or transitions at this stage."-)--STRATEGY_EDGE_PROMPT = (- "You are a management consultant. Given the identified strategic units, map the temporal shifts in strategy (Edges).\n\n"- "Extraction Rules:\n"- "- Extract 'Pivots' and actions like 'Acquire', 'Divest', or 'Sunset'.\n"- "- Link the source (old focus) to the target (new focus) with a precise timestamp.\n"- "- Capture the underlying rationale and any financial commitment (budget) mentioned.\n"- "- Only reference nodes present in the strategic units list."-)--# ==============================================================================-# 3. Template Class-# ==============================================================================---class StrategicChainGraph(AutoTemporalGraph[StrategicNode, StrategicPivot]):- """- Temporal template for tracking corporate strategy, longitudinal organizational change, and market shifts.- """-- 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,- ):- super().__init__(- node_schema=StrategicNode,- edge_schema=StrategicPivot,- node_key_extractor=lambda x: x.name.strip(),- edge_key_extractor=lambda x: (- f"{x.source.strip()}-({x.action})->{x.target.strip()}"- ),- time_in_edge_extractor=lambda x: x.timestamp.strip(),- nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),- 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=STRATEGY_CONSOLIDATED_PROMPT,- prompt_for_node_extraction=STRATEGY_NODE_PROMPT,- prompt_for_edge_extraction=STRATEGY_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: StrategicNode) -> str:- return f"{node.name}"-- def edge_label_extractor(edge: StrategicPivot) -> str:- return f"{edge.action}"-- 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/construction/__init__.py b/hyperextract/templates/en/construction/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/en/construction/project_timeline.py b/hyperextract/templates/en/construction/project_timeline.pydeleted file mode 100644index 247086a..0000000--- a/hyperextract/templates/en/construction/project_timeline.py+++ /dev/null@@ -1,185 +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 AutoTemporalGraph--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================---class MilestoneTaskNode(BaseModel):- """- A specific task, milestone, or phase in a construction project schedule.- """-- task_name: str = Field(- description="Operational name of the task (e.g., 'Foundation Pouring')."- )- phase: str = Field(- description="Project phase: 'Pre-con', 'Substructure', 'Superstructure', 'Fit-out', 'Commissioning'."- )- duration_estimate: Optional[str] = Field(- None, description="Estimated time required (e.g., '14 days', '2 months')."- )- responsible_party: Optional[str] = Field(- None, description="Subcontractor or team lead in charge."- )---class TemporalDependency(BaseModel):- """- A time-based link indicating task sequencing.- """-- source: str = Field(description="The predecessor task.")- target: str = Field(description="The successor task.")- timestamp: str = Field(- description="Temporal marker or sequence ID (e.g., 'Phase 1', 'Step 2', or a specific date/time)."- )- dependency_type: str = Field(- "Finish-to-Start",- description="Type: 'Finish-to-Start (FS)', 'Start-to-Start (SS)', 'Finish-to-Finish (FF)', 'Start-to-Finish (SF)'.",- )- lag_time: Optional[str] = Field(- None,- description="Wait time between tasks (e.g., '3 days for concrete curing').",- )---# ==============================================================================-# 2. Prompts-# ==============================================================================--CONSTRUCTION_TEMPORAL_CONSOLIDATED_PROMPT = (- "You are a Senior Project Planner and Scheduler (P6/MS Project expert). Extract the construction project timeline.\n\n"- "Rules:\n"- "- Identify granular tasks and major milestones as Nodes.\n"- "- Establish clear temporal dependencies (Edges) using industry-standard logic (FS, SS, etc.).\n"- "- Capture durations and curing/lag times where mentioned.\n"- "- Focus on the critical path and sequencing logic."-)--CONSTRUCTION_TEMPORAL_NODE_PROMPT = (- "Identify all tasks, scheduled activities, and project milestones.\n\n"- "Rules:\n"- "- Extract action-oriented task names.\n"- "- Group tasks into project phases and identify responsible parties.\n"- "- DO NOT identify sequences or dependencies yet."-)--CONSTRUCTION_TEMPORAL_EDGE_PROMPT = (- "Link construction tasks based on their logical sequence in time.\n\n"- "Rules:\n"- "- Define the predecessor and successor for each link.\n"- "- Classify the link type (FS is default if not specified).\n"- "- Identify any required lag times (e.g., waiting for inspection or drying).\n"- "- Only link tasks from the provided list."-)--# ==============================================================================-# 3. Template Class-# ==============================================================================---class ProjectSchedulingTimeline(- AutoTemporalGraph[MilestoneTaskNode, TemporalDependency]-):- """- Template for extracting project schedules and Critical Path Method (CPM) networks.-- Ideal for schedule risk analysis, delay tracking, and progress monitoring.-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> timeline = ProjectSchedulingTimeline(llm_client=llm, embedder=embedder)- >>> timeline.feed_text("Excavation must finish before the foundation slab can be poured.")- >>> print(timeline.nodes) # Access tasks and milestones- >>> print(timeline.edges) # Access temporal dependencies- """-- 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 Project Scheduling Timeline template.-- Args:- llm_client (BaseChatModel): The language model client used for schedule extraction.- embedder (Embeddings): The embedding model used for task and dependency deduplication.- extraction_mode (str, optional): 'one_stage' for joint extraction,- 'two_stage' for separate passes. Defaults to "one_stage".- chunk_size (int, optional): Maximum characters per text chunk. Defaults to 2048.- chunk_overlap (int, optional): Overlap between chunks. Defaults to 256.- max_workers (int, optional): Parallel processing workers. Defaults to 10.- verbose (bool, optional): If True, enables progress logging. Defaults to False.- **kwargs (Any): Additional parameters for the AutoTemporalGraph base class.- """- super().__init__(- node_schema=MilestoneTaskNode,- edge_schema=TemporalDependency,- node_key_extractor=lambda x: x.task_name.strip().lower(),- edge_key_extractor=lambda x: (- f"{x.source.strip().lower()}--[{x.dependency_type}]-->{x.target.strip().lower()}"- ),- nodes_in_edge_extractor=lambda x: (- x.source.strip().lower(),- x.target.strip().lower(),- ),- time_in_edge_extractor=lambda x: x.timestamp.strip(),- 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=CONSTRUCTION_TEMPORAL_CONSOLIDATED_PROMPT,- prompt_for_node_extraction=CONSTRUCTION_TEMPORAL_NODE_PROMPT,- prompt_for_edge_extraction=CONSTRUCTION_TEMPORAL_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: MilestoneTaskNode) -> str:- info = f" ({node.phase})" if getattr(node, "phase", None) else ""- return f"{node.task_name}{info}"-- def edge_label_extractor(edge: TemporalDependency) -> 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/construction/resource_registry.py b/hyperextract/templates/en/construction/resource_registry.pydeleted file mode 100644index 8d23f05..0000000--- a/hyperextract/templates/en/construction/resource_registry.py+++ /dev/null@@ -1,108 +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 AutoSet--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================--class ConstructionResource(BaseModel):- """- A specific asset, material, or labor category assigned to a construction project.- """- resource_name: str = Field(description="Name of the resource (e.g., 'Tower Crane TC-01', 'Fly Ash Concrete').")- category: str = Field(description="Category: 'Heavy Machinery', 'Bulk Material', 'Skilled Labor', 'Fixed Equipment', 'Consumables'.")- quantity: Optional[str] = Field(None, description="Current quantity or capacity on site.")- supplier_or_team: Optional[str] = Field(None, description="The entity providing or managing this resource.")- status: str = Field("Active", description="Current operational status: 'Active', 'Idle', 'Maintenance', 'Depleted'.")--# ==============================================================================-# 2. Prompts-# ==============================================================================--CONSTRUCTION_RESOURCE_PROMPT = (- "You are a Construction Logistics and Procurement Manager. Extract all project resources and assets.\n\n"- "Rules:\n"- "- Identify machinery, materials, and labor types.\n"- "- Capture specific quantities and supplier names if mentioned.\n"- "- Deduplicate similar items (e.g., 'Excavator A' and 'The primary excavator' should be merged if referring to the same unit)."-)--# ==============================================================================-# 3. Template Class-# ==============================================================================--class ResourceRegistrySet(AutoSet[ConstructionResource]):- """- Template for managing a consolidated site asset and material registry.-- Uses AutoSet for automatic deduplication and merging of multi-chunk resource mentions.-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> registry = ResourceRegistrySet(llm_client=llm, embedder=embedder)- >>> registry.feed_text("We have two 50-ton cranes from Liebherr on site.")- >>> registry.feed_text("The Liebherr cranes are currently being serviced.")- >>> print(registry.items) # Mentions will be merged into a single Tower Crane resource.- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- *,- chunk_size: int = 2048,- chunk_overlap: int = 256,- max_workers: int = 10,- verbose: bool = False,- **kwargs: Any,- ):- """- Initialize the Resource Registry Set template.-- Args:- llm_client (BaseChatModel): The language model client used for resource extraction.- embedder (Embeddings): The embedding model used for resource deduplication.- chunk_size (int, optional): Maximum characters per text chunk. Defaults to 2048.- chunk_overlap (int, optional): Overlap between chunks. Defaults to 256.- max_workers (int, optional): Parallel processing workers. Defaults to 10.- verbose (bool, optional): If True, enables progress logging. Defaults to False.- **kwargs (Any): Additional parameters for the AutoSet base class.- """- super().__init__(- item_schema=ConstructionResource,- key_extractor=lambda x: x.resource_name.strip().lower(),- llm_client=llm_client,- embedder=embedder,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- max_workers=max_workers,- verbose=verbose,- prompt=CONSTRUCTION_RESOURCE_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: ConstructionResource) -> str:- info = f" ({ item.category })" if getattr(item, "category", None) else ""- return f"{ item.resource_name }{info}"-- 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/construction/site_topology.py b/hyperextract/templates/en/construction/site_topology.pydeleted file mode 100644index b17b294..0000000--- a/hyperextract/templates/en/construction/site_topology.py+++ /dev/null@@ -1,180 +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 AutoSpatialGraph--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================---class PhysicalElementNode(BaseModel):- """- A specific physical component or zone within a construction site.- """-- name: str = Field(- description="Unique identifier or name of the element (e.g., 'Column-A1', 'Zone-B')."- )- element_type: str = Field(- description="Type: 'Structural', 'MEP', 'Architectural', 'Temporary Structure', 'Safety Zone'."- )- location_coordinates: Optional[str] = Field(- None,- description="Spatial coordinates or relative grid location (e.g., 'X:10, Y:20, Z:5').",- )- material_properties: Optional[str] = Field(- None, description="Key material info (e.g., 'C30 Concrete', 'Steel S355')."- )---class SpatialRelation(BaseModel):- """- A spatial or topological connection between two physical elements.- """-- source: str = Field(description="The reference element.")- target: str = Field(description="The related element.")- location_marker: str = Field(- description="The physical location or zone where this relationship resides (e.g., 'Level 3', 'North Wing', 'Grid A-1')."- )- relation_type: str = Field(- description="Type: 'Supporting', 'Adjacent', 'Enclosed By', 'Intersects', 'Aligned With'."- )- offset_distance: Optional[float] = Field(- None, description="Physical distance between elements in meters."- )---# ==============================================================================-# 2. Prompts-# ==============================================================================--CONSTRUCTION_SPATIAL_CONSOLIDATED_PROMPT = (- "You are a Senior BIM (Building Information Modeling) Engineer and Site Surveyor. Extract the spatial topology of the construction project.\n\n"- "Rules:\n"- "- Identify fixed physical elements and their properties as Nodes.\n"- "- Map the structural and spatial relationships (Edges) between these elements.\n"- "- Ensure coordinates and distances are captured if mentioned.\n"- "- Focus on how objects are physically connected or positioned relative to each other."-)--CONSTRUCTION_SPATIAL_NODE_PROMPT = (- "Identify all physical building components and site zones.\n\n"- "Rules:\n"- "- Extract distinct structural, mechanical, or architectural elements.\n"- "- Capture any mentioned locations, levels, or material information.\n"- "- DO NOT identify connections at this stage."-)--CONSTRUCTION_SPATIAL_EDGE_PROMPT = (- "Map the spatial and structural relationships between the identified building elements.\n\n"- "Rules:\n"- "- Determine how Element A relates to Element B (e.g., A supports B, A is adjacent to B).\n"- "- Extract physical offsets or distances if provided.\n"- "- Only link elements from the provided list."-)--# ==============================================================================-# 3. Template Class-# ==============================================================================---class SiteTopologyGraph(AutoSpatialGraph[PhysicalElementNode, SpatialRelation]):- """- Template for building a spatial digital twin of a construction site.-- Useful for structural analysis, BIM-to-Graph conversion, and site logistics planning.-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> graph = SiteTopologyGraph(llm_client=llm, embedder=embedder)- >>> graph.feed_text("The foundation slab supports the four main corner columns.")- >>> print(graph.nodes) # Access structural elements- >>> print(graph.edges) # Access spatial relationships- """-- 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 Site Topology Graph template.-- Args:- llm_client (BaseChatModel): The language model client used for topology extraction.- embedder (Embeddings): The embedding model used for element deduplication.- extraction_mode (str, optional): 'one_stage' for joint extraction,- 'two_stage' for separate passes. Defaults to "one_stage".- chunk_size (int, optional): Maximum characters per text chunk. Defaults to 2048.- chunk_overlap (int, optional): Overlap between chunks. Defaults to 256.- max_workers (int, optional): Parallel processing workers. Defaults to 10.- verbose (bool, optional): If True, enables progress logging. Defaults to False.- **kwargs (Any): Additional parameters for the AutoSpatialGraph base class.- """- super().__init__(- node_schema=PhysicalElementNode,- edge_schema=SpatialRelation,- node_key_extractor=lambda x: x.name.strip().lower(),- edge_key_extractor=lambda x: (- f"{x.source.strip().lower()}--{x.relation_type.lower()}--{x.target.strip().lower()}"- ),- nodes_in_edge_extractor=lambda x: (- x.source.strip().lower(),- x.target.strip().lower(),- ),- location_in_edge_extractor=lambda x: x.location_marker.strip(),- 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=CONSTRUCTION_SPATIAL_CONSOLIDATED_PROMPT,- prompt_for_node_extraction=CONSTRUCTION_SPATIAL_NODE_PROMPT,- prompt_for_edge_extraction=CONSTRUCTION_SPATIAL_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: PhysicalElementNode) -> str:- return f"{node.name}"-- def edge_label_extractor(edge: SpatialRelation) -> str:- return f"{edge.relation_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/cybersecurity/__init__.py b/hyperextract/templates/en/cybersecurity/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/en/cybersecurity/intrusion_kill_chain.py b/hyperextract/templates/en/cybersecurity/intrusion_kill_chain.pydeleted file mode 100644index d69cf63..0000000--- a/hyperextract/templates/en/cybersecurity/intrusion_kill_chain.py+++ /dev/null@@ -1,179 +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 AutoGraph--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================---class AttackStageNode(BaseModel):- """- A specific phase or action in a cyber attack (aligned with MITRE ATT&CK or Lockheed Kill Chain).- """-- stage_name: str = Field(- description="Name of the attack stage (e.g., 'Initial Access', 'Lateral Movement')."- )- tactics_used: List[str] = Field(- default_factory=list,- description="Specific techniques or tactics employed (e.g., 'Phishing', 'Pass-the-Hash').",- )- adversary_tools: List[str] = Field(- default_factory=list,- description="Malware or tools used in this stage (e.g., 'Cobalt Strike', 'Mimikatz').",- )- timestamp: Optional[str] = Field(- None, description="Time or sequence marker for the action."- )---class KillChainLink(BaseModel):- """- A directional link representing the progression of an attack from one stage to another.- """-- source: str = Field(description="The preceding attack stage.")- target: str = Field(description="The succeeding attack stage.")- causality: str = Field(- "Progression",- description="Type: 'Progression' (standard), 'Triggered' (automatic), 'Pivoted' (infrastructure shift).",- )- observables: List[str] = Field(- default_factory=list,- description="IOCs (Indicators of Compromise) linking the stages.",- )---# ==============================================================================-# 2. Prompts-# ==============================================================================--CYBER_KILL_CHAIN_CONSOLIDATED_PROMPT = (- "You are a Forensic Investigator and Incident Responder. Reconstruct the attack timeline and kill chain from incident reports.\n\n"- "Rules:\n"- "- Identify distinct attack stages as Nodes.\n"- "- Map the chronological and logical progression (Edges) of the intrusion.\n"- "- Capture specific tactics, tools (TTPs), and timestamps for each stage.\n"- "- Focus on the 'how' and 'when' of the adversary's movement."-)--CYBER_KILL_CHAIN_NODE_PROMPT = (- "Identify all suspicious activities and distinct phases of a cyber intrusion.\n\n"- "Rules:\n"- "- Extract action-oriented stages (e.g., 'Delivery of Payload', 'C2 Establishment').\n"- "- Identify the tools and techniques associated with each discovery.\n"- "- DO NOT link the stages yet."-)--CYBER_KILL_CHAIN_EDGE_PROMPT = (- "Establish the sequence and progression between identified attack stages.\n\n"- "Rules:\n"- "- Define which stage led to or enabled the next.\n"- "- Identify Indicators of Compromise (IPs, Hashes) that connect the stages.\n"- "- Only link stages from the provided list."-)--# ==============================================================================-# 3. Template Class-# ==============================================================================---class IntrusionKillChainGraph(AutoGraph[AttackStageNode, KillChainLink]):- """- Template for reconstructing cyber attack lifecycles.-- Useful for incident response (IR), forensic reporting, and threat hunting.-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> kill_chain = IntrusionKillChainGraph(llm_client=llm, embedder=embedder)- >>> kill_chain.feed_text("The attacker gained initial access via a phishing email.")- >>> print(kill_chain.nodes) # Access attack stages- >>> print(kill_chain.edges) # Access progression links- """-- 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 Intrusion Kill Chain Graph template.-- Args:- llm_client (BaseChatModel): The language model client used for kill chain extraction.- embedder (Embeddings): The embedding model used for stage deduplication.- extraction_mode (str, optional): 'one_stage' for joint extraction,- 'two_stage' for separate passes. Defaults to "one_stage".- chunk_size (int, optional): Maximum characters per text chunk. Defaults to 2048.- chunk_overlap (int, optional): Overlap between chunks. Defaults to 256.- max_workers (int, optional): Parallel processing workers. Defaults to 10.- verbose (bool, optional): If True, enables progress logging. Defaults to False.- **kwargs (Any): Additional parameters for the AutoGraph base class.- """- super().__init__(- node_schema=AttackStageNode,- edge_schema=KillChainLink,- node_key_extractor=lambda x: x.stage_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=CYBER_KILL_CHAIN_CONSOLIDATED_PROMPT,- prompt_for_node_extraction=CYBER_KILL_CHAIN_NODE_PROMPT,- prompt_for_edge_extraction=CYBER_KILL_CHAIN_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: AttackStageNode) -> str:- return f"{node.stage_name}"-- def edge_label_extractor(edge: KillChainLink) -> str:- return f"{edge.causality}"-- 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/cybersecurity/threat_intelligence_nexus.py b/hyperextract/templates/en/cybersecurity/threat_intelligence_nexus.pydeleted file mode 100644index 2c28541..0000000--- a/hyperextract/templates/en/cybersecurity/threat_intelligence_nexus.py+++ /dev/null@@ -1,181 +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 AutoHypergraph--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================---class ThreatActorNode(BaseModel):- """- An entity (individual, group, or nation-state) responsible for cyber threats.- """-- actor_name: str = Field(- description="Alias or group name (e.g., 'APT28', 'Fancy Bear', 'Lazarus Group')."- )- origin_country: Optional[str] = Field(- None, description="Suspected geographic origin."- )- motivation: Optional[str] = Field(- None,- description="Primary driver: 'Espionage', 'Financial Gain', 'Sabotage', 'Hacktivism'.",- )- typical_targets: List[str] = Field(- default_factory=list, description="Commonly targeted industries or regions."- )---class IntelligenceNexus(BaseModel):- """- A hyperedge connecting an actor, specific infrastructure, and a campaign theme.- """-- participants: List[str] = Field(- description="Entities involved: Actor names, Tool names, Infrastructure (IPs/Domains), Target Organizations."- )- campaign_name: str = Field(- description="Known name of the operation (e.g., 'SolarWinds Supply Chain Attack')."- )- shared_ttp: str = Field(- description="The common tactic, technique, or procedure that links these disparate entities."- )- confidence_level: str = Field(- "Medium", description="Analytical confidence: 'High', 'Medium', 'Low'."- )---# ==============================================================================-# 2. Prompts-# ==============================================================================--CYBER_NEXUS_CONSOLIDATED_PROMPT = (- "You are a Strategic Threat Intelligence Analyst. Map the high-level correlations between actors, infrastructure, and infrastructure.\n\n"- "Rules:\n"- "- Identify threat actors and their aliases as Nodes.\n"- "- Create Hyperedges (Nexuses) that link actors to specific tools and infrastructure under a named campaign.\n"- "- Focus on multi-point connections that reveal a cohesive operation rather than simple binary links.\n"- "- Highlight shared TTPs that unify the nexus."-)--CYBER_NEXUS_NODE_PROMPT = (- "Identify threat actors, malware families, and malicious infrastructure entities.\n\n"- "Rules:\n"- "- Extract actor aliases and group names.\n"- "- Identify motivations and target industries.\n"- "- DO NOT identify campaigns or relations yet."-)--CYBER_NEXUS_EDGE_PROMPT = (- "Identify the operational Campaigns or Nexuses that unify actors, tools, and targets.\n\n"- "Rules:\n"- "- Each hyperedge must describe a single campaign or operation.\n"- "- Link the actor(s) to the specific infrastructure and tools used in that operation.\n"- "- Only link entities from the provided list."-)--# ==============================================================================-# 3. Template Class-# ==============================================================================---class ThreatIntelligenceNexusHypergraph(- AutoHypergraph[ThreatActorNode, IntelligenceNexus]-):- """- Template for strategic threat intelligence mapping.-- Ideal for connecting dots between infrastructure, actors, and malware in complex campaigns.-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> nexus = ThreatIntelligenceNexusHypergraph(llm_client=llm, embedder=embedder)- >>> nexus.feed_text("APT28 utilized X-Tunnel and C2 at 1.2.3.4 during Operation Fancy-Phish.")- >>> print(nexus.nodes) # Access threat actors- >>> print(nexus.edges) # Access campaign hyperedges- """-- 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 Threat Intelligence Nexus Hypergraph template.-- Args:- llm_client (BaseChatModel): The language model client used for nexus extraction.- embedder (Embeddings): The embedding model used for actor deduplication.- extraction_mode (str, optional): 'one_stage' for joint extraction,- 'two_stage' for separate passes. Defaults to "one_stage".- chunk_size (int, optional): Maximum characters per text chunk. Defaults to 2048.- chunk_overlap (int, optional): Overlap between chunks. Defaults to 256.- max_workers (int, optional): Parallel processing workers. Defaults to 10.- verbose (bool, optional): If True, enables progress logging. Defaults to False.- **kwargs (Any): Additional parameters for the AutoHypergraph base class.- """- super().__init__(- node_schema=ThreatActorNode,- edge_schema=IntelligenceNexus,- node_key_extractor=lambda x: x.actor_name.strip().lower(),- edge_key_extractor=lambda x: (- f"{x.campaign_name.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=CYBER_NEXUS_CONSOLIDATED_PROMPT,- prompt_for_node_extraction=CYBER_NEXUS_NODE_PROMPT,- prompt_for_edge_extraction=CYBER_NEXUS_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: ThreatActorNode) -> str:- return f"{node.actor_name}"-- def edge_label_extractor(edge: IntelligenceNexus) -> str:- return f"{edge.campaign_name}"-- 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/cybersecurity/vulnerability_catalog.py b/hyperextract/templates/en/cybersecurity/vulnerability_catalog.pydeleted file mode 100644index cbb6616..0000000--- a/hyperextract/templates/en/cybersecurity/vulnerability_catalog.py+++ /dev/null@@ -1,123 +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 VulnerabilityEntry(BaseModel):- """- A specific security vulnerability or weakness identified in a system or software.- """-- vulnerability_id: str = Field(- description="Unique identifier (e.g., CVE-2023-1234, CWE-79)."- )- title: str = Field(description="Short descriptive name of the vulnerability.")- severity: str = Field(- description="Severity rating: 'Critical', 'High', 'Medium', 'Low', 'Informational'."- )- cvss_score: Optional[float] = Field(- None, description="CVSS base score (0.0 to 10.0)."- )- affected_components: List[str] = Field(- default_factory=list, description="Software or hardware components impacted."- )- remediation: Optional[str] = Field(- None, description="Recommended fix or mitigation steps."- )---# ==============================================================================-# 2. Prompts-# ==============================================================================--CYBER_VULN_PROMPT = (- "You are a Senior Security Analyst and Vulnerability Researcher. Extract and consolidate security vulnerabilities from threat reports, advisories, or scan results.\n\n"- "Rules:\n"- "- Identify unique vulnerabilities by their CVE/CWE ID or title.\n"- "- Capture severity levels and CVSS scores accurately.\n"- "- Merge duplicate mentions of the same vulnerability into a single entry, combining information about affected components and remediation."-)--# ==============================================================================-# 3. Template Class-# ==============================================================================---class VulnerabilityUnifiedCatalog(AutoSet[VulnerabilityEntry]):- """- Template for building a deduplicated catalog of security vulnerabilities.-- Ideal for processing multiple security advisories and creating a master list for patching.-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> catalog = VulnerabilityUnifiedCatalog(llm_client=llm, embedder=embedder)- >>> catalog.feed_text("CVE-2024-0001 is a critical RCE in the kernel.")- >>> catalog.feed_text("The kernel RCE (CVE-2024-0001) requires an immediate patch.")- >>> print(catalog.items) # Duplicate entries for CVE-2024-0001 will be merged- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- *,- chunk_size: int = 2048,- chunk_overlap: int = 256,- max_workers: int = 10,- verbose: bool = False,- **kwargs: Any,- ):- """- Initialize the Vulnerability Unified Catalog template.-- Args:- llm_client (BaseChatModel): The language model client used for vulnerability extraction.- embedder (Embeddings): The embedding model used for entry deduplication.- chunk_size (int, optional): Maximum characters per text chunk. Defaults to 2048.- chunk_overlap (int, optional): Overlap between chunks. Defaults to 256.- max_workers (int, optional): Parallel processing workers. Defaults to 10.- verbose (bool, optional): If True, enables progress logging. Defaults to False.- **kwargs (Any): Additional parameters for the AutoSet base class.- """- super().__init__(- item_schema=VulnerabilityEntry,- key_extractor=lambda x: x.vulnerability_id.strip().upper(),- llm_client=llm_client,- embedder=embedder,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- max_workers=max_workers,- verbose=verbose,- prompt=CYBER_VULN_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: VulnerabilityEntry) -> str:- return f"{item.title}"-- 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/fashion/__init__.py b/hyperextract/templates/en/fashion/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/en/marketing/__init__.py b/hyperextract/templates/en/marketing/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/en/music/__init__.py b/hyperextract/templates/en/music/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/en/politics/__init__.py b/hyperextract/templates/en/politics/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/en/real_estate/__init__.py b/hyperextract/templates/en/real_estate/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/en/recruitment/__init__.py b/hyperextract/templates/en/recruitment/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/en/software/__init__.py b/hyperextract/templates/en/software/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/en/sports/__init__.py b/hyperextract/templates/en/sports/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/en/supply_chain/__init__.py b/hyperextract/templates/en/supply_chain/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/en/travel/__init__.py b/hyperextract/templates/en/travel/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/zh/README.md b/hyperextract/templates/zh/README.mdindex c634969..2c4ce32 100644--- a/hyperextract/templates/zh/README.md+++ b/hyperextract/templates/zh/README.md@@ -11,41 +11,26 @@| 目录名称 | 说明 | 应用场景示例 || :--- | :--- | :--- |-| **`tcm`** | **中医 (特色)** | 中草药方剂、经络穴位、辨证施治过程等。 |-| **`wuxia`** | **武侠/修真 (特色)** | 门派恩怨、功法境界、修仙等级体系、法宝神兵。 || **`general`** | 通用百科 | 人物、机构、事件、地点等基础实体的快速抽取。 || **`finance`** | 金融投资 | A股/港股研报、基金招募说明书、上市公司季报。 || **`legal`** | 法律合规 | 合同关键要素(义务、权利)、案情调查、法条引用。 || **`education`** | 教育学术 | K12知识点图谱、课程大纲依赖关系、学术论文脉络。 |-| **`business`** | 商业通用 | 公司全画像、股权穿透结构、商业战略目标。 || **`medicine`** | 医学健康 | 疾病症状映射、临床诊疗路径、西药说明书结构化。 || **`food`** | 美食餐饮 | 中餐菜谱(刀工、火候)、食材配比、八大菜系特征。 || **`history`** | 历史文化 | 朝代更迭时间线、重大战役、历史人物生平关系。 || **`literature`** | 文学 | 小说人物关系网、文学流派演变、古诗词意象关联。 |-| **`software`** | 软件与IT | 系统架构图、接口定义、代码依赖关系、DevOps流程。 || **`game`** | 游戏娱乐 | 游戏世界观设定、任务流向树、物品合成与掉落表。 |-| **`sports`** | 体育竞技 | 赛事文字直播提取、球员身价与转会网络、战术阵型。 |-| **`travel`** | 旅游出行 | 游记攻略结构化、景点关系图、旅行行程规划。 |-| **`recruitment`**| 招聘简历 | 简历经历解析、技能标签映射、岗位/人才画像匹配。 |-| **`marketing`** | 市场营销 | 用户旅程地图 (CJM)、品牌定位分析、营销活动链路。 |-| **`supply_chain`**| 物流/供应链 | 供应链上下游追溯、物流节点关系、库存流转图。 || **`agriculture`** | 农业与养殖 | 作物生长周期、病虫害防治、畜牧谱系与饲养标准。 |-| **`art`** | 艺术与博物馆 | 艺术品流传有序图、艺术流派、博物馆馆藏关系。 |-| **`automotive`** | 汽车工业 | 汽车参数配置、维保手册提取、零部件组成。 || **`biology`** | 生物科学 | 生物分类学、蛋白质相互作用、基因调控网络。 || **`chemistry`** | 化学科学 | 分子结构、化学反应方程式路径、材料物化特性。 || **`physics`** | 物理与天文 | 天体运行系统、量子物理现象、电路逻辑连接图。 |-| **`construction`**| 建筑工程 | 建筑信息模型 (BIM) 实体、施工进度节点、材料明细。 |-| **`cybersecurity`**| 网络安全 | 攻击路径图、威胁情报 STIX 模型、系统漏洞分析。 || **`environment`** | 环境与气候 | 气象变化趋势、碳排放追踪、生态系统食物网。 |-| **`fashion`** | 时尚设计 | 时装系列设计元素、流行趋势周期、单品构成。 || **`movie`** | 影视 | 剧本节拍器拆解、演员与幕后人员网络、影评情感。 |-| **`music`** | 音乐 | 乐理结构、专辑曲目分类、流派演进。 || **`news`** | 新闻传媒 | 事件因果链、新闻专题聚类、深度报道事实板。 |-| **`politics`** | 政治与政府 | 政策影响分析、地缘政治关系网、选举数据地图。 |-| **`real_estate`** | 房地产 | 房源户型特征、租赁协议要素、土地规划关系。 |+| **`tcm`** | **中医 (特色)** | 中草药方剂、经络穴位、辨证施治过程等。 |+| **`wuxia`** | **武侠/修真 (特色)** | 门派恩怨、功法境界、修仙等级体系、法宝神兵。 |-*(注:英文版对应的 31 个通用领域在中文版中均有映射文件夹,中医与武侠为中文版独有)*+*(注:英文版对应的 16 个通用领域在中文版中均有映射文件夹,中医与武侠为中文版独有)*## 快速上手```pythondiff --git a/hyperextract/templates/zh/__init__.py b/hyperextract/templates/zh/__init__.pyindex ada7ed1..db5ed8b 100644--- a/hyperextract/templates/zh/__init__.py+++ b/hyperextract/templates/zh/__init__.py@@ -2,20 +2,10 @@ from .general.knowledge_graph import KnowledgeGraphfrom .general.concept_map import ConceptMapfrom .general.logic_graph import LogicGraphfrom .agriculture.crop import CropStatusGraph-from .agriculture.supply_chain import AgriSupplyChainGraphfrom .agriculture.soil import SoilNutritionGraph-from .art.history import ArtHistoryGraph-from .art.style import ArtStyleGraph-from .art.exhibition import ExhibitionGraph-from .automotive.vehicle import VehicleSpecGraph-from .automotive.diagnosis import VehicleDiagnosisGraph-from .automotive.market import AutoMarketGraphfrom .biology.taxonomy import TaxonomyGraphfrom .biology.network import BiologicalNetworkfrom .biology.metabolic import MetabolicHypergraph-from .business.equity import EquityStructureGraph-from .business.strategy import StrategicChainGraph-from .business.ecosystem import MarketEcosystemHyperfrom .chemistry.molecular import MolecularStructureGraphfrom .chemistry.reaction import ChemicalReactionHyperfrom .chemistry.protocol import LabProtocolTemporal@@ -25,20 +15,10 @@ __all__ = ["ConceptMap","LogicGraph","CropStatusGraph",- "AgriSupplyChainGraph","SoilNutritionGraph",- "ArtHistoryGraph",- "ArtStyleGraph",- "ExhibitionGraph",- "VehicleSpecGraph",- "VehicleDiagnosisGraph",- "AutoMarketGraph","TaxonomyGraph","BiologicalNetwork","MetabolicHypergraph",- "EquityStructureGraph",- "StrategicChainGraph",- "MarketEcosystemHyper","MolecularStructureGraph","ChemicalReactionHyper","LabProtocolTemporal",diff --git a/hyperextract/templates/zh/art/__init__.py b/hyperextract/templates/zh/art/__init__.pydeleted file mode 100644index 96cb725..0000000--- a/hyperextract/templates/zh/art/__init__.py+++ /dev/null@@ -1,9 +0,0 @@-from .provenance import ProvenanceGraph-from .movement import ArtMovementGraph-from .exhibition import ExhibitionGraph--__all__ = [- "ProvenanceGraph",- "ArtMovementGraph",- "ExhibitionGraph",-]diff --git a/hyperextract/templates/zh/art/exhibition.py b/hyperextract/templates/zh/art/exhibition.pydeleted file mode 100644index 6000d8c..0000000--- a/hyperextract/templates/zh/art/exhibition.py+++ /dev/null@@ -1,152 +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 ExhibitionEntity(BaseModel):- """艺术展览的组成要素(策展人、主题、作品、场馆、赞助商)。"""-- name: str = Field(description="展览名称、艺术家姓名或策展人姓名。")- type: str = Field(- description="类型:'展览'、'主题'、'艺术品'、'策展人'、'场馆'、'合作伙伴'。"- )- details: Optional[str] = Field(description="展览日期、理念说明或地理位置。")---class ExhibitionRelation(BaseModel):- """展览策划与执行中的连接关系。"""-- source: str = Field(description="组织或控制实体。")- target: str = Field(description="相关的作品 or 参与者。")- relation_type: str = Field(- description="类型:'策展自'、'参展于'、'举办于'、'赞助自'、'主题关联至'。"- )- context: Optional[str] = Field(description="具体展厅、借展条件或主题子组。")---# ==============================================================================-# 2. 提示词 (Prompts)-# ==============================================================================--EXHIBITION_GRAPH_PROMPT = (- "你是一位博物馆馆长和展览设计师。请映射艺术展览的结构图谱。\n\n"- "准则:\n"- "- 识别展览名称、核心主题以及参展的艺术家和作品。\n"- "- 将作品连接到其所属的主题板块以及负责的策展人。\n"- "- 捕捉场馆和赞助商等物流信息。"-)--EXHIBITION_NODE_PROMPT = (- "提取展览组件:展览名称、场馆、主题、具体艺术品以及关键人员(策展人、设计师)。"-)--EXHIBITION_EDGE_PROMPT = (- "连接展览内的各项内容。展示哪些作品属于哪个主题,并识别举办场馆和赞助商。"-)--# ==============================================================================-# 3. 模板类-# ==============================================================================---class ExhibitionGraph(AutoGraph[ExhibitionEntity, ExhibitionRelation]):- """- 展览策划图谱模板,用于策划筹备和展览分析。-- 追踪艺术品、主题、策展人和场馆之间的关系。-- 示例:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> llm = ChatOpenAI()- >>> embedder = OpenAIEmbeddings()- >>> graph = ExhibitionGraph(llm_client=llm, embedder=embedder)- >>> text = "'超现实之梦'展览由 Alice Smith 在泰特现代美术馆策划。"- >>> graph.feed_text(text)- >>> print(graph.edges) # 展览关联信息- """-- 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,- ):- """- 初始化展览策划图谱模板。-- Args:- llm_client: 语言模型客户端。- embedder: 嵌入模型。- extraction_mode: 提取模式,"one_stage" 或 "two_stage"。- chunk_size: 分块大小。- chunk_overlap: 分块重叠大小。- max_workers: 最大并行工作线程数。- verbose: 是否开启详细日志。- **kwargs: 传递给 AutoGraph 的额外参数。- """- super().__init__(- node_schema=ExhibitionEntity,- edge_schema=ExhibitionRelation,- node_key_extractor=lambda x: x.name.strip(),- edge_key_extractor=lambda x: (- f"{x.source.strip()}--({x.relation_type.lower()})-->{x.target.strip()}"- ),- nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),- 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=EXHIBITION_GRAPH_PROMPT,- prompt_for_node_extraction=EXHIBITION_NODE_PROMPT,- prompt_for_edge_extraction=EXHIBITION_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: ExhibitionEntity) -> str:- info = f" ({node.type})" if getattr(node, "type", None) else ""- return f"{node.name}{info}"-- def edge_label_extractor(edge: ExhibitionRelation) -> str:- return f"{edge.relation_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/art/movement.py b/hyperextract/templates/zh/art/movement.pydeleted file mode 100644index 8def0cd..0000000--- a/hyperextract/templates/zh/art/movement.py+++ /dev/null@@ -1,150 +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 MovementEntity(BaseModel):- """艺术流派、风格、艺术家或具有影响力的作品。"""-- name: str = Field(description="流派名称(如:印象派)或艺术家姓名。")- category: str = Field(- description="类别:'流派'、'风格'、'艺术家'、'宣言'、'代表作'。"- )- attributes: Optional[str] = Field(description="核心特征、常用媒介或流行时期。")---class ArtInfluenceEdge(BaseModel):- """艺术史中的影响、衍生或成员关系。"""-- source: str = Field(description="前驱流派 or 影响源。")- target: str = Field(description="后继流派、具体作品或艺术家。")- relation: str = Field(- description="关系:'影响了'、'创始人'、'成员'、'是对...的反叛'、'衍生自'。"- )- details: Optional[str] = Field(description="具体的风格技巧传承或历史事件。")---# ==============================================================================-# 2. 提示词 (Prompts)-# ==============================================================================--MOVEMENT_GRAPH_PROMPT = (- "你是一位专门研究艺术风格演变的艺术史学家。请提取艺术流派及其相互影响的图谱。\n\n"- "准则:\n"- "- 识别不同的艺术流派以及与之相关的艺术家。\n"- "- 映射流派之间的演进关系(例如:后印象派对印象派的反思与继承)。\n"- "- 捕捉宣言或作品中定义的各种核心哲学和视觉特征。"-)--MOVEMENT_NODE_PROMPT = (- "提取艺术流派、风格、相关艺术家及关键作品。描述其视觉语言和核心理论。"-)--MOVEMENT_EDGE_PROMPT = "定义流派与个人之间的联系。使用诸如'是对...的反叛'或'影响了'等关系词。记录代际之间传递的具体技法。"--# ==============================================================================-# 3. 模板类-# ==============================================================================---class ArtMovementGraph(AutoGraph[MovementEntity, ArtInfluenceEdge]):- """- 艺术流派图谱模板,用于映射艺术风格、流派影响力和艺术家所属流派。-- 适用于教学应用和艺术史深度分析。-- 示例:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> llm = ChatOpenAI()- >>> embedder = OpenAIEmbeddings()- >>> graph = ArtMovementGraph(llm_client=llm, embedder=embedder)- >>> text = "以莫奈为首的印象派,后来受到了后印象派结构化方法的挑战。"- >>> graph.feed_text(text)- >>> 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,- ):- """- 初始化艺术流派图谱模板。-- Args:- llm_client: 语言模型客户端。- embedder: 嵌入模型。- extraction_mode: 提取模式,"one_stage" 或 "two_stage"。- chunk_size: 分块大小。- chunk_overlap: 分块重叠大小。- max_workers: 最大并行工作线程数。- verbose: 是否开启详细日志。- **kwargs: 传递给 AutoGraph 的额外参数。- """- super().__init__(- node_schema=MovementEntity,- edge_schema=ArtInfluenceEdge,- node_key_extractor=lambda x: x.name.strip(),- edge_key_extractor=lambda x: (- f"{x.source.strip()}--({x.relation.lower()})-->{x.target.strip()}"- ),- nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),- 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=MOVEMENT_GRAPH_PROMPT,- prompt_for_node_extraction=MOVEMENT_NODE_PROMPT,- prompt_for_edge_extraction=MOVEMENT_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: MovementEntity) -> str:- info = f" ({node.category})" if getattr(node, "category", None) else ""- return f"{node.name}{info}"-- def edge_label_extractor(edge: ArtInfluenceEdge) -> str:- return f"{edge.relation}"-- 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/art/provenance.py b/hyperextract/templates/zh/art/provenance.pydeleted file mode 100644index 8380239..0000000--- a/hyperextract/templates/zh/art/provenance.py+++ /dev/null@@ -1,148 +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 ArtEntity(BaseModel):- """艺术领域实体(如:作品、艺术家、博物馆、私人收藏家、拍卖行)。"""-- name: str = Field(description="艺术品名称、人物姓名或机构名称。")- category: str = Field(- description="类别:'艺术品'、'艺术家'、'收藏家'、'机构'、'地理位置'。"- )- description: Optional[str] = Field(description="材质、创作日期或历史地位描述。")---class ProvenanceEdge(BaseModel):- """艺术品的所有权或流转记录。"""-- source: str = Field(description="原持有者或起始地点。")- target: str = Field(description="新持有者或目的地。")- transfer_type: str = Field(- description="流转类型:'收购自'、'出售给'、'捐赠予'、'借展给'、'委托'。"- )- specification: Optional[str] = Field(description="流转日期、成交价格或拍卖详情。")---# ==============================================================================-# 2. 提示词 (Prompts)-# ==============================================================================--PROVENANCE_GRAPH_PROMPT = (- "你是一位资深的艺术史学家和流传考证专家。请提取艺术品的流传历程图谱。\n\n"- "准则:\n"- "- 识别核心艺术品及其所有历史持有者(私人收藏家、博物馆、王室)。\n"- "- 按照时间顺序映射所有权转移(出售、继承、掠夺、捐赠)。\n"- "- 捕捉提到的具体日期、成交价格及传承细节。"-)--PROVENANCE_NODE_PROMPT = "提取艺术实体:识别作品、艺术家、收藏家、博物馆和拍卖行。标注作品的材质及相关人物/机构的角色。"--PROVENANCE_EDGE_PROMPT = "构建传承链条。将前任所有者与现任所有者联系起来,标注流转类型(如'捐赠予')。包含流转的时间段和交易详情。"--# ==============================================================================-# 3. 模板类-# ==============================================================================---class ProvenanceGraph(AutoGraph[ArtEntity, ProvenanceEdge]):- """- 艺术品流传图谱模板,用于追踪艺术品和文物的历史所有权。-- 适用于艺术品鉴定、馆藏档案管理和历史研究。-- 示例:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> llm = ChatOpenAI(model="gpt-4o")- >>> embedder = OpenAIEmbeddings()- >>> graph = ProvenanceGraph(llm_client=llm, embedder=embedder)- >>> text = "该画作于1815年由卢浮宫从博尔盖塞收藏中购得。"- >>> graph.feed_text(text)- >>> print(graph.edges) # 提取的作品所有权转移记录- """-- 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,- ):- """- 初始化艺术品流传图谱模板。-- Args:- llm_client: 语言模型客户端。- embedder: 嵌入模型。- extraction_mode: 提取模式,"one_stage" 或 "two_stage"。- chunk_size: 分块大小。- chunk_overlap: 分块重叠大小。- max_workers: 最大并行工作线程数。- verbose: 是否开启详细日志。- **kwargs: 传递给 AutoGraph 的额外参数。- """- super().__init__(- node_schema=ArtEntity,- edge_schema=ProvenanceEdge,- node_key_extractor=lambda x: x.name.strip(),- edge_key_extractor=lambda x: (- f"{x.source.strip()}--({x.transfer_type.lower()})-->{x.target.strip()}"- ),- nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),- 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=PROVENANCE_GRAPH_PROMPT,- prompt_for_node_extraction=PROVENANCE_NODE_PROMPT,- prompt_for_edge_extraction=PROVENANCE_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: ArtEntity) -> str:- info = f" ({node.category})" if getattr(node, "category", None) else ""- return f"{node.name}{info}"-- def edge_label_extractor(edge: ProvenanceEdge) -> str:- return f"{edge.transfer_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/automotive/__init__.py b/hyperextract/templates/zh/automotive/__init__.pydeleted file mode 100644index 0184d1b..0000000--- a/hyperextract/templates/zh/automotive/__init__.py+++ /dev/null@@ -1,9 +0,0 @@-from .car_spec import CarSpecGraph-from .maintenance import CarMaintenanceGraph-from .manufacturing import AutomotiveMfgGraph--__all__ = [- "CarSpecGraph",- "CarMaintenanceGraph",- "AutomotiveMfgGraph",-]diff --git a/hyperextract/templates/zh/automotive/car_spec.py b/hyperextract/templates/zh/automotive/car_spec.pydeleted file mode 100644index 9666886..0000000--- a/hyperextract/templates/zh/automotive/car_spec.py+++ /dev/null@@ -1,141 +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 CarComponent(BaseModel):- """车辆组件或参数类别(发动机、电池、自动驾驶、传动系统)。"""- name: str = Field(description="车型名称或具体组件名称。")- category: str = Field(- description="类别:'车型'、'动力系统'、'底盘'、'安全系统'、'信息娱乐'。"- )- specification: Optional[str] = Field(description="详细参数(如:马力、电量、版本)。")--class CarSystemRelation(BaseModel):- """汽车系统间的层级或技术关系。"""- source: str = Field(description="父系统或车辆型号。")- target: str = Field(description="子组件或功能。")- relation_type: str = Field(- description="类型:'配备'、'动力源自'、'集成'、'兼容'。"- )- performance_note: Optional[str] = Field(description="性能指标或集成细节。")--# ==============================================================================-# 2. 提示词 (Prompts)-# ==============================================================================--CAR_SPEC_GRAPH_PROMPT = (- "你是一位汽车工程师和技术评论员。请提取车辆的技术参数图谱。\n\n"- "准则:\n"- "- 识别车型及其核心系统(发动机、电机、电池、支驾系统)。\n"- "- 映射组件层级关系(例如:电池包含电芯,发动机使用涡轮增压器)。\n"- "- 捕捉可量化的参数,如 0-100km/h 加速、续航里程、峰值功率和扭矩。"-)--CAR_SPEC_NODE_PROMPT = (- "提取车型和技术组件。重点关注名称及其可测量的参数指标(如:500马力、80kWh)。"-)--CAR_SPEC_EDGE_PROMPT = (- "定义技术依赖关系。展示哪些组件属于哪个汽车系统。使用诸如'动力源自'或'配备'等关系。"-)--# ==============================================================================-# 3. 模板类-# ==============================================================================--class CarSpecGraph(AutoGraph[CarComponent, CarSystemRelation]):- """- 汽车参数图谱模板,用于提取车辆技术数据和参数层级。-- 适用于竞品分析、汽车垂直媒体和技术文档处理。-- 示例:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> llm = ChatOpenAI()- >>> embedder = OpenAIEmbeddings()- >>> graph = CarSpecGraph(llm_client=llm, embedder=embedder)- >>> text = "特斯拉 Model 3 高性能版采用双电机全轮驱动,可输出 510 马力。"- >>> graph.feed_text(text)- >>> 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- ):- """- 初始化汽车参数图谱模板。-- Args:- llm_client: 语言模型客户端。- embedder: 嵌入模型。- extraction_mode: 提取模式,"one_stage" 或 "two_stage"。- chunk_size: 分块大小。- chunk_overlap: 分块重叠大小。- max_workers: 最大并行工作线程数。- verbose: 是否开启详细日志。- **kwargs: 传递给 AutoGraph 的额外参数。- """- super().__init__(- node_schema=CarComponent,- edge_schema=CarSystemRelation,- node_key_extractor=lambda x: x.name.strip(),- edge_key_extractor=lambda x: f"{x.source.strip()}--({x.relation_type.lower()})-->{x.target.strip()}",- nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),- 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=CAR_SPEC_GRAPH_PROMPT,- prompt_for_node_extraction=CAR_SPEC_NODE_PROMPT,- prompt_for_edge_extraction=CAR_SPEC_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: CarComponent) -> str:- info = f" ({ node.category })" if getattr(node, "category", None) else ""- return f"{ node.name }{info}"-- def edge_label_extractor(edge: CarSystemRelation) -> str:- return f"{ edge.relation_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/automotive/maintenance.py b/hyperextract/templates/zh/automotive/maintenance.pydeleted file mode 100644index e09e22d..0000000--- a/hyperextract/templates/zh/automotive/maintenance.py+++ /dev/null@@ -1,137 +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 MaintenanceItem(BaseModel):- """保养项目或车辆零部件(机油、刹车片、正时皮带)。"""- item_name: str = Field(description="零部件名称或保养服务名称。")- category: str = Field(description="类别:'油液'、'易损件'、'检查项'、'软件更新'。")- interval: Optional[str] = Field(description="建议的里程或时间间隔(如:5,000公里)。")--class MaintenanceSequence(BaseModel):- """保养行动的依赖或序列关系。"""- source: str = Field(description="触发保养的部件或初始状态。")- target: str = Field(description="保养任务或更换的零部件。")- action: str = Field(description="动作:'更换'、'检查'、'清洗'、'校准'。")- precaution: Optional[str] = Field(description="安全警告或所需工具。")--# ==============================================================================-# 2. 提示词 (Prompts)-# ==============================================================================--MAINTENANCE_GRAPH_PROMPT = (- "你是一位资深技师和售后顾问。请提取车辆保养与维修图谱。\n\n"- "准则:\n"- "- 识别手册或日志中提到的具体保养项目和零部件。\n"- "- 映射触发保养的条件(如:里程、报警灯、视觉检查结果)。\n"- "- 将零部件连接到对应的系统及所需的维保动作。"-)--MAINTENANCE_NODE_PROMPT = (- "提取保养任务、零部件和油液类型。如果指定了建议间隔,请一并记录。"-)--MAINTENANCE_EDGE_PROMPT = (- "将触发条件与动作联系起来。展示哪些部件需要更换或检查。记录每项任务的具体注意事项。"-)--# ==============================================================================-# 3. 模板类-# ==============================================================================--class CarMaintenanceGraph(AutoGraph[MaintenanceItem, MaintenanceSequence]):- """- 汽车保养图谱模板,用于处理车辆服务手册、维修指南和保养日志。-- 有助于整理维保计划和零部件兼容性信息。-- 示例:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> llm = ChatOpenAI()- >>> embedder = OpenAIEmbeddings()- >>> graph = CarMaintenanceGraph(llm_client=llm, embedder=embedder)- >>> text = "每10,000公里更换发动机机油和机滤,使用 0W-20 全合成机油。"- >>> graph.feed_text(text)- >>> 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- ):- """- 初始化汽车保养图谱模板。-- Args:- llm_client: 语言模型客户端。- embedder: 嵌入模型。- extraction_mode: 提取模式,"one_stage" 或 "two_stage"。- chunk_size: 分块大小。- chunk_overlap: 分块重叠大小。- max_workers: 最大并行工作线程数。- verbose: 是否开启详细日志。- **kwargs: 传递给 AutoGraph 的额外参数。- """- super().__init__(- node_schema=MaintenanceItem,- edge_schema=MaintenanceSequence,- node_key_extractor=lambda x: x.item_name.strip(),- edge_key_extractor=lambda x: f"{x.source.strip()}--({x.action.lower()})-->{x.target.strip()}",- nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),- 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=MAINTENANCE_GRAPH_PROMPT,- prompt_for_node_extraction=MAINTENANCE_NODE_PROMPT,- prompt_for_edge_extraction=MAINTENANCE_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: MaintenanceItem) -> str:- info = f" ({ node.category })" if getattr(node, "category", None) else ""- return f"{ node.item_name }{info}"-- def edge_label_extractor(edge: MaintenanceSequence) -> str:- return f"{ edge.action }"-- 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/automotive/manufacturing.py b/hyperextract/templates/zh/automotive/manufacturing.pydeleted file mode 100644index 29afdb7..0000000--- a/hyperextract/templates/zh/automotive/manufacturing.py+++ /dev/null@@ -1,141 +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 ManufacturingEntity(BaseModel):- """汽车供应链或生产线上的实体(供应商、工厂、组装环节)。"""- name: str = Field(description="公司名称、工厂名称或生产工艺名称。")- category: str = Field(- description="类别:'供应商'、'工厂'、'工艺'、'原材料'、'质检'。"- )- specification: Optional[str] = Field(description="产能、资质认证或交付周期。")--class SupplyChainRelation(BaseModel):- """汽车制造中参与方与环节之间的连接关系。"""- source: str = Field(description="上游供应商或工艺环节。")- target: str = Field(description="下游工厂或产品。")- relation_type: str = Field(- description="类型:'供货给'、'组装于'、'处理自'、'认证用于'。"- )- logistics_details: Optional[str] = Field(description="贸易术语、运输时间或供应量承诺。")--# ==============================================================================-# 2. 提示词 (Prompts)-# ==============================================================================--MFG_GRAPH_PROMPT = (- "你是一位大型汽车制造商的供应链分析师。请提取汽车制造与供应链图谱。\n\n"- "准则:\n"- "- 识别各级供应商(一级、二级供应商)及其提供的零部件。\n"- "- 映射从原材料到整车下线的组装序列。\n"- "- 捕捉工厂的地理位置及特定的物流限制条件。"-)--MFG_NODE_PROMPT = (- "提取供应商、制造工厂和关键生产步骤。标注它们在车辆生产周期中的角色。"-)--MFG_EDGE_PROMPT = (- "定义物料流和工艺流。连接供应商到组装工厂,以及工厂到最终的整车交付环节。"-)--# ==============================================================================-# 3. 模板类-# ==============================================================================--class AutomotiveMfgGraph(AutoGraph[ManufacturingEntity, SupplyChainRelation]):- """- 汽车制造图谱模板,用于生产线流程、供应链物流和供应商管理。-- 有助于可视化全球汽车制造生态系统中的依赖关系。-- 示例:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> llm = ChatOpenAI()- >>> embedder = OpenAIEmbeddings()- >>> graph = AutomotiveMfgGraph(llm_client=llm, embedder=embedder)- >>> text = "宁德时代向特斯拉柏林超级工厂供应电池芯,用于 Model Y 的组装。"- >>> graph.feed_text(text)- >>> print(graph.edges) # 供应链流动信息- """- 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- ):- """- 初始化汽车制造图谱模板。-- Args:- llm_client: 语言模型客户端。- embedder: 嵌入模型。- extraction_mode: 提取模式,"one_stage" 或 "two_stage"。- chunk_size: 分块大小。- chunk_overlap: 分块重叠大小。- max_workers: 最大并行工作线程数。- verbose: 是否开启详细日志。- **kwargs: 传递给 AutoGraph 的额外参数。- """- super().__init__(- node_schema=ManufacturingEntity,- edge_schema=SupplyChainRelation,- node_key_extractor=lambda x: x.name.strip(),- edge_key_extractor=lambda x: f"{x.source.strip()}--({x.relation_type.lower()})-->{x.target.strip()}",- nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),- 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=MFG_GRAPH_PROMPT,- prompt_for_node_extraction=MFG_NODE_PROMPT,- prompt_for_edge_extraction=MFG_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: ManufacturingEntity) -> str:- info = f" ({ node.category })" if getattr(node, "category", None) else ""- return f"{ node.name }{info}"-- def edge_label_extractor(edge: SupplyChainRelation) -> str:- return f"{ edge.relation_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/business/__init__.py b/hyperextract/templates/zh/business/__init__.pydeleted file mode 100644index 8da251c..0000000--- a/hyperextract/templates/zh/business/__init__.py+++ /dev/null@@ -1,9 +0,0 @@-from .equity import EquityStructureGraph-from .strategy import StrategicChainGraph-from .ecosystem import MarketEcosystemHyper--__all__ = [- "EquityStructureGraph",- "StrategicChainGraph",- "MarketEcosystemHyper",-]diff --git a/hyperextract/templates/zh/business/ecosystem.py b/hyperextract/templates/zh/business/ecosystem.pydeleted file mode 100644index 8ec4a84..0000000--- a/hyperextract/templates/zh/business/ecosystem.py+++ /dev/null@@ -1,139 +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 AutoHypergraph--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================---class IndustryParticipant(BaseModel):- """- 产业生态系统中的实体(公司、监管机构、非政府组织)。- """-- name: str = Field(description="参与者名称(如:'台积电'、'欧盟委员会')。")- rank: Optional[str] = Field(- None, description="市场地位:'一级供应商'、'市场领导者'、'挑战者'。"- )- technological_focus: Optional[str] = Field(- None, description="主要技术或领域(如:'5G'、'光刻技术')。"- )---class CollectiveAlliance(BaseModel):- """- 代表财团、联盟、市场卡特尔或联合标准制定机构的超边。- """-- alliance_id: str = Field(description="联盟的名称或标识符(如:'芯片联盟')。")- participants: List[str] = Field(- description="在该团体中进行合作或竞争的所有实体的名称列表。"- )- shared_goal: str = Field(description="目标:'标准化'、'反垄断审查'、'联合研发'。")- governance: Optional[str] = Field(None, description="参与原则或领导实体。")---# ==============================================================================-# 2. Prompts-# ==============================================================================--ECOSYSTEM_CONSOLIDATED_PROMPT = (- "你是一位市场战略家和反垄断专家。请提取市场生态系统的动态。\n\n"- "规则:\n"- "- 使用超边(Hyperedges)将参与合资企业或联盟的多个实体(3个或更多)联系起来。\n"- "- 捕获非二元的群体关系,如卡特尔、产业集群和监管联盟。\n"- "- 清晰地定义这些群体的共同目标。"-)--ECOSYSTEM_NODE_PROMPT = (- "你是一位市场分析师。你的任务是识别产业生态系统中的所有参与者(节点)。\n\n"- "提取规则:\n"- "- 识别提及的公司、非政府组织(NGO)和监管机构。\n"- "- 捕捉它们的市场地位(Rank)和主要技术关注领域。\n"- "- 侧重于识别那些以群体形式进行合作或竞争的角色。\n"- "- 在此阶段请勿识别联盟、合资企业或财团。"-)--ECOSYSTEM_EDGE_PROMPT = (- "你是一位市场分析师。根据产业参与者清单,提取集体关系(超边)。\n\n"- "提取规则:\n"- "- 将多个参与者(3个或更多)归入联盟、标准制定机构或合资企业。\n"- "- 为整个群体定义共同的目标(如:'研发'、'反垄断审查')。\n"- "- 记录提及的任何治理结构或领导参与者。\n"- "- 确保群体的每个成员都选自提供的参与者清单。"-)--# ==============================================================================-# 3. Template Class-# ==============================================================================---class MarketEcosystemHyper(AutoHypergraph[IndustryParticipant, CollectiveAlliance]):- """- 用于产业集群、生态系统联盟和复杂市场协同的超图模板。- """-- 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,- ):- super().__init__(- node_schema=IndustryParticipant,- edge_schema=CollectiveAlliance,- node_key_extractor=lambda x: x.name.strip(),- edge_key_extractor=lambda x: x.alliance_id.strip(),- nodes_in_edge_extractor=lambda x: tuple(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=ECOSYSTEM_CONSOLIDATED_PROMPT,- prompt_for_node_extraction=ECOSYSTEM_NODE_PROMPT,- prompt_for_edge_extraction=ECOSYSTEM_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: IndustryParticipant) -> str:- return f"{ node.name }"-- def edge_label_extractor(edge: CollectiveAlliance) -> str:- return f"{ edge.alliance_id }"-- 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/business/equity.py b/hyperextract/templates/zh/business/equity.pydeleted file mode 100644index b55d6c8..0000000--- a/hyperextract/templates/zh/business/equity.py+++ /dev/null@@ -1,148 +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 StakeholderNode(BaseModel):- """- 在业务中持有股份或拥有控制权的法人或自然人。- """-- name: str = Field(description="公司注册全称或个人全名。")- type: str = Field(- description="类型:'自然人'、'上市公司'、'私有公司'、'国有企业'、'风险投资'。"- )- jurisdiction: Optional[str] = Field(- None, description="注册地或居住地所属的国家或地区。"- )- is_ubo: bool = Field(False, description="该实体是否被识别为最终受益人(UBO)。")---class OwnershipRelation(BaseModel):- """- 两个实体之间的持股或控制联系。- """-- source: str = Field(description="股东或母公司实体。")- target: str = Field(description="被拥有或控制的公司(子公司)。")- stake_percentage: Optional[float] = Field(- None, description="持股比例(0.0 到 100.0)。"- )- control_type: str = Field(- "Equity", description="联系性质:'股权收购'、'投票权'、'代持股份'、'直接控制'。"- )- as_of_date: Optional[str] = Field(- None, description="记录该所有权的时间点或财务周期。"- )---# ==============================================================================-# 2. Prompts-# ==============================================================================--EQUITY_CONSOLIDATED_PROMPT = (- "你是一位企业法务助理和财务分析师。请提取复杂的股权结构。\n\n"- "规则:\n"- "- 优先识别每个实体持有的股份比例。\n"- "- 区分直接股东和最终受益人(UBO)。\n"- "- 映射从母公司到最小子公司的层级结构。"-)--EQUITY_NODE_PROMPT = (- "你是一位企业法务助理和财务分析师。你的任务是识别出公司结构中的所有利益相关者(节点)。\n\n"- "提取规则:\n"- "- 识别公司、投资基金、政府机构和自然人个人。\n"- "- 将其分类为 '自然人'、'上市公司'、'私有公司' 等。\n"- "- 在明确的情况下,标记被识别为最终受益人(UBO)的实体。\n"- "- 在此阶段请勿提取持股比例或控制联系。"-)--EQUITY_EDGE_PROMPT = (- "你是一位企业法务助理和财务分析师。根据利益相关者清单,映射所有权和控制关系(边)。\n\n"- "提取规则:\n"- "- 提取股东(源)与公司(目标)之间持有的确切股份比例。\n"- "- 指定控制的性质(如:投票权、直接控制、代持股份)。\n"- "- 仅在提供的利益相关者清单中的成员之间建立边。\n"- "- 捕获所有权记录的 '截至日期' 或历史时期。"-)--# ==============================================================================-# 3. Template Class-# ==============================================================================---class EquityStructureGraph(AutoGraph[StakeholderNode, OwnershipRelation]):- """- 用于企业登记、并购分析及 KYC/UBO 追踪的高精度模板。- """-- 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,- ):- super().__init__(- node_schema=StakeholderNode,- edge_schema=OwnershipRelation,- node_key_extractor=lambda x: x.name.strip(),- edge_key_extractor=lambda x: (- f"{x.source.strip()}->{x.target.strip()}_at_{x.stake_percentage}%"- ),- nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),- 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=EQUITY_CONSOLIDATED_PROMPT,- prompt_for_node_extraction=EQUITY_NODE_PROMPT,- prompt_for_edge_extraction=EQUITY_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: StakeholderNode) -> str:- info = f" ({ node.type })" if getattr(node, "type", None) else ""- return f"{ node.name }{info}"-- def edge_label_extractor(edge: OwnershipRelation) -> str:- return f"{edge.control_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/business/strategy.py b/hyperextract/templates/zh/business/strategy.pydeleted file mode 100644index f304ec0..0000000--- a/hyperextract/templates/zh/business/strategy.py+++ /dev/null@@ -1,146 +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 AutoTemporalGraph--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================---class StrategicNode(BaseModel):- """- 组织实体、业务部门或战略目标。- """-- name: str = Field(description="战略单元或目标的名称(如:'Azure'、'碳中和')。")- scope: str = Field(description="范围:'全球'、'区域'、'特定产品'、'集团层面'。")- importance: Optional[str] = Field(- None, description="重要性:'核心业务'、'新兴市场'、'传统存量'。"- )---class StrategicPivot(BaseModel):- """- 代表战略重点转移、投资或剥离的时间性转变。- """-- source: str = Field(description="原始关注领域或施加动作的实体。")- target: str = Field(description="新的目标、方向或目的。")- action: str = Field(- description="战略动作:'转型为'、'收购'、'剥离'、'合并'、'关停'、'规模化'。"- )- timestamp: str = Field(- description="转型发生的时间(如:'2022年第四季度'、'2025-01-01')。"- )- rationale: Optional[str] = Field(- None, description="举措背后的原因(市场压力、CEO 变动、技术变革)。"- )- budget: Optional[str] = Field(None, description="与转型相关的财务承诺或预算。")---# ==============================================================================-# 2. Prompts-# ==============================================================================--STRATEGY_CONSOLIDATED_PROMPT = (- "你是一位管理顾问和行业分析师。请提取公司战略的演变过程。\n\n"- "规则:\n"- "- 专注于 '转型(Pivots)':从一个业务领域向另一个业务领域的转移。\n"- "- 将特定动作与具体时间戳联系起来。\n"- "- 捕获每次战略变革背后的深层原因(rationale)。"-)--STRATEGY_NODE_PROMPT = (- "你是一位管理顾问。你的任务是识别战略实体和目标(节点)。\n\n"- "提取规则:\n"- "- 识别业务部门、特定产品以及公司高层目标(如:'可持续发展')。\n"- "- 确定每个单元的范围和组织重要性。\n"- "- 专注于代表战略重点领域的名词和名词短语。\n"- "- 在此阶段请勿提取战略性动作或转型。"-)--STRATEGY_EDGE_PROMPT = (- "你是一位管理顾问。根据已识别的战略单元,映射战略随时间推移的转变(边)。\n\n"- "提取规则:\n"- "- 提取 '转型 (Pivots)' 以及如 '收购'、'剥离' 或 '关停' 之类的动作。\n"- "- 将源(旧重点)与目标(新重点)通过精确的时间戳联系起来。\n"- "- 捕捉深层原因以及提及的任何财务承诺(预算)。\n"- "- 仅引用战略单元清单中存在的节点。"-)--# ==============================================================================-# 3. Template Class-# ==============================================================================---class StrategicChainGraph(AutoTemporalGraph[StrategicNode, StrategicPivot]):- """- 用于追踪公司战略、长期组织变革和市场表现的时序模板。- """-- 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,- ):- super().__init__(- node_schema=StrategicNode,- edge_schema=StrategicPivot,- node_key_extractor=lambda x: x.name.strip(),- edge_key_extractor=lambda x: (- f"{x.source.strip()}-({x.action})->{x.target.strip()}"- ),- time_in_edge_extractor=lambda x: x.timestamp.strip(),- nodes_in_edge_extractor=lambda x: (x.source.strip(), x.target.strip()),- 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=STRATEGY_CONSOLIDATED_PROMPT,- prompt_for_node_extraction=STRATEGY_NODE_PROMPT,- prompt_for_edge_extraction=STRATEGY_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: StrategicNode) -> str:- return f"{node.name}"-- def edge_label_extractor(edge: StrategicPivot) -> str:- return f"{edge.action}"-- 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/construction/__init__.py b/hyperextract/templates/zh/construction/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/zh/construction/project_timeline.py b/hyperextract/templates/zh/construction/project_timeline.pydeleted file mode 100644index d07f2b1..0000000--- a/hyperextract/templates/zh/construction/project_timeline.py+++ /dev/null@@ -1,160 +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 AutoTemporalGraph--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================--class MilestoneTaskNode(BaseModel):- """- 建筑项目进度计划中的特定任务、里程碑或阶段。- """- task_name: str = Field(description="任务操作名称(例如:'基础浇筑')。")- phase: str = Field(description="项目阶段:'前期准备'、'下部结构'、'主体结构'、'装修装饰'、'竣工验收'。")- duration_estimate: Optional[str] = Field(None, description="预估时间(例如:'14天'、'2个月')。")- responsible_party: Optional[str] = Field(None, description="负责的分包商或团队负责人。")--class TemporalDependency(BaseModel):- """- 表示任务权序的基于时间的连接。- """- source: str = Field(description="前置任务。")- target: str = Field(description="后置任务。")- timestamp: str = Field(- description="时间标记或步骤编号(例如:'阶段1'、'步骤2'或具体日期/时间)。"- )- dependency_type: str = Field(- "完成到开始",- description="类型:'完成到开始 (FS)'、'开始到开始 (SS)'、'完成到完成 (FF)'、'开始到完成 (SF)'。"- )- lag_time: Optional[str] = Field(None, description="任务间的等待时间(例如:'混凝土养护3天')。")--# ==============================================================================-# 2. Prompts-# ==============================================================================--CONSTRUCTION_TEMPORAL_CONSOLIDATED_PROMPT = (- "你是一位资深项目管理计划员和计划工程师。请从文本中提取建筑项目的时间进度表。\n\n"- "提取规则:\n"- "- 识别细化的任务和重大里程碑作为节点。\n"- "- 使用行业标准逻辑(FS, SS等)建立清晰的时间依赖关系(边)。\n"- "- 捕获提到的持续时间和养护/滞后时间。\n"- "- 重点关注关键路径和测序逻辑。"-)--CONSTRUCTION_TEMPORAL_NODE_PROMPT = (- "识别所有任务、计划活动和项目里程碑。\n\n"- "提取规则:\n"- "- 提取以动词开头的任务名称。\n"- "- 将任务归类到项目阶段并识别负责方。\n"- "- 在此阶段不要识别顺序或依赖关系。"-)--CONSTRUCTION_TEMPORAL_EDGE_PROMPT = (- "根据任务在时间上的逻辑顺序进行连接。\n\n"- "提取规则:\n"- "- 为每个链接定义前导任务和后续任务。\n"- "- 分类链接类型(如果未指定,默认为FS)。\n"- "- 识别任何要求的滞后时间(例如:等待检验或干燥)。\n"- "- 仅在已识别的列表任务之间创建连接。"-)--# ==============================================================================-# 3. Template Class-# ==============================================================================--class ProjectSchedulingTimeline(AutoTemporalGraph[MilestoneTaskNode, TemporalDependency]):- """- 用于提取项目计划和关键路径法(CPM)网络的模板。-- 适用于进度风险分析、延期跟踪和进度监控。-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> timeline = ProjectSchedulingTimeline(llm_client=llm, embedder=embedder)- >>> timeline.feed_text("土方开挖必须在浇筑基础底板之前完成。")- >>> print(timeline.nodes) # 获取任务和里程碑- >>> print(timeline.edges) # 获取时间依赖关系- """-- 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,- ):- """- 初始化项目进度时间轴模板。-- Args:- llm_client (BaseChatModel): 用于进度提取的大模型客户端。- embedder (Embeddings): 用于任务和依赖项去重的嵌入模型。- extraction_mode (str, optional): 'one_stage' 为联合提取,- 'two_stage' 为分步提取。默认为 "one_stage"。- chunk_size (int, optional): 单个文本块的最大字符数。默认为 2048。- chunk_overlap (int, optional): 文本块之间的重叠字符数。默认为 256。- max_workers (int, optional): 并行处理的工作线程数。默认为 10。- verbose (bool, optional): 是否启用详细日记记录。默认为 False。- **kwargs (Any): 传递给 AutoTemporalGraph 基类的其他参数。- """- super().__init__(- node_schema=MilestoneTaskNode,- edge_schema=TemporalDependency,- node_key_extractor=lambda x: x.task_name.strip().lower(),- edge_key_extractor=lambda x: f"{x.source.strip().lower()}--[{x.dependency_type}]-->{x.target.strip().lower()}",- nodes_in_edge_extractor=lambda x: (x.source.strip().lower(), x.target.strip().lower()),- time_in_edge_extractor=lambda x: x.timestamp.strip(),- 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=CONSTRUCTION_TEMPORAL_CONSOLIDATED_PROMPT,- prompt_for_node_extraction=CONSTRUCTION_TEMPORAL_NODE_PROMPT,- prompt_for_edge_extraction=CONSTRUCTION_TEMPORAL_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: MilestoneTaskNode) -> str:- info = f" ({node.phase})" if getattr(node, "phase", None) else ""- return f"{node.task_name}{info}"-- def edge_label_extractor(edge: TemporalDependency) -> 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/construction/resource_registry.py b/hyperextract/templates/zh/construction/resource_registry.pydeleted file mode 100644index 9b3d927..0000000--- a/hyperextract/templates/zh/construction/resource_registry.py+++ /dev/null@@ -1,108 +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 AutoSet--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================--class ConstructionResource(BaseModel):- """- 分配给建筑项目的特定资产、材料或劳动力类别。- """- resource_name: str = Field(description="资源名称(例如:'塔吊 TC-01'、'粉煤灰混凝土')。")- category: str = Field(description="类别:'重型机械'、'散装材料'、'技工'、'固定设备'、'易耗品'。")- quantity: Optional[str] = Field(None, description="现场当前数量或容量。")- supplier_or_team: Optional[str] = Field(None, description="提供或管理此资源的实体。")- status: str = Field("在用", description="当前运营状态:'在用'、'闲置'、'维护'、'用尽'。")--# ==============================================================================-# 2. Prompts-# ==============================================================================--CONSTRUCTION_RESOURCE_PROMPT = (- "你是一位建筑物流和采购经理。请从文本中提取所有项目资源和资产。\n\n"- "提取规则:\n"- "- 识别机械、材料和劳动力类型。\n"- "- 捕获提到的具体数量和供应商名称。\n"- "- 自动合并相似项(例如:'挖掘机 A' 和 '那台主要的挖掘机' 如果指代同一个单元,应合并)。"-)--# ==============================================================================-# 3. Template Class-# ==============================================================================--class ResourceRegistrySet(AutoSet[ConstructionResource]):- """- 用于管理统一的工地资产和材料清单的模板。-- 使用 AutoSet 自动去重并合并多段文本中提到的资源信息。-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> registry = ResourceRegistrySet(llm_client=llm, embedder=embedder)- >>> registry.feed_text("现场有两台来自利勃海尔的50吨起重机。")- >>> registry.feed_text("这些利勃海尔起重机目前正在进行维修。")- >>> print(registry.items) # 信息将合并到单个起重机资源中- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- *,- chunk_size: int = 2048,- chunk_overlap: int = 256,- max_workers: int = 10,- verbose: bool = False,- **kwargs: Any,- ):- """- 初始化资源登记表模板。-- Args:- llm_client (BaseChatModel): 用于资源提取的大模型客户端。- embedder (Embeddings): 用于资源去重的嵌入模型。- chunk_size (int, optional): 单个文本块的最大字符数。默认为 2048。- chunk_overlap (int, optional): 文本块之间的重叠字符数。默认为 256。- max_workers (int, optional): 并行处理的工作线程数。默认为 10。- verbose (bool, optional): 是否启用详细日记记录。默认为 False。- **kwargs (Any): 传递给 AutoSet 基类的其他参数。- """- super().__init__(- item_schema=ConstructionResource,- key_extractor=lambda x: x.resource_name.strip().lower(),- llm_client=llm_client,- embedder=embedder,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- max_workers=max_workers,- verbose=verbose,- prompt=CONSTRUCTION_RESOURCE_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: ConstructionResource) -> str:- info = f" ({ item.category })" if getattr(item, "category", None) else ""- return f"{ item.resource_name }{info}"-- 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/construction/site_topology.py b/hyperextract/templates/zh/construction/site_topology.pydeleted file mode 100644index 600edf7..0000000--- a/hyperextract/templates/zh/construction/site_topology.py+++ /dev/null@@ -1,157 +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 AutoSpatialGraph--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================--class PhysicalElementNode(BaseModel):- """- 建筑工地内的特定物理构件或区域。- """- name: str = Field(description="元素的唯一标识符或名称(例如:'A1柱'、'B区')。")- element_type: str = Field(description="类型:'结构件'、'机电构件'、'建筑构件'、'临时设施'、'安全区域'。")- location_coordinates: Optional[str] = Field(None, description="空间坐标或相对轴线位置(例如:'X:10, Y:20, Z:5')。")- material_properties: Optional[str] = Field(None, description="关键材料信息(例如:'C30混凝土'、'S355钢材')。")--class SpatialRelation(BaseModel):- """- 两个物理元素之间的空间或拓扑连接关系。- """- source: str = Field(description="参考元素。")- target: str = Field(description="关联元素。")- location_marker: str = Field(- description="该关系所在的物理位置或区域(例如:'3层'、'北翼'、'A-1轴线')。"- )- relation_type: str = Field(- description="类型:'支撑'、'相邻'、'包含于'、'相交'、'对齐'。"- )- offset_distance: Optional[float] = Field(None, description="元素间的物理距离(单位:米)。")--# ==============================================================================-# 2. Prompts-# ==============================================================================--CONSTRUCTION_SPATIAL_CONSOLIDATED_PROMPT = (- "你是一位资深BIM(建筑信息模型)工程师。请从文本中提取建筑项目的空间拓扑结构。\n\n"- "提取规则:\n"- "- 识别固定的物理构件及其属性作为节点。\n"- "- 映射这些构件之间的结构和空间关系(边)。\n"- "- 如果文本提到了坐标和距离,请务必捕获。\n"- "- 重点关注物体是如何物理连接或相对定位的。"-)--CONSTRUCTION_SPATIAL_NODE_PROMPT = (- "识别所有物理建筑构件和工地区域。\n\n"- "提取规则:\n"- "- 提取明确的结构、机械或建筑构件。\n"- "- 捕获任何提到的位置、楼层或材料信息。\n"- "- 在此阶段不要识别连接关系。"-)--CONSTRUCTION_SPATIAL_EDGE_PROMPT = (- "映射已识别建筑构件之间的空间和结构关系。\n\n"- "提取规则:\n"- "- 确定元素A与元素B的关系(例如:A支撑B,A与B相邻)。\n"- "- 提取提供的物理偏移或距离。\n"- "- 仅在已识别的列表元素之间创建连接。"-)--# ==============================================================================-# 3. Template Class-# ==============================================================================--class SiteTopologyGraph(AutoSpatialGraph[PhysicalElementNode, SpatialRelation]):- """- 用于构建建筑工地空间数字孪生的模板。-- 适用于结构分析、BIM转图谱以及工地物流规划。-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> graph = SiteTopologyGraph(llm_client=llm, embedder=embedder)- >>> graph.feed_text("基础底板支撑着四个主要的转角柱。")- >>> print(graph.nodes) # 获取结构构件- >>> print(graph.edges) # 获取空间关系- """-- 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,- ):- """- 初始化工地拓扑图谱模板。-- Args:- llm_client (BaseChatModel): 用于拓扑提取的大模型客户端。- embedder (Embeddings): 用于元素去重的嵌入模型。- extraction_mode (str, optional): 'one_stage' 为联合提取,- 'two_stage' 为分步提取。默认为 "one_stage"。- chunk_size (int, optional): 单个文本块的最大字符数。默认为 2048。- chunk_overlap (int, optional): 文本块之间的重叠字符数。默认为 256。- max_workers (int, optional): 并行处理的工作线程数。默认为 10。- verbose (bool, optional): 是否启用详细日记记录。默认为 False。- **kwargs (Any): 传递给 AutoSpatialGraph 基类的其他参数。- """- super().__init__(- node_schema=PhysicalElementNode,- edge_schema=SpatialRelation,- node_key_extractor=lambda x: x.name.strip().lower(),- edge_key_extractor=lambda x: f"{x.source.strip().lower()}--{x.relation_type.lower()}--{x.target.strip().lower()}",- nodes_in_edge_extractor=lambda x: (x.source.strip().lower(), x.target.strip().lower()),- location_in_edge_extractor=lambda x: x.location_marker.strip(),- 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=CONSTRUCTION_SPATIAL_CONSOLIDATED_PROMPT,- prompt_for_node_extraction=CONSTRUCTION_SPATIAL_NODE_PROMPT,- prompt_for_edge_extraction=CONSTRUCTION_SPATIAL_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: PhysicalElementNode) -> str:- return f"{node.name}"-- def edge_label_extractor(edge: SpatialRelation) -> str:- return f"{edge.relation_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/cybersecurity/__init__.py b/hyperextract/templates/zh/cybersecurity/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/zh/cybersecurity/intrusion_kill_chain.py b/hyperextract/templates/zh/cybersecurity/intrusion_kill_chain.pydeleted file mode 100644index 5f2c5db..0000000--- a/hyperextract/templates/zh/cybersecurity/intrusion_kill_chain.py+++ /dev/null@@ -1,175 +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 AutoGraph--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================---class AttackStageNode(BaseModel):- """- 网络攻击中的特定阶段或行动(符合 MITRE ATT&CK 或 Lockheed Kill Chain)。- """-- stage_name: str = Field(- description="攻击阶段名称(例如:'初始访问'、'权限维持'、'横向移动')。"- )- tactics_used: List[str] = Field(- default_factory=list,- description="所使用的具体技术或战术(例如:'鱼叉式网络钓鱼'、'哈希传递')。",- )- adversary_tools: List[str] = Field(- default_factory=list,- description="该阶段使用的恶意软件或工具(例如:'Cobalt Strike'、'Mimikatz')。",- )- timestamp: Optional[str] = Field(None, description="行动的时间点或顺序标记。")---class KillChainLink(BaseModel):- """- 表示攻击从一个阶段向另一个阶段演进的有向链接。- """-- source: str = Field(description="前置攻击阶段。")- target: str = Field(description="后续攻击阶段。")- causality: str = Field(- "演进",- description="类型:'演进' (标准)、'触发' (自动执行)、'跳转' (基础设施切换)。",- )- observables: List[str] = Field(- default_factory=list, description="连接各阶段的入侵指标 (IOCs,如IP、Hash)。"- )---# ==============================================================================-# 2. Prompts-# ==============================================================================--CYBER_KILL_CHAIN_CONSOLIDATED_PROMPT = (- "你是一位数字取证专家和事件响应人员。请从事件报告中重建攻击时间线和杀伤链。\n\n"- "提取规则:\n"- "- 识别不同的攻击阶段作为节点。\n"- "- 映射攻击在时间上和逻辑上的演进过程(边)。\n"- "- 捕获每个阶段的具体战术、工具 (TTPs) 和时间戳。\n"- "- 重点关注攻击者是如何移动以及在何时移动的。"-)--CYBER_KILL_CHAIN_NODE_PROMPT = (- "识别所有可疑活动和网络入侵的不同阶段。\n\n"- "提取规则:\n"- "- 提取以行动为导向的阶段(例如:'投放载荷'、'建立C2')。\n"- "- 识别与每个发现相关的工具和技术。\n"- "- 在此阶段不要建立各阶段之间的连接。"-)--CYBER_KILL_CHAIN_EDGE_PROMPT = (- "建立已识别攻击阶段之间的顺序和演进关系。\n\n"- "提取规则:\n"- "- 定义哪个阶段导致或促成了下一个阶段。\n"- "- 识别连接这些阶段的入侵指标(IP、哈希等)。\n"- "- 仅在已识别的列表阶段之间创建连接。"-)--# ==============================================================================-# 3. Template Class-# ==============================================================================---class IntrusionKillChainGraph(AutoGraph[AttackStageNode, KillChainLink]):- """- 用于重建网络攻击生命周期的模板。-- 适用于事件响应 (IR)、取证报告和威胁狩猎。-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> kill_chain = IntrusionKillChainGraph(llm_client=llm, embedder=embedder)- >>> kill_chain.feed_text("攻击者通过鱼叉式网络钓鱼邮件获得了初始访问。")- >>> print(kill_chain.nodes) # 获取攻击阶段- >>> print(kill_chain.edges) # 获取演进链接- """-- 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,- ):- """- 初始化入侵杀伤链图谱模板。-- Args:- llm_client (BaseChatModel): 用于杀伤链提取的大模型客户端。- embedder (Embeddings): 用于阶段去重的嵌入模型。- extraction_mode (str, optional): 'one_stage' 为联合提取,- 'two_stage' 为分步提取。默认为 "one_stage"。- chunk_size (int, optional): 单个文本块的最大字符数。默认为 2048。- chunk_overlap (int, optional): 文本块之间的重叠字符数。默认为 256。- max_workers (int, optional): 并行处理的工作线程数。默认为 10。- verbose (bool, optional): 是否启用详细日记记录。默认为 False。- **kwargs (Any): 传递给 AutoGraph 基类的其他参数。- """- super().__init__(- node_schema=AttackStageNode,- edge_schema=KillChainLink,- node_key_extractor=lambda x: x.stage_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=CYBER_KILL_CHAIN_CONSOLIDATED_PROMPT,- prompt_for_node_extraction=CYBER_KILL_CHAIN_NODE_PROMPT,- prompt_for_edge_extraction=CYBER_KILL_CHAIN_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: AttackStageNode) -> str:- return f"{node.stage_name}"-- def edge_label_extractor(edge: KillChainLink) -> str:- return f"{edge.causality}"-- 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/cybersecurity/threat_intelligence_nexus.py b/hyperextract/templates/zh/cybersecurity/threat_intelligence_nexus.pydeleted file mode 100644index f0f7c38..0000000--- a/hyperextract/templates/zh/cybersecurity/threat_intelligence_nexus.py+++ /dev/null@@ -1,176 +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 AutoHypergraph--# ==============================================================================-# 1. Schema Definitions-# ==============================================================================---class ThreatActorNode(BaseModel):- """- 负责网络威胁的实体(个人、团体或国家级组织)。- """-- actor_name: str = Field(- description="别名或团体名称(例如:'APT28'、'Fancy Bear'、'Lazarus Group')。"- )- origin_country: Optional[str] = Field(None, description="疑似地理来源。")- motivation: Optional[str] = Field(- None,- description="主要驱动因素:'间谍活动'、'经济利益'、'破坏'、'黑客行动主义'。",- )- typical_targets: List[str] = Field(- default_factory=list, description="通常的目标行业或地区。"- )---class IntelligenceNexus(BaseModel):- """- 连接攻击者、特定基础设施和战役主题的超边。- """-- participants: List[str] = Field(- description="涉及的实体:攻击者名称、工具名称、基础设施(IP/域名)、受害组织。"- )- campaign_name: str = Field(- description="已知的行动名称(例如:'SolarWinds 供应链攻击')。"- )- shared_ttp: str = Field(- description="连接这些不同实体的共同战术、技术或过程(TTP)。"- )- confidence_level: str = Field("中", description="分析置信度:'高'、'中'、'低'。")---# ==============================================================================-# 2. Prompts-# ==============================================================================--CYBER_NEXUS_CONSOLIDATED_PROMPT = (- "你是一位战略威胁情报分析师。请映射攻击者、基础设施及其战役之间的高层级关联。\n\n"- "提取规则:\n"- "- 识别威胁攻击者及其别名作为节点。\n"- "- 创建超边 (Nexuses),在命名的战役下,将攻击者与特定工具和基础设施关联起来。\n"- "- 重点关注揭示协同行动的多点连接,而非简单的二元链接。\n"- "- 突出显示统一该 Nexus 的共享 TTPs。"-)--CYBER_NEXUS_NODE_PROMPT = (- "识别威胁攻击者、恶意软件家族和恶意基础设施实体。\n\n"- "提取规则:\n"- "- 提取攻击者别名和团体名称。\n"- "- 识别攻击动机和目标行业。\n"- "- 在此阶段不要建立战役关联。"-)--CYBER_NEXUS_EDGE_PROMPT = (- "识别统一了攻击者、工具和目标的行动战役 (Campaigns) 或关联 (Nexuses)。\n\n"- "提取规则:\n"- "- 每个超边必须描述一个单一的战役或行动。\n"- "- 将攻击者关联到在该行动中使用的特定基础设施和工具。\n"- "- 仅在已识别的列表实体之间创建连接。"-)--# ==============================================================================-# 3. Template Class-# ==============================================================================---class ThreatIntelligenceNexusHypergraph(- AutoHypergraph[ThreatActorNode, IntelligenceNexus]-):- """- 用于战略威胁情报映射的模板。-- 适用于在复杂战役中连接基础设施、攻击者和恶意软件。-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> nexus = ThreatIntelligenceNexusHypergraph(llm_client=llm, embedder=embedder)- >>> nexus.feed_text("APT28 在 'Fancy-Phish' 行动中使用了 X-Tunnel。")- >>> print(nexus.nodes) # 获取威胁攻击者- >>> print(nexus.edges) # 获取战役超边- """-- 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,- ):- """- 初始化威胁情报关联超图模板。-- Args:- llm_client (BaseChatModel): 用于关联提取的大模型客户端。- embedder (Embeddings): 用于攻击者去重的嵌入模型。- extraction_mode (str, optional): 'one_stage' 为联合提取,- 'two_stage' 为分步提取。默认为 "one_stage"。- chunk_size (int, optional): 单个文本块的最大字符数。默认为 2048。- chunk_overlap (int, optional): 文本块之间的重叠字符数。默认为 256。- max_workers (int, optional): 并行处理的工作线程数。默认为 10。- verbose (bool, optional): 是否启用详细日记记录。默认为 False。- **kwargs (Any): 传递给 AutoHypergraph 基类的其他参数。- """- super().__init__(- node_schema=ThreatActorNode,- edge_schema=IntelligenceNexus,- node_key_extractor=lambda x: x.actor_name.strip().lower(),- edge_key_extractor=lambda x: (- f"{x.campaign_name.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=CYBER_NEXUS_CONSOLIDATED_PROMPT,- prompt_for_node_extraction=CYBER_NEXUS_NODE_PROMPT,- prompt_for_edge_extraction=CYBER_NEXUS_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: ThreatActorNode) -> str:- return f"{node.actor_name}"-- def edge_label_extractor(edge: IntelligenceNexus) -> str:- return f"{edge.campaign_name}"-- 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/cybersecurity/vulnerability_catalog.py b/hyperextract/templates/zh/cybersecurity/vulnerability_catalog.pydeleted file mode 100644index 1c93e69..0000000--- a/hyperextract/templates/zh/cybersecurity/vulnerability_catalog.py+++ /dev/null@@ -1,120 +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 VulnerabilityEntry(BaseModel):- """- 系统中识别出的特定安全漏洞或弱点。- """-- vulnerability_id: str = Field(- description="唯一标识符(例如:CVE-2023-1234, CWE-79)。"- )- title: str = Field(description="漏洞的简短描述性名称。")- severity: str = Field(- description="严重程度:'危急'、'高危'、'中危'、'低危'、'提示'。"- )- cvss_score: Optional[float] = Field(- None, description="CVSS 基础评分(0.0 到 10.0)。"- )- affected_components: List[str] = Field(- default_factory=list, description="受影响的软件或硬件组件。"- )- remediation: Optional[str] = Field(None, description="建议的修复或缓解措施。")---# ==============================================================================-# 2. Prompts-# ==============================================================================--CYBER_VULN_PROMPT = (- "你是一位资深安全分析师和漏洞研究员。请从威胁报告、安全公告或扫描结果中提取并整合安全漏洞。\n\n"- "提取规则:\n"- "- 通过 CVE/CWE ID 或名称识别唯一的漏洞。\n"- "- 准确捕获严重级别和 CVSS 评分。\n"- "- 将同一漏洞的多次提及合并为单个条目,并汇总受影响组件和修复建议的信息。"-)--# ==============================================================================-# 3. Template Class-# ==============================================================================---class VulnerabilityUnifiedCatalog(AutoSet[VulnerabilityEntry]):- """- 用于构建去重后的安全漏洞目录的模板。-- 适用于处理多个安全公告并创建用于补丁管理的清单。-- Example:- >>> from langchain_openai import ChatOpenAI, OpenAIEmbeddings- >>> catalog = VulnerabilityUnifiedCatalog(llm_client=llm, embedder=embedder)- >>> catalog.feed_text("CVE-2024-0001 是内核中的一个危急 RCE 漏洞。")- >>> catalog.feed_text("该内核 RCE (CVE-2024-0001) 需要立即修复。")- >>> print(catalog.items) # CVE-2024-0001 的重复条目将被合并- """-- def __init__(- self,- llm_client: BaseChatModel,- embedder: Embeddings,- *,- chunk_size: int = 2048,- chunk_overlap: int = 256,- max_workers: int = 10,- verbose: bool = False,- **kwargs: Any,- ):- """- 初始化安全漏洞目录模板。-- Args:- llm_client (BaseChatModel): 用于漏洞提取的大模型客户端。- embedder (Embeddings): 用于条目去重的嵌入模型。- chunk_size (int, optional): 单个文本块的最大字符数。默认为 2048。- chunk_overlap (int, optional): 文本块之间的重叠字符数。默认为 256。- max_workers (int, optional): 并行处理的工作线程数。默认为 10。- verbose (bool, optional): 是否启用详细日记记录。默认为 False。- **kwargs (Any): 传递给 AutoSet 基类的其他参数。- """- super().__init__(- item_schema=VulnerabilityEntry,- key_extractor=lambda x: x.vulnerability_id.strip().upper(),- llm_client=llm_client,- embedder=embedder,- chunk_size=chunk_size,- chunk_overlap=chunk_overlap,- max_workers=max_workers,- verbose=verbose,- prompt=CYBER_VULN_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: VulnerabilityEntry) -> str:- return f"{item.title}"-- 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/fashion/__init__.py b/hyperextract/templates/zh/fashion/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/zh/marketing/__init__.py b/hyperextract/templates/zh/marketing/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/zh/music/__init__.py b/hyperextract/templates/zh/music/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/zh/politics/__init__.py b/hyperextract/templates/zh/politics/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/zh/real_estate/__init__.py b/hyperextract/templates/zh/real_estate/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/zh/recruitment/__init__.py b/hyperextract/templates/zh/recruitment/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/zh/software/__init__.py b/hyperextract/templates/zh/software/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/zh/sports/__init__.py b/hyperextract/templates/zh/sports/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/zh/supply_chain/__init__.py b/hyperextract/templates/zh/supply_chain/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/hyperextract/templates/zh/travel/__init__.py b/hyperextract/templates/zh/travel/__init__.pydeleted file mode 100644index e69de29..0000000