Hypergraph is more powerful. Transform unstructured text into structured knowledge with LLMs. Graphs, hypergraphs, and spatio-temporal extractions — with one command.
Merge PR #139 with #144: JSON-LD export via the shared graph-type guard
yifanfeng97b631995f230b
diff --cc docs/en/cli/index.mdindex ade4009,3455b0f..29b2877--- a/docs/en/cli/index.md+++ b/docs/en/cli/index.md@@@ -33,8 -33,7 +33,12 @@@ he --versio| `he parse` | Extract knowledge from documents | `-t` template, `-o` output, `-l` language, `--source` attribution || `he show` | Visualize knowledge graph | — || `he export obsidian` | Export to an Obsidian vault | `-o` output, `--name`, `-f` force |++<<<<<<< HEAD+| `he export graphml` | Export a pairwise graph to GraphML | `-o` output file |+| `he export jsonld` | Export pairwise edges and N-ary hyperedges to JSON-LD | `-o` output file, `-f` force |++=======+ | `he export graphml` | Export pairwise `<edge>` and N-ary `<hyperedge>` GraphML | `-o` output file, `-f` force |++>>>>>>> origin/main| `he export csv` | Export nodes/edges as CSV tables | `-o` directory, `-f` force || `he search` | Semantic search in knowledge abstract | `-n` top-k results, `--source`, `--tag` || `he talk` | Chat with knowledge abstract | `-i` interactive, `-q` query |@@@ -173,8 -172,7 +177,12 @@@ he show ./output- **[`he talk`](commands/talk.md)** — Chat with knowledge abstract- **[`he info`](commands/info.md)** — View knowledge abstract statistics- **[`he export obsidian`](commands/export.md)** — Export to an Obsidian vault++<<<<<<< HEAD+- **[`he export graphml`](commands/export.md#he-export-graphml)** — Export a pairwise graph to GraphML+- **[`he export jsonld`](commands/export.md#he-export-jsonld)** — Export pairwise edges and N-ary hyperedges to JSON-LD++=======+ - **[`he export graphml`](commands/export.md#he-export-graphml)** — Export pairwise `<edge>` and N-ary `<hyperedge>` GraphML++>>>>>>> origin/main- **[`he export csv`](commands/export.md#he-export-csv)** — Export nodes/edges as CSV tables### Managementdiff --cc docs/zh/cli/index.mdindex 0c25e6f,04d1b71..0196e7d--- a/docs/zh/cli/index.md+++ b/docs/zh/cli/index.md@@@ -33,8 -33,7 +33,12 @@@ he --versio| `he parse` | 从文档提取知识 | `-t` 模板, `-o` 输出, `-l` 语言, `--source` 来源标注 || `he show` | 可视化知识图谱 | — || `he export obsidian` | 导出为 Obsidian 知识库 | `-o` 输出, `--name`, `-f` 强制 |++<<<<<<< HEAD+| `he export graphml` | 将二元图导出为 GraphML | `-o` 输出文件 |+| `he export jsonld` | 将二元边与 N 元超边导出为 JSON-LD | `-o` 输出文件, `-f` 强制 |++=======+ | `he export graphml` | 导出二元 `<edge>` 与 N 元 `<hyperedge>` GraphML | `-o` 输出文件, `-f` 强制 |++>>>>>>> origin/main| `he export csv` | 将节点/边导出为 CSV 表 | `-o` 目录, `-f` 强制 || `he search` | 知识库语义搜索 | `-n` top-k 结果数, `--source`, `--tag` || `he talk` | 与知识库对话 | `-i` 交互模式, `-q` 查询 |@@@ -173,8 -172,7 +177,12 @@@ he show ./output- **[`he talk`](commands/talk.md)** — 与知识库对话- **[`he info`](commands/info.md)** — 查看知识库统计信息- **[`he export obsidian`](commands/export.md)** — 导出为 Obsidian 知识库++<<<<<<< HEAD+- **[`he export graphml`](commands/export.md#he-export-graphml)** — 将二元图导出为 GraphML+- **[`he export jsonld`](commands/export.md#he-export-jsonld)** — 将二元边与 N 元超边导出为 JSON-LD++=======+ - **[`he export graphml`](commands/export.md#he-export-graphml)** — 导出二元 `<edge>` 与 N 元 `<hyperedge>` GraphML++>>>>>>> origin/main- **[`he export csv`](commands/export.md#he-export-csv)** — 将节点/边导出为 CSV 表### 管理diff --cc hyperextract/utils/exporters/ka.pyindex 0000000,b272acd..7456832mode 000000,100644..100644--- a/hyperextract/utils/exporters/ka.py+++ b/hyperextract/utils/exporters/ka.py@@@ -1,0 -1,67 +1,67 @@@+ """KA-level adapters for GraphML and CSV export.++ CLI ``he export graphml/csv`` and MCP ``export_graphml`` / ``export_csv``+ call these functions so extractor wiring and the graph-type check live in+ one place. Encoders stay pure functions over node/edge models.+ """++ from __future__ import annotations++ from pathlib import Path+ from typing import Any++ from .common import resolve_export_file+ from .csv_export import export_to_csv+ from .graphml import export_to_graphml++ GRAPH_TYPE_ERROR = (- "GraphML/CSV export is only supported for graph-type knowledge abstracts "- "(graph, hypergraph, temporal/spatial graphs)."++ "Graph export (GraphML/CSV/JSON-LD) is only supported for graph-type "++ "knowledge abstracts (graph, hypergraph, temporal/spatial graphs)."+ )+++ class GraphTypeError(ValueError):+ """Raised when a non-graph KA is passed to a graph exporter."""+++ def is_hypergraph_ka(ka: Any) -> bool:+ """True for AutoHypergraph; temporal/spatial graphs are pairwise."""+ if type(ka).__name__ == "AutoHypergraph":+ return True+ meta = getattr(ka, "metadata", None)+ return isinstance(meta, dict) and meta.get("type") == "hypergraph"+++ def require_graph_ka(ka: Any) -> None:+ if hasattr(ka, "export_obsidian"):+ return+ raise GraphTypeError(GRAPH_TYPE_ERROR)+++ def export_ka_graphml(ka: Any, dest: str | Path, *, overwrite: bool = False) -> Path:+ """Export a loaded graph-family KA to GraphML."""+ require_graph_ka(ka)+ dest = resolve_export_file(dest, overwrite=overwrite)+ return export_to_graphml(+ ka.nodes,+ ka.edges,+ node_id_extractor=ka.node_key_extractor,+ incident_nodes_extractor=ka.nodes_in_edge_extractor,+ file_path=dest,+ edge_id_extractor=getattr(ka, "edge_key_extractor", None),+ )+++ def export_ka_csv(ka: Any, dest: str | Path, *, overwrite: bool = False) -> Path:+ """Export a loaded graph-family KA to CSV tables."""+ require_graph_ka(ka)+ return export_to_csv(+ ka.nodes,+ ka.edges,+ node_id_extractor=ka.node_key_extractor,+ incident_nodes_extractor=ka.nodes_in_edge_extractor,+ folder_path=dest,+ edge_id_extractor=getattr(ka, "edge_key_extractor", None),+ hypergraph=is_hypergraph_ka(ka),+ overwrite=overwrite,+ )diff --cc tests/utils/test_exporters.pyindex 9ee3534,78508ec..81a4ba0--- a/tests/utils/test_exporters.py+++ b/tests/utils/test_exporters.py@@@ -19,8 -19,14 +19,15 @@@ from hyperextract.utils.exporters imporHYPEREDGE_MEMBER_SEP,export_to_csv,export_to_graphml,+ export_to_jsonld,)+ from hyperextract.utils.exporters.common import default_edge_id, resolve_export_file+ from hyperextract.utils.exporters.ka import (+ GRAPH_TYPE_ERROR,+ GraphTypeError,+ export_ka_csv,+ export_ka_graphml,+ )from hyperextract.utils.exporters.graphml import GRAPHML_NSrunner = CliRunner()