Page MenuHomePhabricator

Syntax highlighting for ShEx editor
Open, Needs TriagePublic

Description

The ShEx editor should have syntax highlighting for the Shape Expressions.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJun 4 2019, 7:04 AM
ericP added subscribers: Jelabra, ericP.EditedJun 11 2019, 9:31 AM

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


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.

The YASHE editor has support to ShEx also.

ericP added a comment.Jun 20 2019, 7:16 AM

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:


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:

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.