json-ld.org icon indicating copy to clipboard operation
json-ld.org copied to clipboard

Collaborate on a JSON-LD hinter for CodeMirror

Open BigBlueHat opened this issue 7 years ago • 18 comments

I started by attempting to extract the exiting JSON-LD hinter in use on the playground: https://github.com/json-ld/json-ld.org/blob/master/playground/jsonld-hint.js

However, I quickly found that it's tightly coupled with the playground's assumptions (depends on jQuery, uses global variables from the playground, etc).

Consequently, I've started a new, more narrowly focused one:

  • Demo: https://wileylabs.github.io/codemirror-jsonld-hint/
  • Code: https://github.com/WileyLabs/codemirror-jsonld-hint

It's MIT licensed, and I'd love to make sure it provides the necessary extension points needed to provide a more widely usable JSON-LD linter--as I also have hopes of contributing this add-on upstream when it's "ready." 😸

So. Is there interest in such things? 😃

Thanks! 🎩

BigBlueHat avatar Jan 25 '17 18:01 BigBlueHat

Oh sweet Jesus, yes, we love you, keep going!

msporny avatar Jan 25 '17 19:01 msporny

Aw, thanks! 😁

I'm guessing things the Playground needs are:

  • callback on highlight (for the jQuery pop-overs)
  • linting extracted / modularized

Anything else?

(and again much thanks for the encouragement!)

BigBlueHat avatar Jan 25 '17 19:01 BigBlueHat

Some other things the playground could use:

  • graphical display of data. I believe there's a Jason-ld D3 module that might work
  • output Turtle/TriG instead of NQuades. N3.js might help here
  • RDF input as an alternative to JSON-LD. I get asked about this a lot.

gkellogg avatar Jan 26 '17 05:01 gkellogg

Also see #450 and #383. https://github.com/scienceai/jsonld-vis looks interesting.

gkellogg avatar Jan 26 '17 06:01 gkellogg

These are great, @gkellogg! Replies below...

graphical display of data. I believe there's a Jason-ld D3 module that might work

Looks like you already found the one I was going to suggest.

output Turtle/TriG instead of NQuades. N3.js might help here

👍

RDF input as an alternative to JSON-LD. I get asked about this a lot.

Could you elaborate on this one? This is a JSON-LD playground after all. 😸 Are people expecting to drop Turtle (etc) into a field and see the JSON-LD output? I have often wanted to flip back and forth between RDF expressions...but that leads us into a larger work...maybe. 💭's?

BigBlueHat avatar Jan 26 '17 15:01 BigBlueHat

One of the core JSON-LD algorithms is fromRdf, which requires RDF input to create expanded JSON-LD. Of course, this can be combined with compact and/or framing to get framed output. As JSON-LD is an RDF serialization, being able to start from some other serialization (at least N-Quads) is a key feature that the playground has not supported to date.

Either some mode could be set to change the input from JSON-LD to Turtle/TriG, or it could be content sniffed easily enough (although possible, TriG will never start with {, none start with [, usually start with @prefix or @base, absolute IRI <..>, or Node _:..). Note that N3.js supports N-Triples, N-Quads, Turtle and TriG.

gkellogg avatar Jan 26 '17 16:01 gkellogg

Great to know @gkellogg! I do want to see all of these things start to lean into each other.

Also, checkout #459 which solves (I hope) #383. It looks like #450 handles the remaining two items you mentioned. So we're on the right track! 🚆

I'll try and work the hinter toward a (to-be-upstreamed) replacement for the current one...and we can refocus that issue on that if that works. 🔨 👷 🔧

BigBlueHat avatar Jan 26 '17 20:01 BigBlueHat

Also, if anyone can help me narrow this issue down, I'd be most grateful: https://github.com/WileyLabs/codemirror-jsonld-hint/issues/1 🙇

BigBlueHat avatar Jan 26 '17 20:01 BigBlueHat

Just an FYI. The http://github.com/WileyLabs/codemirror-jsonld-hint project now supports standard @ prefixed JSON-LD terms and context-based terms (passed in via a config param).

The demo sports Web Annotation as the default vocab (available by typing :) as well as Schema.org terms prefixed by schema: (typing the : after schema opens just those terms). Here's the demo link: https://wileylabs.github.io/codemirror-jsonld-hint/

I'm now working on a "distribute" project for packaging these bits into npm and/or cdn available libraries: https://github.com/WileyLabs/codemirror-jsonld-hint/projects/1

Would love feedback on the overall approach and plans if anyone here has a moment. 😸

Thanks! 🎩

BigBlueHat avatar Feb 21 '17 14:02 BigBlueHat

@BigBlueHat, the hinter is really cool! My one critique at the moment would be its use of CURIEs ... we want to discourage those and encourage simple terms only. I imagine the hinter should just pop up all possible terms when you type the opening quote (") for a key rather than waiting for a prefix or colon.

dlongley avatar Feb 21 '17 14:02 dlongley

@dlongley ah. Good to know, and completely understandable. I'll give that a look soon--that's obviously the ideal anyhow vs. having to type : for the default vocab. 😛 Thanks for the feedback!

BigBlueHat avatar Feb 21 '17 15:02 BigBlueHat

+1, just tried it, super awesome. Agree w/ @dlongley on killing CURIEs with fire.

msporny avatar Feb 21 '17 17:02 msporny

I wouldn't kill compact IRIs, just not promote them. In particular, people using JSON-LD as an RDF serialization format, rather than as a native API, are often coming from environments that use PName/CURIEs. In many cases terms are defined for 1st class entries that are actually used in an API and compact IRIs remain for completeness of statements that exist in the graph, but are not of primary use. Compact IRIs should just fall out of the support for terms, with the part after the : not affecting anything else.

Also, values of @type (or it's alias) should use the same term hints.

gkellogg avatar Feb 21 '17 18:02 gkellogg

@gkellogg no worries. To be clear the : prefix stuff won't go away. It just (hopefully) won't be necessary for the default key/value names. Research and coding to prove that theory. :wink:

BigBlueHat avatar Feb 21 '17 21:02 BigBlueHat

@gkellogg sorry, I was mostly joking. :)

Non-LD people tend to get confused when they see JSON data that contains colons in the keys and values. While CURIEs have their uses, we've been suggesting for a long time that most Web developer facing systems should not use CURIEs in their output as people tend to fixate on how strange it looks and that ends up dominating the conversation vs. talking about the other benefits of Linked Data. Follow the path of least surprise, and all that. :)

msporny avatar Feb 22 '17 16:02 msporny

Done. https://github.com/WileyLabs/codemirror-jsonld-hint/issues/2

BigBlueHat avatar Feb 22 '17 19:02 BigBlueHat

Happy New Year! 😁

I'd love to help get this over the fence...if y'all are still interested.

Cheers! 🎩

BigBlueHat avatar Feb 22 '18 15:02 BigBlueHat

Sure, I think people are still interested. Who wouldn't want better tools? ;-) Are things at a point where PRs could be made?

I imagine at this point everything may need upgrades. CodeMirror and other libs are all using rather old versions. The JSON-LD support will need an upgrade to support 1.1 features at some point as well. If hinter code works without upgrades, that's fine too.

davidlehn avatar Feb 22 '18 18:02 davidlehn