digitalbazaar / jsonld.js

A JSON-LD Processor and API implementation in JavaScript
https://json-ld.org/
Other
1.66k stars 195 forks source link

Only @type value from last named graph retained in result #378

Closed fkleedorfer closed 4 years ago

fkleedorfer commented 4 years ago

The same resource is present in multiple named graphs. It has one or more @type entries in each graph, all different. When framing, matching on the resource's @id property, only the @type values from the last graph are present in the result.

The test case below shows that for normal properties, all values are picked up (see ex:multipleValues). If one uses rdf:type instead of @type, all values are picked up. That will probably be our workaround for the time being.

I am not 100% sure if this is a bug or works as specified, but I suspect it's a bug.

Tested on https://json-ld.org/playground/:

Input:

{
    "@context": {
        "ex": "http://example.com#",
        "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    },
    "@graph": [
        {
            "@graph": [
                {
                    "@id": "ex:entity1",
                    "@type": [
                        "ex:Type1",
                        "ex:Type2"
                    ],
                    "ex:title": "some title",
                    "ex:multipleValues": "ex:One"
                }
            ],
            "@id": "ex:graph1"
        },
        {
            "@graph": [
                {
                    "@id": "ex:entity1",
                    "@type": "ex:Type3",
                    "ex:tags": "tag1 tag2",
                    "ex:multipleValues": [
                        "ex:Two",
                        "ex:Three"
                    ]
                }
            ],
            "@id": "ex:graph2"
        }
    ]
}

frame:

{
    "@context": {
        "ex": "http://example.com#",
        "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    },
    "@id": "ex:entity1"
}

output:

{
    "@context": {
        "ex": "http://example.com#",
        "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    },
    "@graph": [
        {
            "@id": "ex:entity1",
            "@type": "ex:Type3",
            "ex:multipleValues": [
                "ex:One",
                "ex:Two",
                "ex:Three"
            ],
            "ex:tags": "tag1 tag2",
            "ex:title": "some title"
        }
    ]
}

expected output: (all three values for @type, not just ex:Type3)

{
    "@context": {
        "ex": "http://example.com#",
        "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    },
    "@graph": [
        {
            "@id": "ex:entity1",
            "@type": [
                "ex:Type1",
                "ex:Type2",
                "ex:Type3"
            ],
            "ex:multipleValues": [
                "ex:One",
                "ex:Two",
                "ex:Three"
            ],
            "ex:tags": "tag1 tag2",
            "ex:title": "some title"
        }
    ]
}
gkellogg commented 4 years ago

You are framing the merge graph, which is what folds in these separate values, but it should also fold in the separate types. I get essentially the same results in the Ruby implementation.

Looking into it, it seems like an issue in the Merge Node Maps algorithm in JSON-LD11-API. Step 2.2.1 adds property and values to merged node for keywords, which replaces the initial ex:Type1 and ex:Type2 values with a new value. It should probably be run only where property is a keyword other than @type, and allow the otherwise clause in 2.2.2 to merge values.

Could you please file a bug in https://github.com/w3c/json-ld-api/issues.

fkleedorfer commented 4 years ago

Fixed for us - thanks!