in memory triple store
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Mini Sparql

Mini sparql is an experiment in writing a simple (in memory) triple store. It can be used to read in files or triple data, which can be queried using sparql. It's by no means complete, but does provide most of sparql 1.0.


Assuming you have triple data like:

robin name Robin .
robin size small .
robin color red .
robin color brown .
robin legs 2 .
sparrow name Sparrow .
sparrow size small .
sparrow color brown .
bluetit name Bluetit .
bluetit size small .
bluetit color blue .
bluetit color green .
eagle name Eagle .
eagle size large .
eagle color brown .

In a file called birds.ttl, then you can run minisparql and query the data:

$ python birds.ttl
sparql> SELECT ?name ?color WHERE { ?id name ?name . ?id color ?color }
name, color
'Bluetit', 'blue'
'Bluetit', 'green'
'Eagle', 'brown'
'Robin', 'brown'
'Robin', 'red'
'Sparrow', 'brown'
sparql> SELECT ?name WHERE { ?id name ?name . ?id color red }

Filters are supported too:

sparql> SELECT ?name WHERE { ?id name ?name FILTER regex(?name, "r", "i") }

As well as using the interactive prompt it is possible to execute queries via the -e switch:

$ python birds.ttl -e 'SELECT ?name WHERE { ?id name ?name FILTER regex(?name, "r", "i") }'