json-ld / json-ld.org

JSON for Linked Data's documentation and playground site
https://json-ld.org/
Other
857 stars 152 forks source link

recursive @reverse framing #647

Closed eroux closed 6 years ago

eroux commented 6 years ago

I would like to use a @reverse property to build a tree structure in JSON-LD but it doesn't seem to work on the dev-playground nor on the distiller. My initial file is:

{
  "@graph" : [ {
    "@id" : "bdr:O9TAXTBRC201605",
    "@type" : "Taxonomy"
  }, {
    "@id" : "bdr:O9TAXTBRC201605_0001",
    "@type" : "Taxonomy",
    "taxSubclassOf" : "bdr:O9TAXTBRC201605"
  }, {
    "@id" : "bdr:O9TAXTBRC201605_0002",
    "@type" : "Taxonomy",
    "taxSubclassOf" : "bdr:O9TAXTBRC201605_0001"
  }, {
    "@id" : "bdr:O9TAXTBRC201605_0010",
    "@type" : "Taxonomy",
    "taxSubclassOf" : "bdr:O9TAXTBRC201605"
  } ],
  "@context" : {
    "taxSubclassOf" : {
      "@id" : "http://purl.bdrc.io/ontology/core/taxSubclassOf",
      "@type" : "@id"
    },
    "@vocab" : "http://purl.bdrc.io/ontology/core/",
    "bdr" : "http://purl.bdrc.io/resource/"
  }
}

my frame is:

{ 
  "@id": "bdr:O9TAXTBRC201605",
  "@context" : {
    "children": { "@reverse": "http://purl.bdrc.io/ontology/core/taxSubClassOf" }, 
    "taxSubclassOf" : {
      "@id" : "http://purl.bdrc.io/ontology/core/taxSubclassOf",
      "@type" : "@id"
    },
    "@vocab" : "http://purl.bdrc.io/ontology/core/",
    "bdr" : "http://purl.bdrc.io/resource/"
  }
}

I would expect the result to be:

{
  "@graph": [
    {
      "@id": "bdr:O9TAXTBRC201605",
      "@type": "Taxonomy",
      "children": [
        {
          "@id": "bdr:O9TAXTBRC201605_0001",
          "@type": "Taxonomy",
          "children": {
            "@id": "bdr:O9TAXTBRC201605_0002",
            "@type": "Taxonomy"
          }
        },
        {
          "@id": "bdr:O9TAXTBRC201605_0010",
          "@type": "Taxonomy"
        }
      ]
    }
  ]
}

but instead I'm getting:

{
  "@graph": [
    {
      "@id": "bdr:O9TAXTBRC201605",
      "@type": "Taxonomy"
    }
  ]
}

(I removed the @context for the sake of clarity). Is it possible to get the result I want?

pjohnston-wiley commented 6 years ago

You have a typo in the definition of children - subclass vs subClass. Try:

{ 
  "@id" : "bdr:O9TAXTBRC201605",
  "@context" : {
    "children": { "@reverse": "http://purl.bdrc.io/ontology/core/taxSubclassOf" }, 
    "taxSubclassOf" : {
      "@id" : "http://purl.bdrc.io/ontology/core/taxSubclassOf",
      "@type" : "@id"
    },
    "@vocab" : "http://purl.bdrc.io/ontology/core/",
    "bdr" : "http://purl.bdrc.io/resource/"
  },
  "children": {
    "children": {"children": {}}
  }
}

It also seems that you need to be explicit about how deep you want your children to go....

chz p

eroux commented 6 years ago

Thanks for the correction! But my graph is pretty deep and I can't know in advance how deep it is... so I guess that's the main problem

azaroth42 commented 6 years ago

Propose close, working as expected (modulo not having typos :) ) @eroux?

eroux commented 6 years ago

well, should I open a new ticket for not having to specify the number of levels of recursion?

azaroth42 commented 6 years ago

Sure :) That seems an orthogonal issue to @reverse. Thanks!

eroux commented 6 years ago

well, not really : in the normal mode, infinite recursion is possible, in reverse mode, it has to be specified