As a user I want to have an option to automatically transform my SPARQL queries into a standard, consistent format (upper/lowercase, indentation, cosmetic spaces, line breaks, etc.) with the Wikidata Query UI in order to share them. As a Wikidata contributor I also want to have that option in order to apply the same format to all the queries on https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples.
Problem: There are too many ways of writing the same SPARQL query and this fact makes users write their queries using different criteria and copypasted fragments from several sources and examples. This makes a single query inconsistent with itself. On the other hand, there is no way of automatically reformatting SPARQL queries from the Wikidata Query UI and it's tedious to do it manually.
Example:
Screenshots/mockups:
BDD
GIVEN a SPARQL query
AND an option to reformat queries from the Wikidata Query UI
WHEN I click that option
THEN the SPARQL query is reformatted consistently
Suggestions:
- All parentheses, ( and ), when they aren't part of a literal or a comment, are preceded/followed by the same combination of whitespaces/tabs/line feeds/carriage returns. Opening and closing parentheses can follow different rules.
- All brackets, [ and ], when they aren't part of a literal or a comment, are preceded/followed by the same combination of whitespaces/tabs/line feeds/carriage returns. Opening and closing brackets can follow different rules.
- All braces, { and }, when they aren't part of a literal or a comment, are preceded/followed by the same combination of whitespaces/tabs/line feeds/carriage returns. Opening and closing braces can follow different rules.
- All symbols ;, when linking triples with a common subject, are preceded/followed by the same combination of whitespaces/tabs/line feeds/carriage returns.
- All SPARQL clauses, when used as such, are uppercase.
- There is no more than one whitespace between SPARQL clauses.
- There are no blank lines (except, perhaps, the last one).
- Each level of nesting introduces an indentation with the same number of whitespaces.
- The dot symbol, ., when finishing a triple, is always followed by a line feed/carriage return.
- Other possible rules to get a standard, consistent format without modifying the semantics.
Open questions: