RE: Map of identifiers of a type

Hi,

On Thursday, November 14, 2013 11:27 AM, Huynh T.D. wrote:
> Hello,
>
> I've just rediscovered JSON-LD yesterday (after about 2 years) and I've
> been very impressed with its progress.

Glad to hear that.

> Playing with my existing JSON, I found the following compact pattern that
> I have not been able to describe using the current specs.
>
> {
>   "Type1": {
>     // A map of Type1 object IDs
>     "id1": {
>          // Properties of id1
>          "name": "some value",
>        },
>        "id1": {
>         // Properties of id2
>        },
>   },
>   "Type2": {
>     // another map of IDs here
>   }
> }

Right, the index can be only one level deep. You could, however combine your
indexes to flatten the JSON. Something like 

{
  "Type1-id1": {
     // Properties of id1
     "name": "some value",
  },
  "Type1-id2": {
     // Properties of id2
  },
  ...
}


> For example:
> {
>   "ConferencePaper": {
>     "Huynh2013": {
>          "title": "some value",
>        },
>     "Huynh2012": {
>     },
>   },
>   "JournalPaper": {
>   }
> }
>
> Essentially, there are two things that I want to describe using the
> pattern:
> 
> 1. "Huynh2013" and "Huynh2012" are identifiers of some objects, and
> 2. they are of type ConferencePaper (i.e. rdf:type ConferencePaper).
> 
> Is it possible to describe the above pattern with the current spec?

Yes, but not as concise as in your example. You would need to do something
like:

{
  "@context": {
    "ex": "http://example.com/vocab#",
    "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "paperTypes": { "@id": "ex:paperTypes", "@container": "@index" },
    "papers": { "@reverse": "rdf:type", "@container": "@index" },
    "title": "ex:title"
  },
  "paperTypes": {
    "ConferencePaper": {
      "@id": "ex:ConferencePaper",
      "papers": {
        "Huynh2013": {
          "title": "Huynh2013 conf. paper"
        },
        "Huynh2012": {
          "title": "Huynh2012 conf. paper"
        }
      }
    },
    "JournalPaper": {
      "@id": "ex:JournalPaper",
      "papers": {
        "Huynh2011": {
          "title": "Huynh2011 journal paper"
        }
      }
    }
  }
}

Which is equal to the following triples:

_:b0 ex:paperTypes ex:ConferencePaper, 
                   ex:JournalPaper .

_:b1 rdf:type ex:ConferencePaper ;
     ex:title "Huynh2012 conf. paper" .
_:b2 rdf:type ex:ConferencePaper ;
     ex:title "Huynh2013 conf. paper" .
_:b3 rdf:type ex:vocab#JournalPaper ;
     ex:title "Huynh2011 journal paper" .

I think that's what you want, right?


> I found the Data Indexing feature
> (http://json-ld.org/spec/latest/json-ld/#data-indexing) can help a bit
> with (1), but if I have to write "Huynh2013": { "@id": "Huynh2013", ... },
> it is unnecessarily repetitive, I think.

Yeah, unless you can live with blank nodes you have to. We to not support
indexing for things like @id in this version of JSON-LD but may add support
for it in a future version. 


> I also found this email
> http://lists.w3.org/Archives/Public/public-linked-json/2013Nov/0003.html ,
> which is related to (2), but the @reverse solution does not work in this
> case.

A variation works, see above. You have to introduce some repetition though
to make it work.


HTH,
Markus


--
Markus Lanthaler
@markuslanthaler

Received on Monday, 18 November 2013 13:57:01 UTC