RE: Can you provide some context?

On Friday, April 10, 2015 11:30 PM, Ron Siemens wrote:
> I'm looking for some help to create context for my objects and links.
> I gave this a shot myself on the json-ld playground, but haven't got
> far.  Maybe this is child's play for an experienced "json-ld'er"?  Or
> if you'd like some bounty (small... this is just an experiment) to
> help out, get in touch.

Let me try :-)

 
> I have a data model with 3 object types: Tree, Branch, and Leaf.  A
> tree has one "root" branch.  Each branch can have a set of child
> branches and a set of leaves.  A leaf just has some attributes.

The first thing you'd normally do is to express this data model in the form
of a vocabulary.. which in principle means nothing else than giving each of
those concepts an unambiguous URL. So, e.g, Tree would be mapped to
something like http://www.example.com/vocab#Tree (is used fragment
identifiers to keep all definitions in a single document). You can have a
look at an exemplary vocabulary definition here: 

 
https://github.com/HydraCG/Specifications/blob/master/spec/latest/core/core.
jsonld


> I can query the data model through a REST interface as below.  
> 
> http://biohost1:3777/v1/growths9/tree/{tree_name}
> 
> http://biohost1:3777/v1/growths9/branch/{branch_name}
> 
> http://biohost1:3777/v1/growths9/leaf/{leaf_name}
> 
> The JSON looks like this
> 
> A tree...
> {
>  "id":"100",
>  "name":"maple",
>  "root":"root_branch"
> }
> 
> A branch...
> {
>  "id":"200",
>  "name":"root_branch",
>  "branches":[ { "id":"201", "name":"sub1_branch" },
>               { "id":"202", "name":"sub2_branch" } ],
>  "leaves":[ { "id":"500", "name":"leaf1" },
>             { "id":"501", "name":"leaf3" },
>             { "id":"502", "name":"leaf4" } ],
>  "age":"20"
> }
> 
> A leaf...
> {
>  "id":"500",
>  "name":"leaf1",
>  "area":"10",
>  "age":"3"
> }
> 
> As you can see, the "id" and "name" fields are overloaded in the
> different object types (but have no relationship to one another /
> there's not a global scope for ids or names).

That's not a problem...

> I'd like a separate @context for each. Something that I could use for
> a header-linked context that exposes the links into the structure.

.. but this won't work if you also want to be able to browse the resulting
documents as a client wouldn't know how to expand "leaf3" to a full URL.
Would it be a problem to change the names to include the directory
("leaf/leaf3" instead of just "leaf3")?


> Once I have that, what would I need to browse this? Is there off-the-
> shelf Javascript that will do this?

Yes, you can use the HydraConsole for instance [1-2].


> Create and update are also
> supported by the interface: would further extension of the context
> allow me to manipulate the structure with an off-the-shelf tool?

Just a context isn't enough but you can complement it with a Hydra API
Documentation to achieve that [3].

Here's how you could express a branch in JSON-LD

  {
    "@context": {
      "@vocab": "http://www.example.com/vocab#",
      "@base": "http://biohost1:3777/v1/growths9/",
      "name": "@id"
    },
    "id": "200",
    "name": "branch/root_branch",
    "branches":[
      { "id": "201", "name": "branch/sub1_branch" },
      { "id": "202", "name": "branch/sub2_branch" }
    ],
    "leaves":[
      { "id": "500", "name": "leaf/leaf1" },
      { "id": "501", "name": "leaf/leaf3" },
      { "id": "502", "name": "leaf/leaf4" }
    ],
    "age": "20"
  }

You can also load it directly into the HydraConsole: http://bit.ly/1Dw4BgN


HTH,
Markus


[1] http://www.markus-lanthaler.com/hydra/console/
[2] http://bit.ly/hydra-console-event-api
[3] http://www.hydra-cg.com/spec/latest/core/


--
Markus Lanthaler
@markuslanthaler

Received on Saturday, 18 April 2015 17:53:43 UTC