Skip to content

SPARQL & Ontology

ThinkERD converts ERD structures into ontology (RDFS/OWL) in real time, enabling SPARQL queries for semantic analysis.

SPARQL Editor Screen Screen showing the SPARQL query editor and ontology mapping results

Overview

While standard SQL focuses on "how to store data," SPARQL focuses on "how to explore the relationships and meaning between data."

graph LR
    ERD["📊 ERD Model"] -->|"R2RML conversion"| OWL["🌐 RDFS/OWL"]
    OWL -->|"Load"| OX["🔍 Query Engine"]
    OX -->|"SPARQL query"| R["📋 Results"]

SQL vs SPARQL Comparison

Aspect SQL SPARQL
Target Table data Ontology (semantic graph)
Question "What is this data's value?" "What is the relationship between these concepts?"
Strength CRUD, aggregation Semantic exploration, structural analysis
ThinkERD usage Mock data analysis Analyzing the ERD structure itself

ERD → Ontology Mapping

ERD structural elements are automatically converted to ontology concepts:

ERD Ontology Description
Entity owl:Class Class definition
Column owl:DatatypeProperty Data property
PK owl:FunctionalProperty Functional property (ensures uniqueness)
Relationship (FK) owl:ObjectProperty Object relationship
Subtype rdfs:subClassOf Class inheritance

Using the SPARQL Scratchpad

Select the SPARQL tab in Data Lab to open the SPARQL editor.

Basic Query Examples

SELECT ?class ?label WHERE {
  ?class a owl:Class .
  ?class rdfs:label ?label .
}
Queries all entities defined in the ERD as ontology classes.

SELECT ?prop ?label ?type WHERE {
  ?prop rdfs:domain <#Customer> .
  ?prop rdfs:label ?label .
  ?prop rdfs:range ?type .
}
Queries all columns (properties) of the Customer entity.

SELECT ?source ?target WHERE {
  ?rel a owl:ObjectProperty .
  ?rel rdfs:domain ?source .
  ?rel rdfs:range ?target .
}
Finds all entity pairs connected by FK.

Practical Analysis Scenarios

Determine which other entities are affected when a specific entity changes.

# All entities directly/indirectly connected to 'Customer'
SELECT ?related ?label WHERE {
  { ?rel rdfs:domain <#Customer> . ?rel rdfs:range ?related . }
  UNION
  { ?rel rdfs:range <#Customer> . ?rel rdfs:domain ?related . }
  ?related rdfs:label ?label .
}

Find "isolated" entities that have no relationships with any other entity.

SELECT ?class ?label WHERE {
  ?class a owl:Class .
  ?class rdfs:label ?label .
  FILTER NOT EXISTS {
    { ?rel rdfs:domain ?class . ?rel a owl:ObjectProperty . }
    UNION
    { ?rel rdfs:range ?class . ?rel a owl:ObjectProperty . }
  }
}

Explore class hierarchies through subtype (inheritance) relationships.

SELECT ?parent ?child WHERE {
  ?child rdfs:subClassOf ?parent .
}

Model Explorer

The Model Explorer in the global right-side inspector panel lets you browse the current diagram's ontology structure in a tree format.

  • View class (entity) hierarchy structure
  • View property (column) lists
  • View relationship (FK) structure
  • Use as vocabulary reference when writing SPARQL queries

New to SPARQL?

Don't worry if you're unfamiliar with SPARQL. Check the entity and attribute structure in the Model Explorer, then copy the example queries above and just change the entity names. Gradually modify queries to become comfortable with graph querying.