newsdev / archieml-js

JavaScript parser for the Archie Markup Language (ArchieML)
http://archieml.org
Other
205 stars 19 forks source link

Support JSON-LD #2

Closed bollwyvl closed 9 years ago

bollwyvl commented 9 years ago

I would like to write JSON-LD with AML. It's a nice fit, as JSON-LD is good at strong, yet simple semantics for identifier and type, while AML is good at not having lots of quotes and braces.

All I need is some way to create keys containing @.

To support the JSON-LD keywords, it would require:

-  var startKey = new RegExp('^\\s*([A-Za-z0-9-_\.]+)[ \t\r]*:[ \t\r]*(.*)');
+  var startKey = new RegExp('^\\s*([A-Za-z0-9-_\.@]+)[ \t\r]*:[ \t\r]*(.*)');
-  var scopePattern = new RegExp('^\\s*(\\[|\\{)[ \t\r]*([A-Za-z0-9-_\.]*)[ \t\r]*(?:\\]|\\})[ \t\r]*.*?(\n|\r|$)');
+  var scopePattern = new RegExp('^\\s*(\\[|\\{)[ \t\r]*([A-Za-z0-9-_\.@]*)[ \t\r]*(?:\\]|\\})[ \t\r]*.*?(\n|\r|$)');

In return for this, AML could now:

@id: Alice
[knows]
* bob

{@context}
foaf: http://xmlns.com/foaf/0.1/
{@context.knows}
@id: foaf:knows
@type: @id 
@id: Carol
{jobTitle}
en: Doctor
de: Ärtzt

{@context}
sdo: http://schema.org/
{@context.jobTitle}
@id: sdo:jobTitle
@container: @lang

The : namespacing capability, as used on the right-hand side of some of the above entries, might be a bridge too far: however, if you are asking a user to whip up some linked data, you should provide them with a good, simply-keyed context.

abstrctn commented 9 years ago

Hi @bollwyvl, this question falls pretty squarely under one we started over on the archieml.org repo, "Unicode support for keys": newsdev/archieml.org#3

Using @ symbols in keys doesn't seem any stranger than many of the unicode symbols we may want to support going forward; the question is always going to be how to make the parsers recognize a key without implementations getting too complicated.

Using : in values, like you do above in @id: sdo:jobTitle shouldn't be a problem (AML doesn't care what values are used after the first :, so even :s can be used).

It looks like JSON-LD standard [suggests](New DOMESTIC preview) that colons can be used on the left side of keys as well ("Using a compact IRI as a term"):

{
  "@context":
  {
    "foaf": "http://xmlns.com/foaf/0.1/",
    "xsd": "http://www.w3.org/2001/XMLSchema#",
    "name": "foaf:name",
    "foaf:age":
    {
      "@type": "xsd:integer"
    },
    "foaf:homepage":
    {
      "@type": "@id"
    }
  },
  ...
}

As well as using "absolute IRIs" by using a URL as a key, such as http://xmlns.com/foaf/0.1/homepage. I don't know whether this is something A) you care about, or B) is required to support JSON-LD, since it's listed under a non-normative section. But both would be problematic since introducing :s to keys would necessitate introducing some sort of escaping mechanism for keys, which opens a can of worms.

There's a few open questions to discuss here that I'm going to move to the archieml.org issues page. So while this is a maybe, I'm gonna close the issue here. You should be able to modify your version of archieml.js for your own usage, but I want to answer to the larger question about keys before adding characters to the "allowed" list one by one. Thanks!

bollwyvl commented 9 years ago

Great answer! I'll track the other ticket.

IMHO: the only important thing for user-centric support of json-ld is @ in the LHS.

Then at least one can define

@context: http://some/external/context

Which can give meaning to all the keys in the document... It is cruel and unusual to make someone use the colon namespacing if you are trying to "help" get something done.