Support for JSON-LD

21 views
Skip to first unread message

Alex Batlin

unread,
Feb 17, 2014, 6:02:17 AM2/17/14
to sta...@clarkparsia.com
Hi, looking at your docs, there is some support for JSON-LD, but I cannot figure out how to use it properly. I checked out https://github.com/digitalbazaar/jsonld.js, and like the way I can take a POJ (Plain Old JSON) and add a header with link to context file and turn that POJ into linked data, which I can then persist in Stardog. Equally I would like to query for  a resource (you guys already support that largely via the DESCRIBE command support), but instead of returning the JSON output with listed attributes, I would love to see a POJ returned, with link content, either as part of same returned POJ or as a header. Does this make sense to do? What I am really saying is that I want to persist a POJ easily in stardog.

Fernando Hernandez

unread,
Feb 18, 2014, 3:00:20 PM2/18/14
to sta...@clarkparsia.com
Hi Alex,

We support JSON-LD as query results format, e.g. you can request for "application/ld+json" whenever you use a SPARQL endpoint. Currently you cannot use the HTTP or SNARL API to add triples in JSON-LD format. 

However you can use our Sesame Repository API [1] to add triples to your database [2].


Cheers,
Fernando



On Mon, Feb 17, 2014 at 6:02 AM, Alex Batlin <alex....@bytehaus.co.uk> wrote:
Hi, looking at your docs, there is some support for JSON-LD, but I cannot figure out how to use it properly. I checked out https://github.com/digitalbazaar/jsonld.js, and like the way I can take a POJ (Plain Old JSON) and add a header with link to context file and turn that POJ into linked data, which I can then persist in Stardog. Equally I would like to query for  a resource (you guys already support that largely via the DESCRIBE command support), but instead of returning the JSON output with listed attributes, I would love to see a POJ returned, with link content, either as part of same returned POJ or as a header. Does this make sense to do? What I am really saying is that I want to persist a POJ easily in stardog.

--
-- --
You received this message because you are subscribed to the C&P "Stardog" group.
To post to this group, send email to sta...@clarkparsia.com
To unsubscribe from this group, send email to
stardog+u...@clarkparsia.com
For more options, visit this group at
http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en

Alex Batlin

unread,
Feb 19, 2014, 8:38:04 AM2/19/14
to sta...@clarkparsia.com, fern...@clarkparsia.com
Hi, I tried the "application/ld+json" setting when using the graph protocol and it worked well, however when using the stardog.js api, I get a slightly strange for me (does not look part of the spec) response:

[
  {
    "attributes": {
      "http://accounts.com#hasOverdraft": [
        {
          "@value": 500
        }
      ],
      "@type": [
        "http://accounts.com#CurrentAccount",
        "http://www.w3.org/2002/07/owl#NamedIndividual"
      ],
      "http://accounts.com#hasSortCode": [
        {
          "@value": "01-01-01"
        }
      ],
      "http://accounts.com#hasAccountNumber": [
        {
          "@type": "http://www.w3.org/2001/XMLSchema#string",
          "@value": "00000001"
        }
      ],
      "@id": "http://accounts.com#BarclaysCurrentAccount01",
      "http://accounts.com#isPartOf": [
        {
          "@id": "http://accounts.com#AlexBatlinPortfolio01"
        }
      ]
    }
  }
]

I can process that as such : 

            data.forEach(function(item) {
                jsonld.compact(item.attributes, context, function(err, compacted) {
                    res.json(compacted);
                });
            })

And then it works, but I am trying to figure out the rational (I am pretty sure I am missing something) for this type of output. Any thoughts will be most welcome. Here is the query issue code:

var stardog = require("stardog");
var jsonld = require('jsonld');

var conn = new stardog.Connection();

var context = {
    "overDraft": "http://accounts.com#hasOverdraft",
    "sortCode": "http://accounts.com#hasSortCode",
    "portfolio": "http://accounts.com#isPartOf",
    "accountNumber": {
        "@id": "http://accounts.com#hasAccountNumber",
        "@type": "http://www.w3.org/2001/XMLSchema#string"
    }
}

conn.setEndpoint("http://localhost:5820/");
conn.setCredentials("admin", "admin");
conn.setReasoning("SL");

exports.query = function (req, res) {

    conn.queryGraph({
            database: "accountsDB",
            mimetype: "application/ld+json",
            //query: "select distinct ?p ?o where { <http://accounts.com#BarclaysCurrentAccount01> ?p ?o }",
            query: "construct { <http://accounts.com#BarclaysCurrentAccount01> ?p ?o } where { <http://accounts.com#BarclaysCurrentAccount01> ?p ?o }",
            limit: 100,
            offset: 0
        },
        function (data) {
//            data.forEach(function(item) {
//                jsonld.compact(item.attributes, context, function(err, compacted) {
//                    res.json(compacted);
//                });
//            })

            res.json(data);
        });
}

Many thanks,

Alex.

Fernando Hernandez

unread,
Feb 19, 2014, 9:17:31 AM2/19/14
to sta...@clarkparsia.com

Alex Batlin

unread,
Feb 19, 2014, 11:46:05 AM2/19/14
to
Cool, so I was not totally crazy. Final question, how come the attributes return I got is inside an array (square brackets), rather than curly brackets. Reminder of what I got as a return:


Would you expect any other list members, or do you always just get a list with one item, and if so why?


Many thanks,

Alex

Fernando Hernandez

unread,
Feb 19, 2014, 12:28:56 PM2/19/14
to sta...@clarkparsia.com
Alex,

On Wed, Feb 19, 2014 at 11:42 AM, Alex Batlin <alex....@bytehaus.co.uk> wrote:
Cool, so I was totally crazy. Final question, how come the attributes return I got is inside an array (square brackets), rather than curly brackets. Reminder of what I got as a return:


Would you expect any other list members, or do you always just get a list with one item, and if so why?

Since you created a construct query you always get an array of objects, regardless of how many subjects you've bound. The relevant piece of code that handles this in stardog.js is this [1].

 
Cheers,
Fernando

Alex Batlin

unread,
Feb 19, 2014, 1:06:12 PM2/19/14
to sta...@clarkparsia.com
Ok, thanks. Feels a bit awkward given      Json-ld syntax, hopefully as you improve the Json-Ld code that can improve, if I get time I will try to add a pull request 

Sent from my iPhone
--
-- --
You received this message because you are subscribed to the C&P "Stardog" group.
To post to this group, send email to sta...@clarkparsia.com
To unsubscribe from this group, send email to
stardog+u...@clarkparsia.com
For more options, visit this group at
http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en

To unsubscribe from this group and stop receiving emails from it, send an email to stardog+u...@clarkparsia.com.
Reply all
Reply to author
Forward
0 new messages