Skip to content

Context @base with urn expands incorrectly #305

Closed

Description

@riteshrao

When a context utilizes a urn as the @base IRI for expanding relative IRI's, the resulting expanded absolute IRI does not retain the urn format.

Example

{
  "@context": [
    "http://schema.org/",
    { 
      "@base": "urn:example-org:entities/persons/",
      "knows": { "@id": "http://schema.org/knows", "@type": "@id" }
    }
  ],
  "@graph": [
    {
      "@id": "jdoe",
      "@type": "Person",
      "givenName": "John Doe",
      "knows": "janed"    
    },
    {
      "@id": "urn:example-org/entities/persons/janed",
      "@type": "Person",
      "givenName": "Jane Doe"
    }
  ] 
}

After expansion the relative IRI's resolve to:

[
  {
    "@id": "urn:/example-org:entities/persons/jdoe",
    "@type": [
      "http://schema.org/Person"
    ],
    "http://schema.org/givenName": [
      {
        "@value": "John Doe"
      }
    ],
    "http://schema.org/knows": [
      {
        "@id": "urn:/example-org:entities/persons/janed"
      }
    ]
  },
  {
    "@id": "urn:example-org/entities/persons/janed",
    "@type": [
      "http://schema.org/Person"
    ],
    "http://schema.org/givenName": [
      {
        "@value": "Jane Doe"
      }
    ]
  }
]

The relative IRI for jdoe gets expanded to absolute IRI urn:/example.org:entities/person/jdoe. This mangles the urn format and both the nss and nid segments gets mangled. I would have expected the absolute IRI to be urn:example-org:entities/persons/jdoe.

Activity

  1. davidlehn commented on Mar 23, 2019

    @davidlehn
    Member

    Yeah, this is a bug. I think there is also a typo in your example; one of base or janed id have a flipped : or /. Either way, the base is getting parsed in a nonsensical way and the output is wrong. The fix might be related to fixes required for the other failing relative iri tests.

    I made a slightly simplified example. Variations of @base all are broken.

    {
      "@context": {
        "@base": "urn:ex:p/",
        "link": { "@id": "ex:link", "@type": "@id" }
      },
      "@graph": [
        {
          "@id": "a",
          "ex:name": "a",
          "link": "b"
        },
        {
          "@id": "urn:ex:p/b",
          "ex:name": "b"
        }
      ]
    }
  2. AtesComp commented on May 29, 2019

    @AtesComp

    Additional examples derived from the JSON-LD 1.1 documentation that fail. See example.

    Example 1: @id changed to relative id, @type remains relative, "name" property remains relative.

    {
      "@context": {
        "@version": 1.1,
        "@base": "http://example/document",
        "@vocab": "#"
      },
      "@id": "BrewEats",
      "@type": "Restaurant",
      "name": "Brew Eats"
    }
    

    Failure:

    Processing error:
    jsonld.SyntaxError: Invalid JSON-LD syntax; the value of "@vocab" in a @context must be an absolute IRI.
    

    This contradicts the documentation.

    Example 2: Removed @vocab and modified @base end character.

    {
      "@context": {
        "@version": 1.1,
        "@base": "http://example/document#"
      },
      "@id": "BrewEats",
      "@type": "Restaurant",
      "name": "Brew Eats"
    }
    

    Failure:

    1. The @id and @type values have the base truncated to "http://example/". The process doesn't properly accept any gen-delim and sub-delim characters other than "/" as the last character. Oddly, "@" as the last character adds "/" to expand somewhat properly. This suggests the process is somehow enforcing "/" as the last valid character when applied to @id values.
    2. The "name" property is lost. I believe the default should use the @base or, failing that, the document location.
    [
      {
        "@id": "http://example/BrewEats",
        "@type": [
          "http://example/Restaurant"
        ]
      }
    ]
    

    Example 3: Added @vocab with absolute IRI.

    {
      "@context": {
        "@version": 1.1,
        "@base": "http://example/document#",
        "@vocab": "http://example/document#"
      },
      "@id": "BrewEats",
      "@type": "Restaurant",
      "name": "Brew Eats"
    }
    

    Failure:

    1. @id still fails in the same way as example 2.
      Otherwise, @type and "name" use @vocab as intended.
    [
      {
        "@id": "http://example/BrewEats",
        "@type": [
          "http://example/document#Restaurant"
        ],
        "http://example/document#name": [
          {
            "@value": "Brew Eats"
          }
        ]
      }
    ]
    

    Shouldn't @id and @type values expand in the same way using the same code?

    Example 4: No @context.

    {
      "@id": "BrewEats",
      "@type": "Restaurant",
      "name": "Brew Eats"
    }
    

    Failure:

    1. The "name" property is lost as before. I believe it should use the document location like @id and @type.
      Otherwise, @id and @type use the document default for the base.
    [
      {
        "@id": "https://json-ld.org/playground/BrewEats",
        "@type": [
          "https://json-ld.org/playground/Restaurant"
        ]
      }
    ]
    
  3. AtesComp commented on May 29, 2019

    @AtesComp

    Additionally, when the @base contains the gen-delim / sub-delim characters anywhere else in the IRI, similar errors and truncation occur.

  4. gkellogg commented on Mar 29, 2020

    @gkellogg
    Contributor

    I think PR #384 may fix this.

  5. dlongley commented on May 26, 2020

    @dlongley
    Member

    Closing as stale/potentially fixed by #384.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions