从 CSV 数据集生成图数据库加载器和三元组映射。将表格 CSV 数据转换为图数据库可直接使用的节点、边和三元组。
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.
Input CSV:
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):
json
{
"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"}
]
}
Automatically identify entity columns:
Create node types from detected entities:
text
person_id → Person node
company_name → Company node
department → Department node
Map column associations to relationships:
text
person_id + company_name → WORKS_AT
employee_id + manager_id → REPORTS_TO
product_id + category_id → BELONGS_TO
Remaining columns become node properties:
text
name → Person.name
salary → Person.salary
industry → Company.industry
Create loader scripts for target system:
cypher
Neo4j: LOAD CSV WITH HEADERS...
RDF: :Alice rdf:type :Person
JSON: {"nodes": [...], "edges": [...]}
text
pattern: column_name contains "id" or "identifier"
example: person_id, user_id, company_id
text
pattern: column_name contains "name" or "title"
example: person_name, company_name, job_title
text
pattern: column_name contains "type" or "category"
example: person_type, company_category, product_category
text
pattern: column values represent entities
example: department column with values like "Sales", "Engineering"
cypher
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)
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" .
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
# 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
text
pros: No manual configuration needed
cons: May infer wrong relationships
use: Quick prototyping, simple datasets
text
pros: Balance between automation and control
cons: Requires some input
use: Most common production use case
text
pros: Full control, exact desired output
cons: Requires complete configuration
use: Complex schemas, strict requirements
The loader automatically infers:
text
Identical entities across rows are merged
example: Two rows with "Acme Corp" → one Company node
text
Removes duplicate edges from same source/target
example: Multiple WORKS_AT edges → single edge
text
Uses unique identifiers to prevent duplicates
example: person_id as stable key for Person nodes
✓ 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
The generated graph data feeds into:
See loader-patterns.md for detailed CSV loader patterns and example-loaders.md for complete domain-specific examples.
Version: 1.0.0