Re: JSON, RDF Triples and Little Languages

On 21 January 2016 at 22:49, David Janes <davidjanes@davidjanes.com> wrote:

> Although JSON is readable, the approach y'all taking with using JSON as an
> _authoring_ language is fundamentally flawed. JSON is readable, but it's
> still unsuited for most domain specific applications.
>
> Instead, IOTDB has (after several failed ideas [1]) adopted the _little
> language_ [2] approach called IoTQL [3]. Here for example is a model for a
> Hue (or Hue-like) Light [4]
>
>
> CREATE MODEL HueLight WITH
>
> schema:name = "Hue Light",
>
> schema:description = "Philips Hue colored light",
>
> iot:facet = iot-facet:lighting
>
> ATTRIBUTE *on* WITH
>
> schema:name = "on",
>
> *iot:purpose = iot-purpose:on,*
>
> iot:type = iot:type.boolean
>
> ATTRIBUTE color WITH
>
> schema:name = "color",
>
> iot:purpose = iot-purpose:color,
>
> iot:type = iot:type.string,
>
> iot:format = iot:format.color
>
> This is trivially human readable, and easy enough to write, all the QNames
> resolving to sensible values, e.g. we know what the attribute called "on"
> does by just looking at it
>
> *iot:purpose*
> https://iotdb.org/pub/iot#on
>
>
>
> *iot-purpose:on*
> https://iotdb.org/pub/iot-purpose#on
>
>
> This compiles to JSON-LD, which is difficult to properly write but easily
> understood by consumers. You can see the JSON-LD for this model here [5].
>
> Finally, if you need to get to triples this all reads quite well also
> (though I wouldn't recommend it over the JSON-LD version)
>
>>
> <file:///hue-light#color>
>   <http://schema.org/name> "color" .
> <file:///hue-light#color>
>   <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
>   <https://iotdb.org/pub/iot#Attribute> .
> <file:///hue-light#color>
>   <https://iotdb.org/pub/iot#actuator> "true"^^<
> http://www.w3.org/2001/XMLSchema#boolean> .
> <file:///hue-light#color>
>   <https://iotdb.org/pub/iot#format>
>   <https://iotdb.org/pub/iot#format.color> .
> <file:///hue-light#color>
>   <https://iotdb.org/pub/iot#purpose>
>   <https://iotdb.org/pub/iot-purpose#color> .
> <file:///hue-light#color>
>   <https://iotdb.org/pub/iot#read> "true"^^<
> http://www.w3.org/2001/XMLSchema#boolean> .
> <file:///hue-light#color>
>   <https://iotdb.org/pub/iot#sensor> "true"^^<
> http://www.w3.org/2001/XMLSchema#boolean> .
> <file:///hue-light#color>
>   <https://iotdb.org/pub/iot#type>
>   <https://iotdb.org/pub/iot#type.string> .
> <file:///hue-light#color>
>   <https://iotdb.org/pub/iot#write> "true"^^<
> http://www.w3.org/2001/XMLSchema#boolean> .
> *<file:///hue-light#on>*
> *  <http://schema.org/name <http://schema.org/name>> "on" .*
> <file:///hue-light#on>
>   <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
>   <https://iotdb.org/pub/iot#Attribute> .
> <file:///hue-light#on>
>   <https://iotdb.org/pub/iot#actuator> "true"^^<
> http://www.w3.org/2001/XMLSchema#boolean> .
> *<file:///hue-light#on>*
> *  <https://iotdb.org/pub/iot#purpose <https://iotdb.org/pub/iot#purpose>>*
> *  <https://iotdb.org/pub/iot-purpose#on
> <https://iotdb.org/pub/iot-purpose#on>> .*
> <file:///hue-light#on>
>   <https://iotdb.org/pub/iot#read> "true"^^<
> http://www.w3.org/2001/XMLSchema#boolean> .
> <file:///hue-light#on>
>   <https://iotdb.org/pub/iot#sensor> "true"^^<
> http://www.w3.org/2001/XMLSchema#boolean> .
> <file:///hue-light#on>
>   <https://iotdb.org/pub/iot#type>
>   <https://iotdb.org/pub/iot#type.boolean> .
> <file:///hue-light#on>
>   <https://iotdb.org/pub/iot#write> "true"^^<
> http://www.w3.org/2001/XMLSchema#boolean> .
> <file:///hue-light>
>   <http://schema.org/description> "Philips Hue colored light" .
> <file:///hue-light>
>   <http://schema.org/name> "Hue Light" .
> <file:///hue-light>
>   <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
>   <https://iotdb.org/pub/iot#Model> .
> <file:///hue-light>
>   <https://iotdb.org/pub/iot#attribute>
>   <file:///hue-light#color> .
> *<file:///hue-light>*
> *  <https://iotdb.org/pub/iot#attribute
> <https://iotdb.org/pub/iot#attribute>>*
> *  <file:///hue-light#on> .*
> <file:///hue-light>
>   <https://iotdb.org/pub/iot#facet>
>   <https://iotdb.org/pub/iot-facet#lighting> .
>
> My apologies if any of this comes out fuzzy: it's authored in GMail with a
> fair bit of formatting. The links below have the original sources.
>
>>
> References:
>

JSON is the current fashion, as XML was in its day.  JSON has one
particular advantage in that it doesnt require a library for the first
step, of parsing it into javascript.  After the parsing process it becomes
a lot less powerful.  You can use your triples with qnames too using the
Terse Triple language (TTL or Turtle)

https://www.w3.org/TR/turtle/

I've actually moved from JSON onto this format, and am enjoying the
results.  Each serialization church will have strong supporters, but they
do tend change their allegiance with the fashion.  Personally I just try
and use the best tool for the job ...


>
> [1]
> using an HTML-based editor; writing in natively JSON; writing in
> Javascript that compiles to JSON.
>
> [2]
> https://en.wikipedia.org/wiki/Domain-specific_language
>
> [3]
> https://github.com/dpjanes/iotdb-iotql
>
> [4]
> https://github.com/dpjanes/homestar-hue/blob/master/models/HueLight.iotql
>
> [5]
> https://github.com/dpjanes/homestar-hue/blob/master/models/HueLight.json
>
> Regards, etc...
> David
>

Received on Friday, 22 January 2016 00:34:02 UTC