当前位置: 首页 > Skill >

ontology-tugraph-engineer

ontology-tugraph-engineer

ontology-tugraph-engineer

本体图谱格式文件抽取

2026.11.21 514
获取Skill文件查看使用说明
作 者:江宁 许可证: 更新时间:2026.11.21
本文目录展开

Ontology Engineer

Extract candidate ontology models from existing data. Build and maintain personal knowledge graphs.

Core principle: Make implicit business models in existing data explicit. Don't create from scratch.

Division of labor: Scripts handle mechanical extraction (file scanning, format conversion, table parsing). LLM handles semantic judgment (entity identification, property selection, relationship discovery, naming, cross-source merging).

Security model:

  • No external API calls. The LLM running this skill (Claude, OpenClaw, etc.) IS the semantic engine. No credentials, no network endpoints, no data exfiltration paths.
  • User-scoped scanning. Step 1.5 is a MANDATORY interactive checkpoint — the user reviews and approves every folder before any content is read. Nothing is analyzed without explicit confirmation.
  • Local-only output. All artifacts (graph.jsonl, schema.yaml, review.md) are written to a user-specified local directory. No data leaves the machine.
  • Append-only writes. Scripts only create/append files. No deletion, no modification of existing user files.

When This Skill Adds Value (and When It Doesn't)

Knowledge graphs and ontology extraction are not universally useful. Before starting, assess fit:

Scenario Value Why
3+ heterogeneous systems with inconsistent naming for the same concepts High (Mode A) Cross-system concept alignment is the core use case
Agent product needs factual grounding to reduce hallucination High (Mode B/C) Graph becomes Agent's fact base — auto-query before every response
1000+ entities with dense relationships across long time spans High Pattern discovery humans can't do manually (churn, cross-sell, capability mapping)
Client consulting engagement analyzing their data landscape High (Mode A) Core consulting deliverable: "here's what your data assets look like"
Small org, <200 entities, info fits in one person's head + Excel Low (Mode B) Graph just re-stores what user already knows — use as PoC/capability validation only
Single system, no cross-system integration need Low (Mode A) Read the schema directly; ontology layer adds overhead without value

Rule of thumb: If the user's reaction to the output is "I already knew all this", the graph isn't producing incremental value. Redirect to Mode A (client projects) or Agent integration.

Detailed value scenarios: references/value-scenarios.md

Operating Modes

Mode Input Output Use When
A: Database Extraction SQL DDL, data dictionaries, Word/Excel schemas ontology.json + review.md Analyzing enterprise business systems
B: Filesystem Scanning Local/cloud directories graph.jsonl + schema.yaml Building personal knowledge graph
C: External Data Others' data spaces, shared drives graph.jsonl (source=external) Acquiring others' business models

Mode A: Database Extraction

Three-phase workflow for extracting ontology from structured data sources.

Phase 1: SCAN

Run scripts/scan_directory.py to discover and classify files by priority (P1-P7).

python scripts/scan_directory.py "<dir>" --output scan_result.json --report

Review scan report. Process P1-P2 files first, expand as needed.

Phase 2: EXTRACT

  1. Convert .doc files if needed: scripts/convert_doc.py
  2. Extract tables from Word/Excel: scripts/extract_tables.py
  3. Read extracted data, apply Rules 1-7 (see references/analysis-rules.md)
  4. For text formats (.sql, .json, .yaml, .md, .csv): read directly

Phase 3: MERGE

  1. Cross-source entity deduplication (Rule 5)
  2. Relationship consolidation
  3. Output: ontology.json + review.md

Detailed rules: references/analysis-rules.md (Rules 1-7) Quality checks: references/quality-checks.md Script details: references/script-operations.md Modeling decisions: references/modeling-decisions.md

Mode B/C: Knowledge Graph

Two-step pipeline for building personal knowledge graphs from file systems.

Step 1: File Indexing (script, no LLM)

python scripts/scan_filesystem.py --root /path --config namespace_rules.yaml --extract-metadata

Creates Document + Project entities in graph.jsonl. Pure mechanical operation.

Key features: Auto namespace inference, duplicate detection, .docx/.pdf metadata extraction, universal noise filtering.

Step 1.5: User Scope Confirmation (MANDATORY interactive step)

After Step 1 completes, present the scan summary to the user and ask for scope confirmation before proceeding to Step 2. The user knows which folders matter most.

Display a table of all discovered projects/namespaces with document counts, then ask:

扫描完成,发现 {N} 个项目,共 {M} 篇文档。请标记每个文件夹的优先级:
- 🔴 重点(高采样率,优先分析)
- ⚪ 普通(默认采样率)
- ⚫ 忽略(跳过,不分析)
- 或输入"全部"跳过选择,按默认策略处理所有文件夹

| # | 项目 | 文档数 | 格式分布 | 默认优先级 |
|---|------|--------|----------|-----------|
| 1 | work/myfiles | 15,617 | .doc .docx .pdf .xlsx | 🔴 重点 |
| 2 | work/classified | 1,578 | .doc .pdf .xlsx | ⚪ 普通 |
| ... | ... | ... | ... | ... |

请输入调整(如 "2=忽略, 5=重点")或 "全部" 或 "确认":

Rules:

  • User can mark any folder as 重点/普通/忽略
  • User can type "全部" to skip selection and use defaults
  • 重点 folders get 2-3x sampling rate, 忽略 folders are skipped entirely
  • Default priority is auto-inferred: human work folders=重点, AI-generated=普通, downloads/cache=忽略
  • Never skip this step. Even if obvious, let the user confirm.

Step 2: Semantic Analysis (LLM, core step)

Five phases: Sampling → Document Reading → Aggregation → Cross-project Alignment → Output.

Key decisions (details in references/knowledge-graph-workflow.md):

  • Minimum 10% coverage, 重点 folders 2-3x, 忽略 folders skip
  • Structured lists (Rule 13): Files named 列表/台账/名单/登记表/清单 etc. → full extraction (every row = one entity), NOT sampling. See references/analysis-rules.md Rule 13.
  • Dual-track extraction: Track A (named entities) + Track B (domain terms)
  • Subagents must be general-purpose type (Bash access). Never use Explore type.
  • Format tools: see references/formats-and-deps.md
  • Relation semantics: Use enriched relation format with direction, cardinality, temporal range. See references/relation-ontology.md.

Step 3: Runtime Evolution

Agent enriches the knowledge graph during daily conversations. source.type = "runtime".

When to trigger (passive, no user action needed):

  • User mentions a person by name + role/org → check graph, append if new
  • User discusses a project/event with dates → append Event
  • User makes a strategic decision or key insight → append Note
  • User mentions a new organization/client → append Organization

How to append:

python query_graph.py search "张三"  # Check if entity exists
# If not found, append to graph.jsonl:
echo '{"op":"create","ts":"...","entity":{"id":"per-NNNNN","type":"Person","graph":"core/persons","source":{"type":"runtime","conversation_id":"..."},...}}' >> graph.jsonl

Rules:

  • Only append entities with concrete evidence from the conversation
  • Never overwrite existing entities — only add new ones or note conflicts
  • Use source.type = "runtime" to distinguish from scan-derived entities
  • Keep it lightweight: 1-3 entities per conversation, not a full re-scan

Full workflow details: references/knowledge-graph-workflow.md Analysis rules (8-12): references/analysis-rules.md Format support & deps: references/formats-and-deps.md

Key Principles

  • Model business concepts, not database tables. Table names ≠ object names.
  • Extract then express. Make implicit models explicit, don't create from nothing.
  • Experts judge. Produce candidates; final decisions belong to humans. When in doubt, flag it.
  • Invest in invariants. Stable entities and relationships, not technical details.
  • Handle what exists. Real projects use Word and Excel. Adapt to the data.
  • Scripts extract, LLM analyzes. Mechanical extraction via Python. Semantic judgment via LLM.
  • Coverage over perfection. 60% of files at moderate depth beats 3% at maximum depth.
  • Generic skeleton + domain discovery. 8 core types (BFO-aligned). Domain types discovered by scanning.
  • Single source of truth. All data in one graph.jsonl. Soft partition via graph/labels/source.
  • Relations carry semantics. Direction, cardinality, temporal range, evidence. Not just type + target.
  • Append-only evolution. Never delete entities. Deprecate, reclassify, version.

Ontology Theory References

Reference When to Read
references/modeling-decisions.md Core type boundaries, entity vs enum, promotion judgment
references/relation-ontology.md Relation format, core relation catalog, ternary relations
references/ontology-evolution.md Schema versioning, entity reclassification, conflict resolution
references/constraints-and-inference.md Type/relation constraints, inference rules, inconsistency detection
references/value-scenarios.md When this skill adds value and when it doesn't

Output Formats

graph.jsonl (Mode B/C)

{"op":"create","ts":"2026-01-15T10:00:00Z","entity":{"id":"per-00001","type":"Person","graph":"core/persons","labels":["employee"],"source":{"type":"scan","scan_id":"step2-r1"},"properties":{"name":"张三","roles":["项目经理"],"organizations":["某科技公司"]},"relations":[{"type":"works_at","target_id":"org-00002","direction":"forward","cardinality":"N:1","temporal":{"start":"2019-01","end":null},"confidence":"high"}],"created_at":"2026-01-15T10:00:00Z"}}

Required: id, type, graph, source, created_at. Optional: labels, properties, relations.

Relation fields: type + target_id required. Optional: direction (forward/reverse/bidirectional), cardinality (1:1/1:N/N:1/N:M), temporal ({start, end}), evidence (source entity ID), confidence (high/medium/low). See references/relation-ontology.md.

schema.yaml (Mode B/C)

meta:
  version: "2.0"
core_types:       # 8 fixed (BFO-aligned): Person, Organization, Project, Task, Document, Event, Note, Goal
domain_types:     # Discovered by Step 2 Track B, grouped by domain
namespaces:       # core/, work/*, personal/*, external/*, uncategorized/*
source_types:     # scan | runtime | manual | email | cloud | chat
relation_schema:  # Relation fields: type, target_id, direction, cardinality, temporal, evidence, confidence
relation_types:   # Core relation catalog grouped by source type pair
constraints:      # type_constraints (required props, enums), relation_constraints, id_pattern
inference_rules:  # Transitive subsidiary, symmetric partner, inverse works_at, etc.
schema_evolution:  # Version format, backward compatibility rules

ontology.json (Mode A)

{
  "meta": {"generated_by": "ontology-engineer", "source_files": [], "domain": "..."},
  "object_types": [{"name": "...", "english": "...", "core_properties": [], "confidence": "high|medium|low"}],
  "link_types": [{"from": "A", "relation": "verb", "to": "B", "cardinality": "1:N", "evidence": "..."}],
  "review_flags": [{"type": "promotion|merge|ambiguity|missing", "item": "...", "question": "..."}]
}

review.md

  1. Scan summary 2. Model overview 3. Object catalog 4. Relationship map 5. Review items 6. Cross-source merges 7. Data quality notes 8. Decision log

TuGraph Import Format (Optional Export)

After generating ontology.json (Mode A) or graph.jsonl (Mode B/C), export to TuGraph bulk-import JSON aligned with tugraph_import_demo_new.json:

python scripts/export_tugraph.py ontology.json --out ontology_tugraph.json

Output structure:

{
  "schema": {
    "vertex_labels": [
      {
        "label": "Domain",
        "type": "VERTEX",
        "primary": "name",
        "properties": [
          {"name": "name", "type": "string", "optional": false, "comment": "业务域中文名(主键)"},
          {"name": "object_count", "type": "int64", "optional": true, "comment": "域内实体表数量"}
        ]
      },
      {
        "label": "Table",
        "type": "VERTEX",
        "primary": "id",
        "properties": [
          {"name": "id", "type": "string", "optional": false, "comment": "tbl-xxxxxxxxxx"},
          {"name": "name", "type": "string", "optional": true, "comment": "业务化名称"},
          {"name": "english", "type": "string", "optional": true, "comment": "英文表名"},
          {"name": "schema_name", "type": "string", "optional": true, "comment": "DB schema"},
          {"name": "table_name", "type": "string", "optional": true, "comment": "DB 表名"},
          {"name": "source_table", "type": "string", "optional": true, "comment": "schema.table 全名"},
          {"name": "table_comment", "type": "string", "optional": true},
          {"name": "category", "type": "string", "optional": true, "comment": "object_type/link_type/value_domain/excluded"},
          {"name": "domain_name", "type": "string", "optional": true, "comment": "所属业务域"},
          {"name": "confidence", "type": "string", "optional": true, "comment": "low/medium/high"},
          {"name": "row_estimate", "type": "int64", "optional": true},
          {"name": "code_sql_ref_count", "type": "int64", "optional": true}
        ]
      }
    ],
    "edge_labels": [
      {
        "label": "BELONGS_TO",
        "type": "EDGE",
        "properties": [{"name": "confidence", "type": "string", "optional": true}],
        "edge_constraints": [["Table", "Domain"]]
      },
      {
        "label": "REFERENCES",
        "type": "EDGE",
        "properties": [
          {"name": "from_column", "type": "string", "optional": true},
          {"name": "to_column", "type": "string", "optional": true},
          {"name": "cardinality", "type": "string", "optional": true},
          {"name": "confidence", "type": "string", "optional": true},
          {"name": "evidence", "type": "string", "optional": true}
        ],
        "edge_constraints": [["Table", "Table"]]
      }
    ],
    "vector_indexes": {
      "items": [
        {"label": "Domain", "field": "embedding", "dimension": 768, "algorithm": "HNSW", "source_field": "name"},
        {"label": "Table",  "field": "embedding", "dimension": 768, "algorithm": "HNSW", "source_field": "name"}
      ]
    }
  },
  "vertices": {
    "Domain": {"label": "Domain", "primary": "name", "fields": ["name", "object_count"], "values": [["项目管理", 464], ...]},
    "Table":  {"label": "Table",  "primary": "id",   "fields": [...], "values": [[...], ...]}
  },
  "edges": {
    "BELONGS_TO": {"label": "BELONGS_TO", "fields": ["confidence"], "edge": [{"source": "tbl-xxx", "destination": "项目管理", "values": ["medium"]}]},
    "REFERENCES": {"label": "REFERENCES", "fields": ["from_column","to_column","cardinality","confidence","evidence"], "edge": [...]}
  }
}

Vertex mappings:

Label Source object_count
Domain One per unique object.domain Count of object_types in that domain
Table One per object_types entry —

Edge mappings:

Label From To Source
BELONGS_TO Table Domain object.domain field
REFERENCES Table Table link_types (FK constraints)

Vector index: Both Domain and Table use source_field: "name" — the vertex name property is embedded for semantic search. id (tbl-xxxxxxxxxx) is only the primary key.

Scripts

Script Mode Purpose
scripts/scan_filesystem.py B/C File indexing, namespace inference, metadata extraction
scripts/scan_directory.py A File discovery with P1-P7 priority classification
scripts/convert_doc.py A .doc → .docx conversion
scripts/extract_tables.py A Table extraction from Word/Excel
scripts/export_tugraph.py A Export ontology.json → TuGraph bulk-import JSON

Details: references/script-operations.md

Agent Integration

Component Purpose Status
query_graph.py Search entities by type/name/graph/labels, traverse relations Done
Runtime write Agent appends new entities during conversation (Step 3) Done
MCP Server Expose graph as tools: search_entities, get_relations Planned
Prompt injection Agent auto-queries graph for context before handling tasks Planned

Query tool usage:

python query_graph.py stats                    # Overview
python query_graph.py search "关键词"           # Search
python query_graph.py type Person --limit 20   # By type
python query_graph.py get per-00001            # Details
python query_graph.py relations per-00001      # Relations
python query_graph.py domain --limit 30        # Domain terms
python query_graph.py export Person --format csv  # Export

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,034
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,031
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,018
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,017
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,013
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,013
Skill 文件
  • SKILL.md
    • Ontology Engineer
    • When This Skill Adds Value (and When It Doesn't)
    • Operating Modes
    • Mode A: Database Extraction
      • Phase 1: SCAN
      • Phase 2: EXTRACT
      • Phase 3: MERGE
    • Mode B/C: Knowledge Graph
      • Step 1: File Indexing (script, no LLM)
      • Step 1.5: User Scope Confirmation (MANDATORY interactive step)
      • Step 2: Semantic Analysis (LLM, core step)
      • Step 3: Runtime Evolution
    • Key Principles
    • Ontology Theory References
    • Output Formats
      • graph.jsonl (Mode B/C)
      • schema.yaml (Mode B/C)
      • ontology.json (Mode A)
      • review.md
      • TuGraph Import Format (Optional Export)
    • Scripts
    • Agent Integration

相关 Skill

更多
service-qa-coach service-qa-coach Review support quality for chat, email, phone, social DM, or marketplace service teams. Use when a team needs a QA scorecard, failure-mode analysis, coaching plan, calibration checklist, or service-improvement brief without live ticketing, CRM, or contact-center system access.
高中数学作业批改助手 高中数学作业批改助手 >图片识别 直接读取学生手写作答照片,识别公式、符号、步骤 🧮 自动推导 根据题目自动生成参考答案和评分细则,无需教师预设 📊 逐步给分 每个关键步骤独立评分,体现过程分 📝 结构化报告 输出含识别内容、参考答案、逐步评分、改进建议的完整报告 🗂 批量批改 支持一次性批改多道题,最终汇总得分表
Vibration Analysis Vibration Analysis 分析来自CMS趋势、RMS/峰值、频谱及SCADA报警的风机传动链(主轴、齿轮箱、发电机)振动数据。
Traditional Bone Tool Making Basics Traditional Bone Tool Making Basics Use when you need custom, durable, repairable tools like awls, needles, scrapers, harpoons, or fishing hooks made from local animal bones or antlers and comm...
音频混音工具 音频混音工具 名称:Sound Mixing Tool(标识 sound-mixing-tool) 短简介(≤60字):音乐/音效响度精确对齐 + 融合混音工作流:用 ffmpeg 两段式 loudnorm 把多组素材 LUFS 偏差压到 <0.10,再最小干预融合、导出可进引擎的独立分轨。 标签/关键词:音频混音 响度匹配 LUFS ffmpeg 游戏音频 音效设计 Wwise FMOD 分轨导出 后期处理 触发词:混音 · 响度匹配 · LUFS 对齐 · MIX 版本 · 音乐音效分轨 · 融合 · 不打架 · 不能盖住 适用场景 :游戏音频集成、影视短视频配乐、播客后期