Skip to content

SPARQL Query Language

SPARQL (SPARQL Protocol and RDF Query Language) is the W3C standard query language for RDF (Resource Description Framework) data. Grafeo implements SPARQL 1.1 for querying RDF graphs.

Overview

SPARQL uses triple patterns to match RDF data. It's designed for querying semantic web data and knowledge graphs.

Quick Reference

Operation Syntax
Select variables SELECT ?x ?y
Match triples ?s ?p ?o
Filter results FILTER(?x > value)
Optional patterns OPTIONAL { ?s ?p ?o }
Union patterns { ... } UNION { ... }
Aggregate COUNT(?x), SUM(?x)
Order results ORDER BY ?x
Limit results LIMIT 10

RDF Data Model

Unlike property graphs (LPG), RDF uses triples:

Subject --Predicate--> Object

Example triples:

<http://example.org/alice> <http://xmlns.com/foaf/0.1/name> "Alice" .
<http://example.org/alice> <http://xmlns.com/foaf/0.1/knows> <http://example.org/bob> .

Enabling SPARQL

SPARQL support requires the sparql feature flag:

[dependencies]
grafeo-engine = { version = "0.1", features = ["sparql"] }
# SPARQL is enabled by default in the Python package
import grafeo

Learn More