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

rdf prefix is not emitted when saving to turtle when only rdf:type is used #1649

Closed
cmungall opened this issue Jan 7, 2022 · 1 comment · Fixed by #1684
Closed

rdf prefix is not emitted when saving to turtle when only rdf:type is used #1649

cmungall opened this issue Jan 7, 2022 · 1 comment · Fixed by #1684
Labels
bug Something isn't working in-resolution

Comments

@cmungall
Copy link
Contributor

cmungall commented Jan 7, 2022

whenusing rdflib 6.1.1 to convert the following jsonld to turtle:

{
  "slots": [
    {
      "name": "type",
      "slot_uri": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
    }
  ],
  "@context": [
  {
      "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
      "@vocab": "https://w3id.org/linkml/",
      "slot_uri": {
         "@type": "@id"
      }
    }
  ]
}

the turtle emitted is:

@prefix : <https://w3id.org/linkml/> .

[] :slots [ :name "type" ;
            :slot_uri rdf:type ] .

which is invalid, as it lacks a prefix declaration for rdf

The situation is resolved by either

  • adding another node to the graph in the rdf namespace, other than rdf:type
  • saving to a format like nt

This reproduces the error:

JSONLD = """
{
  "slots": [
    {
      "name": "type",
      "slot_uri": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
    }
  ],
  "@context": [
  {
      "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
      "@vocab": "https://w3id.org/linkml/",
      "slot_uri": {
         "@type": "@id"
      }
    }
  ]
}"""

from rdflib import Graph

graph = Graph()
graph.parse(data=JSONLD, format="json-ld", prefix=False)
ttl_str = graph.serialize(format='turtle')
print(ttl_str)
graph.parse(data=ttl_str, format="turtle")

This is in contrast to other libs, e.g. Jena, which will produce valid turtle:

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

_:b0    <https://w3id.org/linkml/slots>  _:b1 .

_:b1    <https://w3id.org/linkml/name>  "type" ;
        <https://w3id.org/linkml/slot_uri>  rdf:type .
aucampia added a commit to aucampia/rdflib that referenced this issue Jan 9, 2022
This includes xfails for the following issues:

- RDFLib#1216
- RDFLib#1655
- RDFLib#1649

Also:

- Add graph variant test scaffolding. Multiple files representing the
  same graph can now easily be tested to be isomorphic by just adding
  them in `test/variants`.
- Add more things to `testutils.GraphHelper`, including some methods that does
  asserts with better messages. Also include some tests for GraphHelper.
- Add some extra files to test_roundtrip, set the default identifier
  when parsing, and change verbose flag to rather be based on debug
  logging.
- move one test from `test/test_issue247.py` to variants.
aucampia added a commit to aucampia/rdflib that referenced this issue Jan 9, 2022
This includes xfails for the following issues:

- RDFLib#1216
- RDFLib#1655
- RDFLib#1649

Also:

- Add graph variant test scaffolding. Multiple files representing the
  same graph can now easily be tested to be isomorphic by just adding
  them in `test/variants`.
- Add more things to `testutils.GraphHelper`, including some methods that does
  asserts with better messages. Also include some tests for GraphHelper.
- Add some extra files to test_roundtrip, set the default identifier
  when parsing, and change verbose flag to rather be based on debug
  logging.
- move one test from `test/test_issue247.py` to variants.
- Fix problems with `.editorconfig` which prevents it from working
  properly.
aucampia added a commit to aucampia/rdflib that referenced this issue Jan 9, 2022
This includes xfails for the following issues:

- RDFLib#1216
- RDFLib#1655
- RDFLib#1649

Also:

- Add graph variant test scaffolding. Multiple files representing the
  same graph can now easily be tested to be isomorphic by just adding
  them in `test/variants`.
- Add more things to `testutils.GraphHelper`, including some methods that does
  asserts with better messages. Also include some tests for GraphHelper.
- Add some extra files to test_roundtrip, set the default identifier
  when parsing, and change verbose flag to rather be based on debug
  logging.
- move one test from `test/test_issue247.py` to variants.
- Fix problems with `.editorconfig` which prevents it from working
  properly.
aucampia added a commit to aucampia/rdflib that referenced this issue Jan 9, 2022
This includes xfails for the following issues:

- RDFLib#1216
- RDFLib#1655
- RDFLib#1649

Also:

- Add graph variant test scaffolding. Multiple files representing the
  same graph can now easily be tested to be isomorphic by just adding
  them in `test/variants`.
- Add more things to `testutils.GraphHelper`, including some methods that does
  asserts with better messages. Also include some tests for GraphHelper.
- Add some extra files to test_roundtrip, set the default identifier
  when parsing, and change verbose flag to rather be based on debug
  logging.
- move one test from `test/test_issue247.py` to variants.
- Fix problems with `.editorconfig` which prevents it from working
  properly.
