当前位置: 首页 > Skill >

Knowledge Graph - Csv Graph Loader Generator

Knowledge Graph - Csv Graph Loader Generator

Knowledge Graph - Csv Graph Loader Generator

从 CSV 数据集生成图数据库加载器和三元组映射。将表格 CSV 数据转换为图数据库可直接使用的节点、边和三元组。

1.0.0 2026.11.24 197
获取Skill文件查看使用说明
作 者:苏言 许可证: 更新时间:2026.11.24
本文目录展开

CSV Graph Loader Generator

Convert CSV datasets into graph-ready structures for knowledge graph construction.

This skill transforms tabular CSV data into graph database ingestion formats such as nodes, edges, or triples. It generates mappings and loader scripts for graph systems like Neo4j, RDF triple stores, property graphs, and knowledge graphs.

Quick Start

Use When

  • Converting CSV datasets to graph structures
  • Preparing data for graph database import
  • Generating Neo4j LOAD CSV scripts
  • Creating RDF triple mappings
  • Building property graphs from tables
  • Constructing knowledge graphs from structured data
  • Automating CSV → graph ETL workflows

Inputs

  • CSV file or data
  • Column definitions and data types
  • Entity type specifications
  • Relationship definitions
  • Target graph format
  • Custom mapping rules

Outputs

  • Node definitions (labels, properties)
  • Relationship mappings (types, directions)
  • Neo4j Cypher import scripts
  • RDF triple definitions
  • Property graph JSON
  • Graph schema definitions
  • Mapping configuration files

Example

Input CSV:

person_id,name,company_name,company_industry,job_title
1,Alice Johnson,Acme Corp,Technology,Software Engineer
2,Bob Smith,Acme Corp,Technology,Product Manager
3,Carol Davis,TechStart Inc,Technology,CTO

Generated Output (Nodes & Edges):

{
  "nodes": [
    {"id": "p1", "type": "Person", "properties": {"name": "Alice Johnson", "job": "Software Engineer"}},
    {"id": "p2", "type": "Person", "properties": {"name": "Bob Smith", "job": "Product Manager"}},
    {"id": "c1", "type": "Company", "properties": {"name": "Acme Corp", "industry": "Technology"}},
    {"id": "c2", "type": "Company", "properties": {"name": "TechStart Inc", "industry": "Technology"}}
  ],
  "edges": [
    {"source": "p1", "target": "c1", "type": "WORKS_AT"},
    {"source": "p2", "target": "c1", "type": "WORKS_AT"},
    {"source": "p3", "target": "c2", "type": "WORKS_AT"}
  ]
}

CSV-to-Graph Transformation Strategy

1. Entity Detection

Automatically identify entity columns:

  • ID columns - Unique identifiers (person_id, company_id)
  • Name columns - Entity names (name, title, company_name)
  • Category columns - Entity types (type, category, industry)

2. Entity Classification

Create node types from detected entities:

person_id → Person node
company_name → Company node
department → Department node

3. Relationship Inference

Map column associations to relationships:

person_id + company_name → WORKS_AT
employee_id + manager_id → REPORTS_TO
product_id + category_id → BELONGS_TO

4. Property Assignment

Remaining columns become node properties:

name → Person.name
salary → Person.salary
industry → Company.industry

5. Output Generation

Create loader scripts for target system:

Neo4j: LOAD CSV WITH HEADERS...
RDF: :Alice rdf:type :Person
JSON: {"nodes": [...], "edges": [...]}

Supported Entity Patterns

ID-Based Entities

pattern: column_name contains "id" or "identifier"
example: person_id, user_id, company_id

Name-Based Entities

pattern: column_name contains "name" or "title"
example: person_name, company_name, job_title

Category-Based Entities

pattern: column_name contains "type" or "category"
example: person_type, company_category, product_category

Implicit Entities

pattern: column values represent entities
example: department column with values like "Sales", "Engineering"

Output Formats

Neo4j Cypher Script

LOAD CSV WITH HEADERS FROM 'file:///employees.csv' AS row
MERGE (p:Person {id: row.person_id})
SET p.name = row.name, p.job_title = row.job_title
MERGE (c:Company {name: row.company_name})
SET c.industry = row.company_industry
MERGE (p)-[:WORKS_AT]->(c)

RDF Triples (Turtle)

@prefix ex: <http://example.org/> .

ex:person1 a ex:Person ;
  ex:name "Alice Johnson" ;
  ex:jobTitle "Software Engineer" ;
  ex:worksAt ex:acme_corp .

ex:acme_corp a ex:Company ;
  ex:name "Acme Corp" ;
  ex:industry "Technology" .

Property Graph JSON

{
  "nodes": [
    {"id": "p1", "type": "Person", "properties": {"name": "Alice", "job": "Engineer"}},
    {"id": "c1", "type": "Company", "properties": {"name": "Acme", "industry": "Tech"}}
  ],
  "edges": [
    {"source": "p1", "target": "c1", "type": "WORKS_AT"}
  ]
}

CSV to Node/Edge Tables

