Skip to content

Query a model

The Query page answers a question about one model. You write a SPARQL query, choose Run, and the answer comes back as a table: one column per variable you asked for, one row per solution. Results that are elements of your model link straight to them, so an answer stays connected to the model it came from.

Use it for questions the model tree cannot show you at a glance — “which classes have no definition?”, “how many attributes does each class have?”, “every concept with its broader concept” — and for checking what your model actually contains before an export or a transformation.

The query runs in your browser, over the model as it is rendered in RDF, so no query is ever sent anywhere. Nothing is saved either: the query you wrote comes back while you stay in the same browser session, and its answer comes back with it while the model is unchanged and you have not reloaded the page — so opening an element from a result and returning costs you neither.

  • A model you can open in ModelDesk, written in a standard that supports querying, and owned by an organization that has SPARQL enabled. Query appears in the left navigation only for those models.
  • Some familiarity with SPARQL. The SPARQL reference lists what ModelDesk supports and what it rejects.
  1. Open your model and choose Query in the left navigation. The model tree stays on the left, and the query editor takes the rest of the page, with the query language named beside the Query heading.

  2. Write your query, or start from a worked example: choose Templates and pick one under Example queries. Every statement shows the raw graph, Types, and how many of each counts the resources per type, Everything with a label lists each labelled resource, and Anything without a label shows the ones that have none. The example is inserted into the editor, where you can change it before running it.

  3. While you write, the editor helps in four ways. A query ModelDesk cannot answer is underlined where the problem is. Typing offers completions for the predicates your model actually uses, so you do not have to know its vocabulary by heart. When you type a prefix the editor knows, such as skos:, it adds the PREFIX line for you. See Prefixes. And Format, in the editor’s top-right corner, lays a long query out over lines; Shift+Alt+F (⇧⌥F on a Mac) does the same from inside the editor. Formatting changes only line breaks and indentation, so the query still asks the same thing and keeps your comments.

  4. Choose Run, or press Ctrl/Cmd + Enter from inside the editor. Nothing runs while you type: a query is evaluated only when you ask for it. Just after the page opens the button is disabled and the header says Preparing the model…, while the model is being made ready to query.

  5. Read the answer. Each column is headed by the variable you projected. A result ModelDesk renders as an element of this model shows the label you know it by; a term from a vocabulary your model uses shows as a short name (rdfs:Resource), and where its IRI is a web address it opens there in a new tab; a value shows as text, with its language tag beside it where it has one. A variable that was left unbound — an OPTIONAL that found nothing — shows as —.

  6. Select a result to place it in the model tree on the left: the tree opens the path to it, so you can see where the answer sits without leaving your query. To open it in the editor instead, use Edit name in the header, or Ctrl/Cmd-click the result to open the editor in a new tab.

  7. Drag the right edge of a column heading to make a column wider or narrower. The other columns hold still while you drag. The edge takes keyboard focus too, and the arrow keys move it.

The Query page with the model tree, a SPARQL query in the editor, and the answered result table

Above the table, ModelDesk states what the answer holds: 12 rows, or 12 rows · 20 solutions when the query returned identical solutions that were folded into one row. Such a row carries a ×n badge under Count, rather than being repeated as indistinguishable lines.

Large answers are drawn up to a point: at most 500 rows appear, and the summary says so — Showing 500 of 12,483 rows, with the hint Add LIMIT and OFFSET to page through the rest. The whole answer is computed; only the table is limited, so the numbers you read are the true ones.

An ASK query answers Yes or No instead of a table. A SELECT that matched nothing says No solutions., which is different from a query you have not run yet.

The answer is a statement about the model as it was when you ran the query. If the model changes, the table is cleared: its links and values described the previous version. Otherwise it stays with you — open an element from a result, come back, and both your query and its answer are as you left them. Reloading the page keeps the query and drops the answer, which you can run again.

A prefixed name such as skos:broader works only when the query declares its prefix in a PREFIX line at the top. The editor writes those lines for you. When you type skos: in a query that has no PREFIX line for skos, it adds PREFIX skos: <http://www.w3.org/2004/02/skos/core#> below the PREFIX and BASE lines already at the top of the query. One undo removes the line together with what you typed. Text you paste or drag in gets a line for each prefix it uses. A screen reader announces what was added, for example Declared prefix skos.

The editor looks a prefix up in this order, and the first place that knows it wins:

  1. the PREFIX lines in your query;
  2. your model’s namespaces, set on the Model settings page;
  3. the namespaces of the models your model depends on;
  4. the namespaces of your model’s metamodel;
  5. public lists of well-known prefixes. They ship with ModelDesk, so looking up a prefix contacts no other site.

A prefix none of these knows gets no line, and you write it yourself (see If this goes wrong).

Where the completion popup offers terms, it also offers the prefixes that match the name you are typing, under a Prefixes heading below the terms. The panel beside the highlighted prefix shows its namespace, and for a prefix from your query or your models also where it comes from: Query, Model, the dependency’s name or Metamodel. Accepting a prefix writes it, adds its PREFIX line when the query has none, and opens the popup again for the rest of the name. Prefixes from the public lists appear from the second character you type, so a single letter does not list thousands of them.

A PREFIX line you write yourself completes too. After PREFIX , the popup offers the prefixes the editor knows that your query does not declare yet, each with its namespace, and accepting one writes both. After PREFIX skos: , it offers every namespace the sources bind skos to: first those from your model, its dependencies and its metamodel, each with its source beside it, then those from the public lists. This is where you choose when your model and a public list disagree about a prefix.

Terms you accept from the popup are written the same way. When one of the sources has a prefix for a term’s namespace, the term goes in as a short name such as skos:prefLabel, with its PREFIX line. Otherwise it goes in as its full IRI in angle brackets.

  • There is no Query item in the navigation. Either the standard your model is written in has no query support, or SPARQL is not enabled for the organization that owns the model. Opening the page by its address tells you which of the two it is.
  • The page says Querying is not available. The standard your model is written in has no query support. This is a property of the standard, not of your model or your account.
  • The page says Feature not enabled. The standard supports querying, but SPARQL is an organization feature, and the organization that owns the model does not have it. ModelDesk support can enable it for that organization.
  • A red box below the editor explains the query. ModelDesk refused it, and the message names what it cannot answer — see Not supported for the constructs on that list and the usual way to rewrite around them. Editing the query clears the message.
  • Part of the query is underlined. The same check, while you write. Hover the underline to read what it says.
  • The underline says a prefix is unknown. Hovering it reads Invalid SPARQL query: Unknown prefix: skos: the query uses skos: without a PREFIX line for it. The editor adds that line as you type a name, but not when you change the prefix of a name already in the query, and not for a prefix it does not know. If one of the sources knows the prefix, the hover offers a Declare skos: button, which adds the line. If none does, there is no button: write the line yourself at the top of the query, with the namespace the vocabulary uses, for example PREFIX acme: <https://example.org/def/acme#>.
  • No solutions, where you expected some. Most often the query asks for terms from a vocabulary your model is not rendered in. Run Every statement to see what is actually there, and build the query from what it shows. The predicates the completion popup offers are the ones your model uses.
  • A result is plain text rather than a link. That resource is not an element of this model — a term from a vocabulary it uses, or a value. Terms whose IRI is an http/https address can still be followed in a new tab; other names (a urn:, a blank node) have nowhere to lead.
  • The page is briefly unresponsive. The query is evaluated in your browser, so a pattern that has to combine everything with everything takes as long as it takes. Narrow the pattern — name a type, add a FILTER — rather than only adding a LIMIT, which limits the answer but not the work.