aucampia added a commit to aucampia/rdflib that referenced this issue Jan 9, 2022
This includes xfails for the following issues:

- RDFLib#1216
- RDFLib#1655
- RDFLib#1649

Also:

- Add graph variant test scaffolding. Multiple files representing the
  same graph can now easily be tested to be isomorphic by just adding
  them in `test/variants`.
- Add more things to `testutils.GraphHelper`, including some methods that does
  asserts with better messages. Also include some tests for GraphHelper.
- Add some extra files to test_roundtrip, set the default identifier
  when parsing, and change verbose flag to rather be based on debug
  logging.
- move one test from `test/test_issue247.py` to variants.
- Fix problems with `.editorconfig` which prevents it from working
  properly.
@nicholascar
Copy link
Member

nicholascar commented Jan 10, 2022

I think that the use of rdf:type as an object, as opposed to the commonly seen predicate, is somehow confusing RDFlib. This use is perfectly valid, so this is an RDFLib bug. Tagging as such.

RDFLib will always convert rdf:type to a if it's used as a predicate, so that why RDFLib thinks it doesn't need to add the rdf: prefix, but it's wrong!

aucampia added a commit to aucampia/rdflib that referenced this issue Jan 10, 2022
This includes xfails for the following issues:

- RDFLib#1216
- RDFLib#1655
- RDFLib#1649

Also:

- Add graph variant test scaffolding. Multiple files representing the
  same graph can now easily be tested to be isomorphic by just adding
  them in `test/variants`.
- Add more things to `testutils.GraphHelper`, including some methods that does
  asserts with better messages. Also include some tests for GraphHelper.
- Add some extra files to test_roundtrip, set the default identifier
  when parsing, and change verbose flag to rather be based on debug
  logging.
- move one test from `test/test_issue247.py` to variants.
- Fix problems with `.editorconfig` which prevents it from working
  properly.
aucampia added a commit to aucampia/rdflib that referenced this issue Jan 12, 2022
This includes xfails for the following issues:

- RDFLib#1216
- RDFLib#1655
- RDFLib#1649

Also:

- Add graph variant test scaffolding. Multiple files representing the
  same graph can now easily be tested to be isomorphic by just adding
  them in `test/variants`.
- Add more things to `testutils.GraphHelper`, including some methods that does
  asserts with better messages. Also include some tests for GraphHelper.
- Add some extra files to test_roundtrip, set the default identifier
  when parsing, and change verbose flag to rather be based on debug
  logging.
- move one test from `test/test_issue247.py` to variants.
- Fix problems with `.editorconfig` which prevents it from working
  properly.
aucampia added a commit to aucampia/rdflib that referenced this issue Jan 12, 2022
This includes xfails for the following issues:

- RDFLib#1216
- RDFLib#1655
- RDFLib#1649

Also:

- Add graph variant test scaffolding. Multiple files representing the
  same graph can now easily be tested to be isomorphic by just adding
  them in `test/variants`.
- Add more things to `testutils.GraphHelper`, including some methods that does
  asserts with better messages. Also include some tests for GraphHelper.
- Add some extra files to test_roundtrip, set the default identifier
  when parsing, and change verbose flag to rather be based on debug
  logging.
- move one test from `test/test_issue247.py` to variants.
- Fix problems with `.editorconfig` which prevents it from working
  properly.
aucampia added a commit to aucampia/rdflib that referenced this issue Jan 12, 2022
…sers.

The time it takes for these parsers to parse strings with escape
sequences will be increased, and the increase will be correlated with
the amount of escape sequences that occur in a string.

For strings with many escape sequences the parsing speed seems to be
almost 4 times slower.

Also:

- Add graph variant test scaffolding. Multiple files representing the
  same graph can now easily be tested to be isomorphic by just adding
  them in `test/variants`.
- Add more things to `testutils.GraphHelper`, including some methods that does
  asserts with better messages. Also include some tests for GraphHelper.
- Add some extra files to test_roundtrip, set the default identifier
  when parsing, and change verbose flag to rather be based on debug
  logging.
- move one test from `test/test_issue247.py` to variants.
- Fix problems with `.editorconfig` which prevents it from working
  properly.
- Add xfail tests for a couple of issues
  This includes xfails for the following issues:
  - RDFLib#1216
  - RDFLib#1649
aucampia added a commit to aucampia/rdflib that referenced this issue Jan 12, 2022
…sers.

These parsers will now correctly handle strings like `"\\r"`.

The time it takes for these parsers to parse strings with escape
sequences will be increased, and the increase will be correlated with
the amount of escape sequences that occur in a string.

For strings with many escape sequences the parsing speed seems to be
almost 4 times slower.

Also:

- Add graph variant test scaffolding. Multiple files representing the
  same graph can now easily be tested to be isomorphic by just adding
  them in `test/variants`.
