Page MenuHomePhabricator

Display references next to query results
Open, Needs TriagePublic


To encourage the usage of references in queries, and make it easier to embed query results in contexts that require references for the embedded information, it would be nice if the query service UI could show references for the information used in a query in a dedicated location, next to the results themselves.

My proposal would be to use one or more result columns (by default, ?reference and ?referenceLabel, but this would be configurable) for the references. The distinct values of those columns are then taken, concatenated, and shown next to the results. Afterwards, for displaying the actual results, these columns are removed, and results that have become equivalent due to this removal (i. e., result lines which had multiple references) are deduplicated.

This would allow adding references with little more than

?statement pr:P248|pr:P854 ?reference.

but the queries could also build a full reference string (label of the stated in item, chapter, page, …) in the query.

Right now, something similar is possible on the chart result views with something like this:

SELECT ?x ?y (" " AS ?dummy) ?sources WITH {
  SELECT ?x ?y ?source WHERE {
    # ...
} AS %results WITH {
  SELECT (GROUP_CONCAT(DISTINCT ?sourceLabel; separator = "; ") AS ?sources_) WHERE {
    INCLUDE %results.
    SERVICE wikibase:label {
      bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
      ?source rdfs:label ?sourceLabel.
} AS %sources WHERE {
  INCLUDE %results.
  INCLUDE %sources.
  # change “source; source; source” to “source; source; and source”, and “source; source” to “source and source”
    IF(REGEX(?sources_, "; .*;"),
       REPLACE(?sources_, "(.*); (.*)", "$1; and $2"), # the first .* is greedy, so this replaces the last ;
       REPLACE(?sources_, "(.*); (.*)", "$1 and $2"))
    AS ?sources)

But it requires the use of a dummy variable to coerce the chart view into displaying ?sources in a suitable location, as well as a convoluted construction of named subqueries to get both the individual results and, on each of them, the aggregated sources of all results.

Event Timeline

Would it be possible to add the name of the organisation producing or providing the data by stripping the URLs to just the root URLs and then 'official website (P856)' to get the name?