Skip to content

RDF JSON with Optimisations

iand edited this page Apr 15, 2011 · 9 revisions

I think there could be some ways to make RDF/JSON nicer by introducing some optimisations for common cases. However I want to adhere to these principles:

  1. No optional syntax that forces users to have conditional tests in their code

This is the standard sample from the RDF/JSON Specification:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:foaf="http://xmlns.com/foaf/0.1/"
  xmlns:dc="http://purl.org/dc/elements/1.1/">
  <rdf:Description rdf:about="http://example.org/about">
    <dc:creator>Anna Wilder</dc:creator>
    <dc:title xml:lang="en">Anna's Homepage</dc:title>
    <foaf:maker rdf:nodeID="person" />
  </rdf:Description>
  <rdf:Description rdf:nodeID="person">
    <foaf:homepage rdf:resource="http://example.org/about" />
    <foaf:made rdf:resource="http://example.org/about" />
    <foaf:name>Anna Wilder</foaf:name>
    <foaf:firstName>Anna</foaf:firstName>
    <foaf:surname>Wilder</foaf:surname>
    <foaf:depiction rdf:resource="http://example.org/pic.jpg" />
    <foaf:nick>wildling</foaf:nick>
    <foaf:nick>wilda</foaf:nick>
    <foaf:mbox_sha1sum>69e31bbcf58d432950127593e292a55975bc66fd</foaf:mbox_sha1sum>
  </rdf:Description>
</rdf:RDF>

##Standard RDF/JSON

{
    "http://example.org/about" : {
        "http://purl.org/dc/elements/1.1/creator": [ { "value": "Anna Wilder", 
                                                        "type": "literal" } ],
        "http://purl.org/dc/elements/1.1/title": [ { "value": "Anna's Homepage", 
                                                        "type": "literal", "lang" : "en" } ] ,
        "http://xmlns.com/foaf/0.1/maker": [ { "value": "_:person", 
                                                        "type" : "bnode" } ]
    } ,
 
    "_:person" : {
        "http://xmlns.com/foaf/0.1/homepage": [ { "value": "http://example.org/about", 
                                                        "type": "uri" } ] ,
        "http://xmlns.com/foaf/0.1/made": [ { "value": "http://example.org/about", 
                                                        "type": "uri" } ] ,
        "http://xmlns.com/foaf/0.1/name": [ { "value": "Anna Wilder", 
                                                        "type": "literal" } ] ,
        "http://xmlns.com/foaf/0.1/firstName": [ { "value" : "Anna", 
                                                        "type": "literal" } ] ,
        "http://xmlns.com/foaf/0.1/surname": [ { "value": "Wilder", 
                                                        "type": "literal" } ] , 
        "http://xmlns.com/foaf/0.1/depiction": [ { "value": "http://example.org/pic.jpg", 
                                                        "type": "uri" } ] ,
        "http://xmlns.com/foaf/0.1/nick": [ 
                                                      { "type" : "literal", "value" : "wildling"} , 
                                                      { "type" : "literal", "value" : "wilda" } 
                                                    ] ,
        "http://xmlns.com/foaf/0.1/mbox_sha1sum": [ {  "value" : "69e31bbcf58d432950127593e292a55975bc66fd", 
                                                      "type" : "literal" } ] 
    }
}

Short properties

One optimisation could be to introduce short names for properties. However namespace mechanisms introduce variability in the choice of prefixes and/or whether to use the namespaced version of URI or the full version.

A non-variable approach is to define a fixed set of short property names that covers 90% of usage and require that these short names are always used if a property with that URI exists in the data, i.e. remove the variability.

Therefore we could have:

{
    "http://example.org/about" : {
        "creator": [ { "value": "Anna Wilder", 
                                                        "type": "literal" } ],
        "title": [ { "value": "Anna's Homepage", 
                                                        "type": "literal", "lang" : "en" } ] ,
        "maker": [ { "value": "_:person", 
                                                        "type" : "bnode" } ]
    } ,
 
    "_:person" : {
        "homepage": [ { "value": "http://example.org/about", 
                                                        "type": "uri" } ] ,
        "made": [ { "value": "http://example.org/about", 
                                                        "type": "uri" } ] ,
        "name": [ { "value": "Anna Wilder", 
                                                        "type": "literal" } ] ,
        "firstName": [ { "value" : "Anna", 
                                                        "type": "literal" } ] ,
        "surname": [ { "value": "Wilder", 
                                                        "type": "literal" } ] , 
        "depiction": [ { "value": "http://example.org/pic.jpg", 
                                                        "type": "uri" } ] ,
        "nick": [ 
                                                      { "type" : "literal", "value" : "wildling"} , 
                                                      { "type" : "literal", "value" : "wilda" } 
                                                    ] ,
        "http://xmlns.com/foaf/0.1/mbox_sha1sum": [ {  "value" : "69e31bbcf58d432950127593e292a55975bc66fd", 
                                                      "type" : "literal" } ] 
    }
}

Clone this wiki locally