- Add more things to `testutils.GraphHelper`, including some methods that does
  asserts with better messages. Also include some tests for GraphHelper.
- Add some extra files to test_roundtrip, set the default identifier
  when parsing, and change verbose flag to rather be based on debug
  logging.
- move one test from `test/test_issue247.py` to variants.
- Fix problems with `.editorconfig` which prevents it from working
  properly.
- Add xfail tests for a couple of issues
  This includes xfails for the following issues:
  - RDFLib#1216
  - RDFLib#1649
aucampia added a commit to aucampia/rdflib that referenced this issue Jan 12, 2022
…sers.

These parsers will now correctly handle strings like `"\\r"`.

The time it takes for these parsers to parse strings with escape
sequences will be increased, and the increase will be correlated with
the amount of escape sequences that occur in a string.

For strings with many escape sequences the parsing speed seems to be
almost 4 times slower.

Also:

- Add graph variant test scaffolding. Multiple files representing the
  same graph can now easily be tested to be isomorphic by just adding
  them in `test/variants`.
- Add more things to `testutils.GraphHelper`, including some methods that does
  asserts with better messages. Also include some tests for GraphHelper.
- Add some extra files to test_roundtrip, set the default identifier
  when parsing, and change verbose flag to rather be based on debug
  logging.
- move one test from `test/test_issue247.py` to variants.
- Fix problems with `.editorconfig` which prevents it from working
  properly.
- Add xfail tests for a couple of issues
  This includes xfails for the following issues:
  - RDFLib#1216
  - RDFLib#1649
aucampia added a commit to aucampia/rdflib that referenced this issue Jan 12, 2022
…sers.

These parsers will now correctly handle strings like `"\\r"`.

The time it takes for these parsers to parse strings with escape
sequences will be increased, and the increase will be correlated with
the amount of escape sequences that occur in a string.

For strings with many escape sequences the parsing speed seems to be
almost 4 times slower.

Also:

- Add graph variant test scaffolding. Multiple files representing the
  same graph can now easily be tested to be isomorphic by just adding
  them in `test/variants`.
- Add more things to `testutils.GraphHelper`, including some methods that does
  asserts with better messages. Also include some tests for GraphHelper.
- Add some extra files to test_roundtrip, set the default identifier
  when parsing, and change verbose flag to rather be based on debug
  logging.
- move one test from `test/test_issue247.py` to variants.
- Fix problems with `.editorconfig` which prevents it from working
  properly.
- Add xfail tests for a couple of issues
  This includes xfails for the following issues:
  - RDFLib#1216
  - RDFLib#1649
aucampia added a commit to aucampia/rdflib that referenced this issue Jan 12, 2022
…sers.

These parsers will now correctly handle strings like `"\\r"`.

The time it takes for these parsers to parse strings with escape
sequences will be increased, and the increase will be correlated with
the amount of escape sequences that occur in a string.

For strings with many escape sequences the parsing speed seems to be
almost 4 times slower.

Also:

- Add graph variant test scaffolding. Multiple files representing the
  same graph can now easily be tested to be isomorphic by just adding
  them in `test/variants`.
- Add more things to `testutils.GraphHelper`, including some methods that does
  asserts with better messages. Also include some tests for GraphHelper.
- Add some extra files to test_roundtrip, set the default identifier
  when parsing, and change verbose flag to rather be based on debug
  logging.
- move one test from `test/test_issue247.py` to variants.
- Fix problems with `.editorconfig` which prevents it from working
  properly.
- Add xfail tests for a couple of issues
  This includes xfails for the following issues:
  - RDFLib#1216
  - RDFLib#1649
@nicholascar nicholascar added the bug Something isn't working label Jan 15, 2022
aucampia added a commit to aucampia/rdflib that referenced this issue Jan 15, 2022
…sers.

These parsers will now correctly handle strings like `"\\r"`.

The time it takes for these parsers to parse strings with escape
sequences will be increased, and the increase will be correlated with
the amount of escape sequences that occur in a string.

For strings with many escape sequences the parsing speed seems to be
almost 4 times slower.

Also:

- Add graph variant test scaffolding. Multiple files representing the
  same graph can now easily be tested to be isomorphic by just adding
  them in `test/variants`.
- Add more things to `testutils.GraphHelper`, including some methods that does
  asserts with better messages. Also include some tests for GraphHelper.
- Add some extra files to test_roundtrip, set the default identifier
  when parsing, and change verbose flag to rather be based on debug
  logging.
- move one test from `test/test_issue247.py` to variants.
- Fix problems with `.editorconfig` which prevents it from working
  properly.
- Add xfail tests for a couple of issues
  This includes xfails for the following issues:
  - RDFLib#1216
  - RDFLib#1649
@aucampia aucampia self-assigned this Jan 21, 2022
@aucampia aucampia removed their assignment Jan 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working in-resolution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants