Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

SPARQL

The SPARQL tab runs read-only SPARQL 1.1 SELECT and ASK queries, either against your current work or against a deployment, without leaving the editor.

Video 3.1 · Facts, rules and SPARQL, chapter “The SPARQL console” (1:10–1:45). Watch on PeerTube

Choosing what to query

The first drop-down picks the data:

ChoiceQueries
Live: current package (default)The project as it is saved right now, compiled on the fly: schema and facts. Nothing needs to be deployed.
v3 · 1a2b3c4d · 120 triplesOne of the project’s deployments: its schema, facts and all the data written to it through the API. (inactive) marks a deployment that is not active.

In both cases the project’s rules and its reasoning profile are applied, so inferred triples are part of the answer. A deployment uses the profile it was deployed or last updated with, the live entry the current one.

Writing and running a query

  • The @prefix declarations of the Turtle tab are added to your query for you, so you can write ex:Book without a PREFIX line. For a deployment, they use the IRIs that deployment was published with.
  • Run the query with the button or Ctrl+Enter (⌘+Enter on a Mac).
  • A SELECT shows a table. IRIs are shortened to prefix:name and quantities shown as value unit; hover a cell for its full value. An ASK shows ASK → true or false. To show a SELECT another way, see Result views.

Result views

The drop-down left of Download CSV picks how the result is shown. Table is always there. Graph appears for a SELECT with at least one IRI or blank node. Other views appear when the shape of the result fits them (below).

After a run, the panel shows the first view that fits the result, in the order Histogram, KPI, Line chart, Calendar heatmap, Bar chart, then Scatter but only when none of those fits, else the table. Graph, Matrix and Kanban are never picked for you, and Donut only for a COUNT or SUM (see below). A view you pick yourself is kept when you run the query again, including the live re-run on save, as long as the new result offers it; picking Table keeps the table. If the new result doesn’t offer your pick any more (for example Graph and a result with no IRI or blank node, an error or an ASK), the panel forgets it and picks for you again. The drop-down is greyed out while a query runs.

Besides the column types, the panel also reads the query itself: the outer GROUP BY and the aggregate behind each column (COUNT, SUM, AVG, MIN, MAX, SAMPLE, GROUP_CONCAT). This is what picks Donut for a COUNT or SUM, and Histogram for an integer key with a COUNT. Only the outermost SELECT is read: aggregates inside a sub-select, and expressions such as (COUNT(?x) + 1 AS ?n), count as plain columns. The result shows at once; the analysis arrives a moment later and may switch the view then, but never a view you picked yourself. If the query cannot be analysed, or the analysis fails, the view is chosen from the column types alone.

For a column whose cells are all IRIs, the panel also looks up whether they are the variants of an enum (a one of concept), in their declared order; this is what offers the Kanban view.

Choosing the view from the query

A comment line # view: <name> anywhere in the query picks the view the results open in, for example:

# view: bar
SELECT ?status (COUNT(?o) AS ?orders) WHERE { ?o ex:status ?status } GROUP BY ?status

Names: table, graph, kpi, line, calendar, bar, donut, histogram, scatter, matrix, kanban. Case and spaces do not matter (#VIEW:Bar), and text after the name is ignored.

  • Only the first # view: line counts. If its name is unknown, it is ignored.
  • The line must start with #: a # inside an IRI or a string, or after other text on the line, is not read.
  • A view that does not fit the result (for example kpi on several rows, or graph with no IRI or blank node) is ignored without a message, and the panel picks for you as above. Graph, Donut, Matrix and Kanban can be asked for this way.
  • Running a new or edited query opens on its # view: view, even after you picked another one. Running the same query again keeps a view you picked yourself.
  • Switching views never edits your query: the line stays as you wrote it, in the editor and in saved queries.

It works the same for saved and pasted queries. Named Dolfin queries will honour it once their generated SPARQL carries the line.

Graph

Graph swaps the table for an instance graph of every IRI in the results (all rows, all columns; literals are left out). Blank nodes are drawn too, dashed, with their links and literal values. It is the same drawing as the Instances tab: drag a node, hover to zoom and see its literal values, concept colours as picked there. Links are the properties between two result nodes. They follow the same merging and hiding rules as the Instances tab; Show all links, under the graph, turns them off (the choice is shared with the Instances tab). The Hierarchy picker shows above the graph too; its pick is shared with the Instances tab. Pick Table to go back. The graph follows a re-run, including the live re-run on save; if the new result has no IRI or blank node, the panel picks for you again. The download buttons still save the table. Large results (hundreds of nodes) lay out slowly.

Blank nodes are fetched by running the query again in the same request. If it uses LIMIT without ORDER BY, or sorts on a blank-node column, the graph may show other blank nodes than the table on the live package. A query with FROM, or a blank node bound inside GRAPH ?g, shows blank nodes without their links.

KPI

KPI appears when the result is exactly one row and every column is a number (xsd:integer, decimal, double, float and the derived integer types). One column shows as a big tile with the value over its ?name; several columns show as a strip of tiles. Values are shown as in the table; hover a tile for the raw value. An unbound cell doesn’t count against its column, but a column with no value, a text or IRI value, or a unit-bearing quantity ("42"^^unit:km) gives no KPI. The download buttons still save the table.

SELECT (COUNT(?b) AS ?books) WHERE { ?b a ex:Book }

Line chart

Line chart appears for a SELECT of 2 to 2000 rows with a column of dates (xsd:date, xsd:dateTime, xsd:gYear or xsd:gYearMonth; dates and date-times may be mixed in one column) and at least one numeric column (numbers as for KPI). If several columns hold dates, the first one is the time axis, and only that one has to be readable: if one of its values cannot be read as a date ("2024-13-45"^^xsd:date), the line chart is not offered for that result.

Each point is placed at its date: a gYear at 1 January of that year, a gYearMonth at the 1st of the month. A date’s timezone (2024-03-01Z, 2024-03-01+01:00) is accepted but not applied, so the point stays on the day as written; a date-time is placed at its UTC instant, and a date-time without a timezone is read as UTC.

Points are drawn in time order. Missing dates are not filled in: the line joins the points that exist. Each numeric column is its own line, in its own colour, named in the legend below the chart. An empty cell (or one that is not a number) is skipped for that line only; a row with no date is left out. The y axis always includes 0, so negative values go below the zero line. The x axis shows the first and last date and a few in between, as precise as the data: years only when every value is a year, months for year-months, hours and minutes when there is a date-time. Hover a point for its date as written and its value, with units as in the table. The footer counts the points drawn. The download buttons still save the table.

SELECT ?day (COUNT(?o) AS ?orders) WHERE { ?o ex:orderedOn ?day } GROUP BY ?day ORDER BY ?day

Calendar heatmap

Calendar heatmap appears next to Line chart (right after it; the line chart stays the one shown by default) when the result has exactly one numeric column besides its date column, and that column holds days:

  • every value is an xsd:date, or an xsd:dateTime exactly at midnight (T00:00:00; T00:00:00.000 counts too). A date-time like T00:00:01 or T12:00:00 means no calendar for that result. Dates and midnight date-times may be mixed;
  • no day appears twice (a date and a midnight date-time of the same day count as twice);
  • the last day minus the first day is 60 to 800 days (2024-01-01 to 2024-03-01 is 60).

A year (xsd:gYear), a year-month (xsd:gYearMonth) or any value that cannot be read as a date rules it out. The timezone is ignored: the day is the one written, so 2024-03-01T00:00:00+01:00 is 1 March and 2024-03-01Z too. A row with no date is left out. The view is offered on the span alone, so a few rows over a long span still get one, mostly grey.

Each week is a column, Monday at the top, with Mon, Wed and Fri on the left and the month names above the week where each month starts. Each day is a square in one of five shades of green by quintile of the values: the largest values are the darkest, values that are all equal are all the darkest, and 0 or negative values are shaded like any other. A day of the span with no row, or no value, is grey. Days before the first date and after the last one are not drawn. The legend below goes from Less to More, then No data. Hover a square for its date and value, with units as in the table. The footer counts the days with a row. A long span makes a wide grid: the results area scrolls. The download buttons still save the table.

# view: calendar
SELECT ?day (COUNT(?o) AS ?orders) WHERE { ?o ex:orderedOn ?day } GROUP BY ?day

Bar chart

Bar chart appears for a SELECT of 2 to 50 rows with exactly one column of IRIs, text or booleans (the key) and at least one numeric column (numbers as for KPI). A key column mixing IRIs and text counts as text. It is not offered for a date or dateTime key, two text or IRI columns, only numbers, or fewer than 2 or more than 50 rows. A column that is never bound (an OPTIONAL that never matches) counts as text: next to another key it rules the chart out; alone, every bar is (none).

Each row is one bar (rows are not added together), sorted from the largest value to the smallest, so it doubles as a leaderboard. Keys are shortened to prefix:name as in the table; an unbound key shows (none). The value is shown as in the table. Long labels are cut with …: hover a bar for its full key and value. Negative values go left of the zero line, in red; positive ones right, in blue. Rows with no value in the measure are left out and counted in the footer (N bar(s) · M skipped (no value)).

With several numeric columns, a drop-down above the chart picks the one the bars measure. It starts on the first numeric column for each new result. Many rows make a tall chart: the results area scrolls. The download buttons still save the table.

SELECT ?author (COUNT(?b) AS ?books) WHERE { ?b ex:author ?author } GROUP BY ?author

Donut

Donut appears for a result that has the bar chart’s shape (one key column of IRIs, text or booleans; an unbound key counts as (none)) with 2 to 7 rows, when a numeric column holds whole numbers (xsd:integer or a derived type: int, long, nonNegativeInteger…) in every row, all 0 or more and not all 0. A decimal, a negative value, an empty cell or more than 7 rows in that column rule it out for that column.

It is picked for you, instead of the bar chart, only when the query says that column is a COUNT or SUM (parts of a whole). With MIN, MAX or AVG, a column computed by an expression, or when the query cannot be analysed, it stays in the drop-down only: MIN and MAX give whole numbers too, and a donut of maxima is misleading.

Each row is one slice, largest first as in the bars, with the total in the middle (shown as in the table). The legend gives each key and its share of the total, for example Alice 42%: a tiny slice shows <1%, and shares are rounded, so they may not add up to 100. A row at 0 is listed in the legend without a slice. Hover a slice or a legend entry for its full key and value. Colours follow the theme.

With several whole-number columns that qualify, a drop-down above the donut picks the one it measures; columns that do not qualify are not listed. The download buttons still save the table.

SELECT ?status (COUNT(?o) AS ?orders) WHERE { ?o ex:status ?status } GROUP BY ?status

Histogram

Histogram appears when the query groups by exactly one variable (GROUP BY ?age), that column holds whole numbers (xsd:integer or a derived type) and another column is a COUNT, with 2 to 50 rows. Each key value is one bar, in ascending key order (1, 2, 10, not by count); an unbound key is (none), last. Hover a bar for its key and count. It is picked for you, before a scatter, the line chart or any other chart. It needs the query’s analysis (see Result views): without it, or with a SUM, a decimal key, a GROUP BY on more variables than one (even ones not selected), or a key value that repeats, it is not offered. The download buttons still save the table.

SELECT ?age (COUNT(?p) AS ?people) WHERE { ?p ex:age ?age } GROUP BY ?age

Scatter

Scatter appears for a SELECT of 2 to 2000 rows with 2 or 3 numeric columns (numbers as for KPI). The first numeric column is the x axis, the second the y axis, and a third, if any, sizes the bubbles: the smallest value gets the smallest bubble, the largest the biggest. Other columns (keys, dates) are ignored. With 4 or more numeric columns, fewer than 2 rows or more than 2000, it is not offered: rows are never cut to fit.

Each row is one point. A row with an empty cell, or a value that is not a number, in one of the plotted columns is left out and counted in the footer (N point(s) · M row(s) skipped (unbound or non-numeric)). Each axis goes from the smallest to the largest value, with a tick at both ends, so negative and decimal values need nothing special; when every value is the same, the points sit in the middle with one tick. Hover a point for its values, with units as in the table.

It is picked for you only when no other chart fits, for example two numeric columns and no key. With a key column the bar chart is picked and Scatter stays in the drop-down; with a date column the line chart is. The download buttons still save the table.

SELECT ?height ?weight ?age WHERE { ?p ex:height ?height ; ex:weight ?weight ; ex:age ?age }

Matrix

Matrix appears for a SELECT of at least 2 rows with exactly 2 key columns (IRIs, text or booleans, as for the bar chart) and exactly 1 numeric column, when each key column has at most 30 different values. An unbound key shows as (none) and counts as one value; an IRI and a text with the same spelling are two values. Three key columns, two numeric columns, or a key with 31 values or more: not offered. A date column is ignored.

The first key gives the rows, the second the columns, in the order they first appear in the result (so ORDER BY holds). Each cell is shaded in one of five shades of green, in equal steps from the smallest to the largest value (not from 0, so negative values are shaded like any other); if every value is the same, every cell is the darkest. A pair with no row, or only rows with no value, is grey. Several rows for the same pair are added together. Keys are shortened to prefix:name as in the table; long ones are cut with … and column names are slanted so 30 fit: hover a name for the full key, a cell for A × B: value. The legend under the grid shows the value range of each shade. A big grid scrolls.

It is never picked for you: choose it in the drop-down (or # view: matrix); the table stays the default. The download buttons still save the table.

SELECT ?author ?genre (COUNT(?b) AS ?books) WHERE { ?b ex:author ?author ; ex:genre ?genre } GROUP BY ?author ?genre

Kanban

Kanban shows the rows as cards on a board, one column per variant of an enum (a one of concept). It is offered for a SELECT with exactly one column whose values are all variants of one enum (the enum lookup of Result views), plus at least one other column. It appears in the drop-down a moment after the result, once both the query analysis and the enum lookup have answered; a pick made before that is kept until they have.

It is not offered when:

  • the enum has more than 12 variants, or the result more than 500 rows;
  • the outer SELECT has a COUNT, SUM, AVG, MIN or MAX, even inside an expression such as (COUNT(?x) + 1 AS ?n), or only in HAVING. GROUP_CONCAT, SAMPLE and aggregates in a sub-select are fine;
  • the enum lookup failed or found no enum, or the query could not be analysed.

The columns follow the enum’s declared order, and a variant with no row is an empty column. When a row has no value in the enum column, a last (none) column holds it. Each card is titled by the first other column, in SELECT order; the remaining columns show below it as name: value. IRIs are shortened and quantities shown as in the table. Long text is cut with …: hover a card for every full value, a column header for the variant’s full IRI.

The board is read-only: no drag and drop. It is never picked for you, so pick it in the drop-down or ask for it in the query. The download buttons still save the table.

# view: kanban
SELECT ?room ?kind WHERE { ?r a hs:Room ; hs:name ?room ; hs:kind ?kind }

To see why a row of a query made only of triple patterns holds, use its Why? button. See Why does a fact hold?.

Downloading the results

Download CSV and Download XLSX, above the results, save the table of the last SELECT you ran as a file: the same query (with its added prefixes), the same columns in the same order, all rows. IRIs are prefix:name as in the table; in the XLSX file numbers, booleans and dates are real Excel cells. The file is named after the query picked in Saved queries…, else results. The buttons are greyed out until a SELECT succeeds; an ASK has no table to download.

It works for the live package and for a deployment, also in a public project’s read-only view. From your own code, use format=csv or format=xlsx on the deployment endpoint, see Deployments.

Saved queries

The second drop-down, Saved queries…, has two groups:

GroupWhere it comes from
◈ nameQueries declared in the project’s Dolfin source. They follow the source, unsaved edits included, and cannot be deleted from here. The server compiles the project for them when you open the tab and again after each edit; meanwhile compiling project queries… shows next to the list, and the page stays usable. When the project does not compile, a ⚠ project queries unavailable note appears; hover it for the compile error.
Plain namesQueries you saved with the save button. They are stored in this browser only. The delete button next to the list removes the selected one.

Pick a query to load it in the editor box.

Video 3.3 · Dolfin queries, opening (0:04–0:55). Watch on PeerTube

Pinning the clock

A deployment’s SPARQL endpoints (/api/data/<id>/sparql/public, see Deployments) take an optional now=<dateTime> in the URL query string, for example ?now=2026-06-15T12:00:00Z, also when the query itself is sent as the request body. It pins the clock of the package’s rules: an inferred class that uses now() (someone becoming able to vote at 18) is computed as of that instant. It is the same parameter as on the validate endpoint, so a query can reproduce a validation run. Default: the time of the request. An invalid value answers 400.

SPARQL’s own NOW() function, written in the query text, is not pinned: it is still the time of the request.

To query deployments from your own code, see the deployment’s API section in Deployments. To query them from an AI assistant, see Connecting AI assistants (MCP).