Install
openclaw skills install mapping-dsl-builderGenerate declarative mapping rules that transform structured data sources into graph triples or nodes using a domain-specific mapping language similar to R2RML.
openclaw skills install mapping-dsl-builderGenerate declarative mapping rules for transforming data into graph structures.
This skill creates domain-specific language (DSL) mappings that define how data fields from structured sources such as databases, CSV files, JSON, or APIs should be transformed into nodes, relationships, and triples for graph databases or knowledge graphs. The mapping language functions similarly to R2RML, the standard for relational-to-RDF mappings.
Input Database Schema:
CREATE TABLE employee (
id INT,
name VARCHAR(255),
email VARCHAR(255),
company_id INT
);
CREATE TABLE company (
id INT,
name VARCHAR(255),
industry VARCHAR(100)
);
Generated Mapping DSL:
mapping: EmployeeMapping
version: 1.0
source:
type: database
table: employee
connection: postgresql://localhost/company_db
entity:
type: Person
identifier: id
uri_template: "http://example.org/person/{id}"
properties:
- source: name
target: http://xmlns.com/foaf/0.1/name
type: string
- source: email
target: http://xmlns.com/foaf/0.1/mbox
type: string
relationships:
- name: WORKS_AT
source: company_id
target: Company
target_identifier: id
Purpose: Specify where data comes from
Types Supported:
Configuration:
source:
type: database|csv|json|api|stream
connection_string: connection_details
table_or_location: specification
format: format_options
Purpose: Define how records map to graph entities
Components:
Configuration:
entity:
type: EntityType
identifier: id_column
uri_template: "http://example.org/type/{id}"
namespace: http://example.org/
Purpose: Map source attributes to graph properties
Details:
Configuration:
properties:
- source: database_column
target: http://schema.org/propertyName
type: string|integer|date
transformation: function_name
required: true|false
Purpose: Define relationships between entities
Details:
Configuration:
relationships:
- name: RELATIONSHIP_TYPE
source: foreign_key_column
target: TargetEntity
target_identifier: target_id
cardinality: "1..1"|"1..*"|"*..1"|"*..*"
direction: forward|backward|bidirectional
Pattern: Map relational table to graph entity
source:
type: database
table: employee
relationships:
- name: WORKS_AT
source: company_id (foreign key)
target: Company entity
Pattern: Map CSV columns to graph properties
source:
type: csv
file: data/employees.csv
delimiter: ","
entity:
identifier: person_id (unique column)
properties:
- source: name
target: foaf:name
Pattern: Map JSON properties to graph structure
source:
type: json
path: $.employees[*]
entity:
identifier: $.id
properties:
- source: $.name
target: http://example.org/name
Pattern: Handle nested structures
source:
type: json
path: $.employees[*]
relationships:
- name: HAS_ADDRESS
source: $.address (nested object)
target: Address
inline: true
mapping: PersonMapping
version: 1.0
source:
type: csv
file: people.csv
entity:
type: Person
identifier: person_id
properties:
- source: name
target: foaf:name
- source: email
target: foaf:mbox
relationships:
- name: WORKS_AT
source: company_id
target: Company
@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix ex: <http://example.org/> .
ex:EmployeeMapping a rr:TriplesMap ;
rr:logicalTable [ rr:tableName "employee" ] ;
rr:subjectMap [
rr:template "http://example.org/person/{id}" ;
rr:class foaf:Person
] ;
rr:predicateObjectMap [
rr:predicate foaf:name ;
rr:objectMap [ rr:column "name" ]
] ;
rr:predicateObjectMap [
rr:predicate foaf:workplaceHomepage ;
rr:objectMap [
rr:parentTriplesMap ex:CompanyMapping ;
rr:joinCondition [ rr:child "company_id" ; rr:parent "id" ]
]
] .
version: 1.0
mappings:
- name: PersonMapping
source:
type: database
table: person
entity:
type: Person
id: person_id
properties:
name: name
email: email_address
relationships:
works_at:
target: Company
foreign_key: company_id
Relational → RDF Type Mapping
INTEGER → xsd:integer
VARCHAR → xsd:string
DATE → xsd:date
DECIMAL → xsd:decimal
BOOLEAN → xsd:boolean
concat(field1, field2) - Concatenate fields
uppercase(field) - Convert to uppercase
lowercase(field) - Convert to lowercase
substring(field, 0, 5) - Extract substring
replace(field, old, new) - Replace values
regex(field, pattern) - Regex matching
split(field, delimiter) - Split string
trim(field) - Remove whitespace
✓ Use consistent URI templates
✓ Choose meaningful identifiers
✓ Document mapping rationale
✓ Normalize property names
✓ Handle missing values explicitly
✓ Test mappings with sample data
✓ Version mapping configurations
✓ Document transformations
✓ Validate schemas before mapping
✓ Keep mappings reusable
Generated mappings are used by:
See mapping-patterns.md for detailed mapping design patterns and example-mappings.md for complete real-world examples.
Version: 1.0.0