JSON-LD: Assign custom URIs to blank nodes within context

349 views Asked by At

I'm trying to convert a very large JSON file to JSON-LD. When I import the example code below into GraphDB, db:metadata becomes a property/predicate connecting each GeneSet:setX node with an automatically created blank node _:bX (gray in figure), from which the properties set_name and set_id then point to their corresponding values.

Linked data example

{
    "@context":{
        "xsd": "http://www.w3.org/2001/XMLSchema#",
        "db": "http://example.com/setDB#",
        "_id": "@id",
        "GeneSet": {"@id": "db:GeneSet"},
        "data": {"@id": "db:metadata"},
        "set_name": {
            "@id": "db:set_name",
            "@type": "xsd:string"
        },
        "set_id": {
            "@id": "db:set_id",
            "@type": "xsd:string"
        }
    },
    "@graph": [
        {
        "_id": "GeneSet:set1",
        "data": {
            "set_name": "set1",
            "set_id": "M123"}},
        {
        "_id": "GeneSet:set2",
        "data": {
            "set_name": "set2",
            "set_id": "M456"}},
        {
        "_id": "GeneSet:set3",
        "data": {
            "set_name": "set3",
            "set_id": "M789"}
        }]
}

I would like to convert these blank nodes into actual URIs, preferably with the unique form db:setX/data, but the more generic db:data could also work. I know I can achieve the former by adding "@id": "db:data/setX" within the curly brackets of each "data": {...} definition, but since my complete data has over 100,000 of these GeneSets I would like to achieve this by simply modifying the @context.

Is this possible?

1

There are 1 answers

2
BigBlueHat On BEST ANSWER

The sort of "templated" ID generation your after is (deliberately) not possible via the JSON-LD @context mechanism. The @context is for mapping tree data into graph data, not transforming it.

Consequently, looking into injecting those ID values programmatically into the JSON-LD before you process it is one option.

You might also want to ask on the JSON-LD WG's mailing list to get further options.