# nodes.csv
id,type,name,job_title
p1,Person,Alice,Software Engineer
p2,Person,Bob,Product Manager
c1,Company,Acme Corp,

# edges.csv
source,target,type
p1,c1,WORKS_AT
p2,c1,WORKS_AT

Mapping Strategies

Automatic Detection

pros: No manual configuration needed
cons: May infer wrong relationships
use: Quick prototyping, simple datasets

Semi-Automated with Hints

pros: Balance between automation and control
cons: Requires some input
use: Most common production use case

Explicit Mapping

pros: Full control, exact desired output
cons: Requires complete configuration
use: Complex schemas, strict requirements

Data Type Inference

The loader automatically infers:

  • String - Text columns
  • Integer - Numeric whole numbers
  • Float - Decimal numbers
  • Boolean - True/false values
  • DateTime - Date and time formats
  • Reference - Columns pointing to other entities

Duplicate Handling

Merge Strategy

Identical entities across rows are merged
example: Two rows with "Acme Corp" → one Company node

Deduplication

Removes duplicate edges from same source/target
example: Multiple WORKS_AT edges → single edge

ID-Based Deduplication

Uses unique identifiers to prevent duplicates
example: person_id as stable key for Person nodes

Execution Steps

  1. Parse CSV – Read file and validate structure
  2. Analyze Schema – Detect data types and patterns
  3. Detect Entities – Identify entity columns
  4. Infer Relationships – Map column associations
  5. Create Schema – Define node types and relationship types
  6. Generate Mappings – Create column-to-property mappings
  7. Validate Data – Check for data quality issues
  8. Generate Loaders – Output scripts for target system

Recommended Libraries

  • CSV Processing: pandas, csv, polars
  • Graph Generation: neo4j, rdflib, networkx
  • Data Validation: pydantic, jsonschema
  • RDF/OWL: rdflib, owlready2, sparql-client
  • JSON Transformation: jsonschema, jinja2

Best Practices

✓ Use stable, meaningful identifiers
✓ Normalize entity names to prevent duplicates
✓ Define explicit entity types rather than guessing
✓ Validate data before loading to graph database
✓ Document custom mapping rules
✓ Test with sample data first
✓ Monitor for duplicate nodes or relationships
✓ Keep mapping configurations version-controlled
✓ Handle missing values explicitly
✓ Implement referential integrity checks

Integration with Downstream Skills

The generated graph data feeds into:

  • Graph Query Optimization – Optimize generated Cypher queries
  • Schema Validation – Validate against graph schema
  • Graph Constraint Generator – Define constraints for loaded data
  • Knowledge Graph Construction – Build KGs from CSV sources
  • ETL Pipeline Generator – Orchestrate full CSV → Graph workflows

References

See loader-patterns.md for detailed CSV loader patterns and example-loaders.md for complete domain-specific examples.

Version: 1.0.0

推荐文章

更多
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,019
JavaScript中利用replace结合正则实现replaceAll效果

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

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

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

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

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

2026.12.02 1,013
Skill 文件
  • SKILL.md
    • CSV Graph Loader Generator
    • Quick Start
      • Use When
      • Inputs
      • Outputs
    • Example
    • CSV-to-Graph Transformation Strategy
      • 1. Entity Detection
      • 2. Entity Classification
      • 3. Relationship Inference
      • 4. Property Assignment
      • 5. Output Generation
    • Supported Entity Patterns
      • ID-Based Entities
      • Name-Based Entities
      • Category-Based Entities
      • Implicit Entities
    • Output Formats
      • Neo4j Cypher Script
      • RDF Triples (Turtle)
      • Property Graph JSON
      • CSV to Node/Edge Tables
    • Mapping Strategies
      • Automatic Detection
      • Semi-Automated with Hints
      • Explicit Mapping
    • Data Type Inference
    • Duplicate Handling
      • Merge Strategy
      • Deduplication
      • ID-Based Deduplication
    • Execution Steps
    • Recommended Libraries
    • Best Practices
    • Integration with Downstream Skills
    • References
  • 项目或源文件

相关 Skill

更多
Knowledge Graph - Tigergraph Connector Knowledge Graph - Tigergraph Connector 使用 GSQL和 REST++ API 连接 TigerGraph 分布式图数据库,查询、加载并管理大规模知识图数据。
Knowledge Graph - Graph Path Reasoning Analyzer Knowledge Graph - Graph Path Reasoning Analyzer 在知识图中分析并发现实体之间的路径,以解释关系、识别间接关联并提供遍历推理。
Knowledge Graph - Transitive Closure Generator Knowledge Graph - Transitive Closure Generator 在图上计算传递闭包,以推断隐含关系并通过逻辑蕴含的连接扩展图。支持多种算法及自定义实现。
Knowledge Graph - Rdf Triple Store Integration Knowledge Graph - Rdf Triple Store Integration 连接RDF三元组存储并执行SPARQL查询,实现语义知识图数据的存储、检索与管理
Knowledge Graph - Ontology Based Inference Helper Knowledge Graph - Ontology Based Inference Helper 将语义本体规则应用于知识图谱,从显式本体定义中推断新的关系、类成员资格和属性。支持...