Skip to content

Framed @graph @container output not properly compacted #627

Closed
@gkellogg

Description

@gkellogg

From digitalbazaar/jsonld.js#241.

When framing, anonymous named graphs are not considered simple graphs, and so are not properly compacted with "@container": "@graph" if the pruneBlankNodeIdentifiers option is false. For example:

Input

{
  "@context": {
    "@version": 1.1,
    "@vocab": "https://example.com#",
    "ex": "https://example.org/",
    "claim": {
      "@id": "ex:claim",
      "@container": "@graph"
    },
    "id": "@id"
  },
  "claim": {
    "id": "ex:1",
    "test": "foo"
  }
}

Frame

{
  "@context": {
    "@version": 1.1,
    "@vocab": "https://example.com#",
    "ex": "https://example.org/",
    "claim": {
      "@id": "ex:claim",
      "@container": "@graph"
    },
    "id": "@id"
  },
  "claim": {}
}

Because of flattening, this leads to the following before compaction:

Expanded/Framed output

```json
[
  {
    "@id": "_:b0",
    "http://example.org/claim": [
      {
        "@id": "_:b1",
        "@graph": [
          {
            "@id": "http://example.org/1",
            "https://example.com#test": [
              {
                "@value": "foo"
              }
            ]
          }
        ]
      }
    ]
  }
]

With the pruneBlankNodeIdentifiers option set to try, the @id elements are removed:

[
  {
    "http://example.org/claim": [
      {
        "@graph": [
          {
            "@id": "http://example.org/1",
            "https://example.com#test": [
              {
                "@value": "foo"
              }
            ]
          }
        ]
      }
    ]
  }
]

This allows compaction to render the following:

{
  "@context": {
    "@version": 1.1,
    "@vocab": "https://example.com#",
    "claim": {
      "@id": "ex:claim",
      "@container": "@graph"
    },
    "id": "@id"
  },
  "@graph": [
    {
      "claim": {
        "id": "ex:1",
        "test": "foo"
      }
    }
  ]
}

which is the expected result.

The proposed solution is to not make pruneBlankNodeIdentifiers an option, but the normal behavior when running in 1.1 mode. In retrospect, it was never intended that these unreferenced blank node identifiers remain, it was just a byproduct of the flattening algorithm.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions