Skip to main content

DIAGNOSE

Because of SPARQL’s pattern matching semantics, it can sometimes be difficult to diagnose queries containing logical errors.  This is because if one sub-pattern fails to match--perhaps because of a typo--the entire query will likely just return 0 rows, rather than returning a useful error. To help figure out errors in SPARQL queries, data.world has created the DIAGNOSE keyword.  If you add the new keyword DIAGNOSE before any SPARQL query, data.world will effectively rewrite the query to help you better understand just which components of your query are causing problems.

Here is how it works:

  • Your query is split into smaller components, representing subpatterns of interest.

  • Each subpattern is then aggregated counting then number of results it would match in your graph.

  • Finally, the subpatterns and their counts are then composed into a report, showing the subpattern text and the number of matches for that subpattern.

Subpatterns which have zero matches are likely places to find errors.

Examples - DIAGNOSE

Here is a query that we will run with DIAGNOSE:

PREFIX : <https://ddw-doccorp.linked.data.world/d/sparql-csv-dataset/>

SELECT ?abbreviation ?city ?state
{
    ?q :col-cities-airport ?abbreviation.
    ?q :col-cities-city    ?city.
    ?q :col-cities-states  ?state.
}

Run query

This is what it looks like on data.world:

Empty_query.png

Here is the same query written using DIAGNOSE to show which sub graph patterns are empty (in this case due to a typo).

PREFIX : <https://ddw-doccorp.linked.data.world/d/sparql-csv-dataset/>

DIAGNOSE SELECT ?abbreviation ?city ?state 
{
    ?q  :col-cities-airport   ?abbreviation.
    ?q  :col-cities-city ?city.
    ?q  :col-cities-states ?state.
}

Run query

Here is what it looks like on data.world:

DIAGNOSE.png