Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json-ld serialize doesnt failt or raise warning, when producing invalid syntax; type is literal #2747

Open
WhiteGobo opened this issue Mar 19, 2024 · 7 comments

Comments

@WhiteGobo
Copy link
Contributor

So im not sure if this is a bug. So i tested if there are any problems bumping up the default version of json-ld to 1.1 and the roundtrip test failed. Background is #2606

[
  {
    "@id": "file:///somewhere/",
    "@type": [
      {
        "@value": "thing too"
      }
    ]
  },
  {
    "@id": "file:///somewhere/#",
    "@type": [
      {
        "@value": "another thing"
      }
    ]
  }
]

Cant pe parsed with version 1.1 but it works with 1.0.

Graph().parse(jsonfile, format="json-ld", version=1.1)

It seems that it tries to get an existing reference to the type {"@value": "another thing"} which is a dict and cant be hashed. It doesnt try to do this in version 1.0.

@WhiteGobo
Copy link
Contributor Author

WhiteGobo commented Mar 19, 2024

It fails at this point: (rt is the dict {"@value": "another thing"})

typeterm = self.terms.get(rt)

This is the testfile that fails to be loaded again:

# Test the syntactic items for abbreviation.
# This is *not* testing rule application.
@prefix : <#> .
_:a => _:b .
_:a <= _:b .
_:a = _:b .
# 'this' refers to the current formula so is not legal for RDF
# this a "thing".
<> a "thing too".
<#> a "another thing".

@WhiteGobo
Copy link
Contributor Author

WhiteGobo commented Mar 21, 2024

Ok i'm pretty sure this is a bug in the serializer and not in the parser. @type should be a term, a compact iri or a reference and shouldnt contain value objects.(edited after comment from edmondchuc)

I would change the parser to give more leniency and let it fallback to its behaviour of version 1.0, till the bug in the serializer is repaired. We could remove this behaviour or at least raise a warning in the next major release of rdflib.

@WhiteGobo
Copy link
Contributor Author

@prefix foaf: <http://xmlns.com/foaf/0.1/> .
[] a foaf:Person.

is serialized to

[
  {
    "@id": "_:ncd6c76112bd148c0a0c9a8a035854d6cb1",
    "@type": [
      "http://xmlns.com/foaf/0.1/Person"
    ]
  }
]

As far as i understand it should be "@type": "http://xmlns.com/foaf/0.1/Person" instead, without the [...]

@edmondchuc
Copy link
Contributor

edmondchuc commented Mar 21, 2024

As far as i understand it should be "@type": "http://xmlns.com/foaf/0.1/Person" instead, without the [...]

I guess the serialized result you got there is just the JSON-LD in the expanded form. If you don't want it as a list, you can use compaction. Behaviour of @type here is relevant? https://www.w3.org/TR/json-ld11/#using-set-with-type.

Sorry, haven't looked too much into how this is related to your original issue though.

@WhiteGobo
Copy link
Contributor Author

Mh your right. I still think value objects arent allowed in that array. so things like {"@type": [{"@value": "thing too"}]} shouldnt be allowed. (ive changed my comment above to reflect this)

@edmondchuc
Copy link
Contributor

Yeah, probably the JSON-LD processor in RDFLib is just not as strict. Your provided example fails in https://json-ld.org/playground/ when the value of @type is a value object.

JSON-LD example: https://tinyurl.com/2atu5gdy

@WhiteGobo WhiteGobo reopened this Apr 18, 2024
@WhiteGobo WhiteGobo changed the title parsing json-ld version 1.1 fails, when type is a literal json-ld serialize doesnt failt or raise warning, when producing invalid syntax; type is literal Apr 18, 2024
@WhiteGobo
Copy link
Contributor Author

Ive renamed the issue, because of the bug in the serializer. Now Roundtrip test with default jsonld version 1.1 will succeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants