Complete TARQL-based conversion system for transforming SQL Server HR database to RDF using SHACL 1.2 schema.
- hr_database_shacl.ttl - SHACL 1.2 schema defining the RDF structure
- hr_database.sql - Original SQL Server DDL for reference
- convert_all.sh - Master bash script to run all conversions
- CONVERSION_GUIDE.md - Comprehensive step-by-step conversion guide
- TARQL_QUICK_REFERENCE.md - Quick reference for TARQL patterns
11 SPARQL CONSTRUCT queries for converting each table:
01_departments.tarql- Departments table02_positions.tarql- Positions table03_employees.tarql- Employees table (main)04_employeepositions.tarql- Position assignments05_salaries.tarql- Salary history06_benefits.tarql- Benefit plans07_employeebenefits.tarql- Benefit enrollments08_timeoffrequests.tarql- Time off requests09_performancereviews.tarql- Performance reviews10_trainingcourses.tarql- Training courses11_employeetraining.tarql- Training completions
departments.csv- Sample department dataemployees.csv- Sample employee data
-- Run in SQL Server Management Studio
USE HumanResources;
-- Export each table to CSV
-- See CONVERSION_GUIDE.md for complete export scriptsyour-project/
βββ tarql/ # TARQL query files (from this package)
βββ csv/ # Your exported CSV files
β βββ departments.csv
β βββ positions.csv
β βββ employees.csv
β βββ ... (all 11 tables)
βββ convert_all.sh # Conversion script
# Make script executable
chmod +x convert_all.sh
# Run conversion
./convert_all.sh
# Output will be in output/ directory# Using pyshacl
pyshacl -s hr_database_shacl.ttl \
-d output/hr_database_complete.ttl \
-f humanThe conversion transforms 11 SQL tables into RDF:
Core Entities:
- Departments (organizational units)
- Positions (job definitions)
- Employees (personnel records)
Relationships:
- EmployeePositions (assignment history)
- Salaries (compensation history)
Benefits & Training:
- Benefits (available plans)
- EmployeeBenefits (enrollments)
- TrainingCourses (catalog)
- EmployeeTraining (completions)
Activities:
- TimeOffRequests (leave management)
- PerformanceReviews (evaluations)
All entities get unique IRIs following this pattern:
http://example.org/hr/{table}/{id}
Examples:
<http://example.org/hr/employee/1001>
<http://example.org/hr/department/5>
<http://example.org/hr/salary/9876>SQL columns β RDF properties via sh:codeIdentifier:
# SQL Column: FirstName
# RDF Property: hr:firstName
# Defined in SHACL as:
hr-shape:Employee-firstName a sh:PropertyShape ;
sh:path hr:firstName ;
sh:codeIdentifier "FirstName" ; # Maps to SQL column
sh:datatype xsd:string .SQL foreign keys β RDF object properties:
-- SQL
ManagerEmployeeID INT FOREIGN KEY REFERENCES Employees(EmployeeID)# RDF
<http://example.org/hr/department/1>
hr:managerEmployee <http://example.org/hr/employee/1001> .Each TARQL query follows this pattern:
PREFIX hr: <http://example.org/hr/ontology#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
CONSTRUCT {
# Generate RDF triples
?iri a hr:ClassName ;
hr:property ?value .
}
WHERE {
# Bind IRI from primary key
BIND(URI(CONCAT("http://example.org/hr/table/", STR(?ID))) AS ?iri)
# Cast datatypes
BIND(xsd:integer(?ID) AS ?value)
# Handle optional fields
BIND(IF(BOUND(?OptionalColumn) && ?OptionalColumn != "",
xsd:string(?OptionalColumn),
?UNDEF) AS ?optionalValue)
# Create foreign key references
BIND(URI(CONCAT("http://example.org/hr/employee/", STR(?EmployeeID)))
AS ?employeeIri)
}- First row: Column headers matching SQL column names
- Delimiter: Comma (
,) - Encoding: UTF-8
- Line endings: Unix (LF) or Windows (CRLF)
- Integers: Plain numbers (e.g.,
1001) - Decimals: Use period (e.g.,
50000.00) - Strings: No quotes needed (unless contain comma)
- Dates: ISO format
YYYY-MM-DD - DateTimes: ISO format
YYYY-MM-DD HH:MM:SS - Booleans:
1/0ortrue/false - NULL values: Leave blank
DepartmentID,DepartmentName,DepartmentCode,ManagerEmployeeID,Budget,CreatedDate,ModifiedDate
1,Information Technology,IT,1001,500000.00,2024-01-01 09:00:00,2024-01-01 09:00:00
2,Human Resources,HR,,250000.00,2024-01-01 09:00:00,2024-01-01 09:00:00Input CSV:
EmployeeID,FirstName,LastName,Email,HireDate,EmployeeStatus
1001,John,Doe,jdoe@example.com,2020-01-15,ActiveOutput RDF (Turtle):
<http://example.org/hr/employee/1001> a hr:Employee ;
hr:employeeId 1001 ;
hr:firstName "John" ;
hr:lastName "Doe" ;
hr:email "jdoe@example.com" ;
hr:hireDate "2020-01-15"^^xsd:date ;
hr:employeeStatus "Active" .Convert SQL data to RDF for integration with semantic web applications
Build an enterprise knowledge graph from relational data
Enable powerful graph queries over your HR data
Publish HR data as linked data with proper semantics
Use SHACL to validate data quality and business rules
- TARQL_QUICK_REFERENCE.md - Common patterns and examples
- CONVERSION_GUIDE.md - Detailed step-by-step guide
- hr_shacl_usage_guide.md - SHACL schema usage
- TARQL - Converts CSV to RDF using SPARQL CONSTRUCT
- SHACL - Validates RDF structure and constraints
- IRI Construction - Unique identifiers for all entities
- Foreign Keys - Mapped to RDF object properties
- Type Casting - SQL types β XSD datatypes
- TARQL 1.2+ - CSV to RDF converter
wget https://github.com/tarql/tarql/releases/download/v1.2/tarql-1.2.tar.gz
-
pyshacl - Python SHACL validator
pip install pyshacl
-
Apache Jena - Java-based RDF tools
wget https://dlcdn.apache.org/jena/binaries/apache-jena-4.10.0.tar.gz
- Export SQL Server tables to CSV files
- Verify CSV format (headers, encoding, delimiters)
- Place CSV files in
csv/directory
- Review TARQL queries in
tarql/directory - Customize IRI base if needed (default:
http://example.org/hr/) - Run
./convert_all.sh - Check
output/directory for generated Turtle files
- Validate individual table files
- Validate combined output
- Check for constraint violations
- Fix any data quality issues
- Load RDF into triple store (Fuseki, GraphDB, Stardog)
- Set up SPARQL endpoint
- Create sample queries
- Enable RDFS/OWL inference if desired
Edit TARQL queries to use your domain:
# Before
BIND(URI(CONCAT("http://example.org/hr/employee/", STR(?EmployeeID))) AS ?empIri)
# After
BIND(URI(CONCAT("https://mycompany.com/hr/employee/", STR(?EmployeeID))) AS ?empIri)- Add property to SHACL schema
- Add BIND clause to TARQL query
- Map to appropriate CSV column
TARQL queries can include data transformations:
# Uppercase department codes
BIND(UCASE(?DepartmentCode) AS ?deptCode)
# Concatenate name fields
BIND(CONCAT(?FirstName, " ", ?LastName) AS ?fullName)
# Calculate derived values
BIND(?MaxSalary - ?MinSalary AS ?salaryRange)Empty output files
- Check CSV headers match query variables
- Verify file encoding is UTF-8
- Check for BOM (Byte Order Mark) in CSV
Invalid IRIs
- Ensure no spaces in ID columns
- Check for special characters
- Verify IDs are not empty
Type casting errors
- Use ISO date format: YYYY-MM-DD
- Remove currency symbols from numbers
- Use 1/0 or true/false for booleans
Missing triples
- Check optional field handling
- Verify foreign key references exist
- Look for empty vs. NULL values
# Get detailed error report
pyshacl -s hr_database_shacl.ttl \
-d output/hr_database_complete.ttl \
-f human \
--debug > validation_errors.txtCommon violations:
sh:minCount- Missing required propertiessh:datatype- Incorrect data typessh:pattern- Format validation failuressh:class- Invalid foreign key references
- 10K employees: ~2 seconds
- 50K employees: ~8 seconds
- 100K employees: ~15 seconds
- 1M employees: ~2.5 minutes
- Process tables in parallel
- Use TARQL's
--ntriplesfor large datasets - Validate incrementally
- Use SSD for CSV files and output
- Check CONVERSION_GUIDE.md for detailed instructions
- Review TARQL_QUICK_REFERENCE.md for patterns
- Examine sample CSV files for format examples
- Test with small datasets first
This conversion package is provided as-is for use with your HR database conversion project.
After successful conversion:
-
Explore with SPARQL
SELECT ?emp ?name WHERE { ?emp a hr:Employee ; hr:firstName ?name . } LIMIT 10
-
Create Visualizations
- Use GraphDB's Visual Graph
- Build custom dashboards
- Generate org charts
-
Add Inference Rules
- Define derivations
- Add business logic
- Create computed properties
-
Integrate Systems
- Connect to reporting tools
- Expose SPARQL endpoint
- Enable federated queries
For questions about this conversion package, refer to the included documentation files or review the SHACL schema for data model details.
Version: 1.0
Created: 2026-02-19
SHACL Version: 1.2
TARQL Version: 1.2+