Skip to content

Starting in CLI

This guide needs Cargo. Install Rust and Cargo if it is not already available.

Install sparqld with Cargo:

Command

cargo install sparqld

Install ktk/sq to send the query:

Command

cargo install zazuko-sq

Serve a directory

Create a directory for the data:

Command

mkdir -p data

In your editor, create data/alpha-centauri.md and paste this source:

Source alpha-centauri.md

---
"@context":
  schema: https://schema.org/
  dbo: http://dbpedia.org/ontology/
  dbp: http://dbpedia.org/property/
  dbr: http://dbpedia.org/resource/
  $: schema:name
  constellation:
    "@id": dbo:constellation
    "@type": "@id"
  contains:
    "@id": schema:hasPart
    "@type": "@id"
  is-orbited-by:
    "@reverse": dbp:star
$id: dbr:Alpha_Centauri
$: Alpha Centauri
schema:description: The closest star system to the Solar System.
constellation:
  $id: dbr:Centaurus
  $: Centaurus
contains:
  - $: Alpha Centauri AB
    contains:
      - $type: dbo:Star
        $: Alpha Centauri A
      - $type: dbo:Star
        $: Alpha Centauri B
    is-orbited-by:
      - $id: dbr:Proxima_Centauri
        $type: dbo:Star
        $: Proxima Centauri
        is-orbited-by:
          - $id: dbr:Proxima_Centauri_b
            $type: dbo:Planet
            $: Proxima Centauri b
          - $id: dbr:Proxima_Centauri_d
            $type: dbo:Planet
            $: Proxima Centauri d
---

# Alpha Centauri

Alpha Centauri is the closest star system to the Solar System.

Start sparqld in this terminal:

Command

sparqld --directory ./data http

Keep this terminal running. The endpoint is available at http://127.0.0.1:7737/ and watches the directory for changes.

Query the endpoint

Open a second terminal. This query shows what orbits what in the example.

Save it as orbits.rq:

Source orbits.rq

PREFIX schema: <https://schema.org/>
PREFIX dbp: <http://dbpedia.org/property/>

SELECT ?body ?orbits
WHERE {
  ?bodyResource dbp:star ?parent .
  ?bodyResource schema:name ?body .
  ?parent schema:name ?orbits .
}
ORDER BY ?body

Run it with sq:

Command

sq -e http://127.0.0.1:7737/ -f orbits.rq

Result orbits.tsv

Proxima Centauri    Alpha Centauri AB
Proxima Centauri b  Proxima Centauri
Proxima Centauri d  Proxima Centauri

Each row is a body followed by what it orbits.

Queries are read-only, so exploring the dataset cannot modify your files.

See a live update

In data/alpha-centauri.md, change Alpha Centauri to a new name and save the file. Run the same sq command again: the result changes without restarting sparqld.

Browse the compatible SPARQL clients for other ways to query the endpoint, or prefer Starting with Agents for the skill-based path.