Page MenuHomePhabricator

Syntax highlighting for editing ShExC code (EntitySchema pages)
Open, Needs TriagePublic

Description

As an editor I want to have syntax highlighting, code completion and tooltips for the mentioned entities in order to make writing ShEx more easy.

Problem:
Right now we don't have any editor support for Entity Schemas, only free-text.

Example:
https://www.wikidata.org/w/index.php?title=EntitySchema:E10&action=edit

Options:
We could use YASHE. (It would still need to go through security review before deployment.) The benefits of using it would be:

  • it works very similar to the existing query service UI syntax highlighting and code completion
  • it does dynamic syntax validation to show you syntax errors
  • it supports namespace completion

BDD
GIVEN an Entity Schema
WHEN in edit mode
THEN syntax highlighting, code completion and tooltips for the mentioned entities are available

Acceptance criteria:

  • syntax highlighting, code completion and tooltips for the mentioned entities are available in the edit mode of an Entity Schema

Open questions:

  • Can we and do we want to use YASHE?

Event Timeline

I mocked up using the ace ShExC mode in an EntitySchema.

EntitySchema2-ace-edit.png (925×961 px, 179 KB)

The [x]s at the left come form an WebWorker which runs a shex.js ShEx parser asynchronously. If you uncomment the PREFIX decl at the top of the schema, you'll see the [x]s go away in ~.2 seconds.

Upsides: syntax highlighting and error checking.

Downsides: no tool tips for Qids.

I think @Jelabra has a student working one that's more in the spirit of the wikidata SPARQL editor, which will probably be more useful in the long run. OTOH, you could use mine today and switch to his when it's ready.

That's way cooler than mine. @Jelabra, can that be plugged in today?

Integrating YASHE seems like a good way forward, since CodeMirror (which it’s based on) is also integrated into MediaWiki elsewhere (Extension:CodeMirror). It would take some work, though, including security review by WMF people, so I don’t know when it would happen.

Color is nice but imho decoding the P and Q numbers is critical.
https://www.wikidata.org/wiki/User:Zvpunry/EntitySchemaHighlighter.js does that: it linkifies Pnnn and Qnnn and shows a tooltip on hover.

Some aid in adding comments semi-automatically would be even better, eg from

wdt:P31 [wd:Q5];
wdt:P21 [wd:Q6581097 wd:Q6581072 wd:Q1097630 wd:Q1052281 wd:Q2449503 wd:Q48270]?;

to

wdt:P31 [wd:Q5]; # instance of # human
wdt:P21 [    # sex or gender
  wd:Q6581097 # male
  wd:Q6581072 # female
  wd:Q1097630 # intersex
...]?;

Color is nice but imho decoding the P and Q numbers is critical.
https://www.wikidata.org/wiki/User:Zvpunry/EntitySchemaHighlighter.js does that: it linkifies Pnnn and Qnnn and shows a tooltip on hover.

https://phabricator.wikimedia.org/source/tool-wd-shex-infer/browse/master/static/annotate-wikidata-entity-ids-in-shex.js does something similar, though not as a user script; you can see it in action e. g. here.

YaSHE already does that. YaShE has been implemented as a fork of YasQe, which is the code behind the wikidata query service.

Indeed, also supports auto-completion in the same way as wikidata query service, i.e. you can start typing the name of an entity/property and after CTRL-Space it gives a suggestion of entities/properties.

@Jelabra I see the tooltips at http://wikishape.weso.es/ Schema>Info:

wikishape-E10-YASHE-editor.png (684×788 px, 63 KB)

The positioning, size and alignment of the tooltip need to be adjusted a bit.

However, I think the embedded comments shown by @LucasWerkmeister are a lot more useful:

wd-shex-infer-highlight-and-comment.jpg (1×1 px, 527 KB)

Such embedded comments allow you to see the schema it in its entirety:

  • facilitates much easier understanding, without having to mouse around and remember the tooltips on every P and Q.
  • you can also print it out or copy-paste it to an email
  • so I think this "expanded comments" style is the best thing while reading (T238831) and if it can be UX-ed not to conflict with editing, also for this issue.

Can YASHE/CodeMirror be tricked into displaying inferred non-editable text? Alternatively, @ericP can the SHEX CG figure out some syntax for embedded in-line comments?

BTW @LucasWerkmeister the first lines of your schemas confuse me a bit, guess that's because they are inferred?

  • wdt:P50 @wd:Q5?; and wd:Q5: {: a schema is supposed to use a different namespace, right?
  • wd:Q5 { # & wd:Q215627: does that mean it applies to two classes? Or is inferred from two classes?

Also see T242410.

Lydia_Pintscher renamed this task from Syntax highlighting for ShEx editor to Syntax highlighting for editing ShExC code (EntitySchema pages).Apr 19 2021, 4:34 PM
Lydia_Pintscher updated the task description. (Show Details)
Lydia_Pintscher updated the task description. (Show Details)