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

Fix turtle serialization of rdf:type in subject, object #1684

Merged

Conversation

aucampia
Copy link
Member

Previously if rdf:type occurred in subject or object of a triple then
turtle would have not added a prefix for rdf as it considered rdf:type
to be a keyword regardless of where in the triple it occurred.

This changeset ensures that rdf:type is only considered a keyword if it
occurs as the predicate of a triple.

Fixes #1649

@aucampia
Copy link
Member Author

New tests

$ .venv/bin/python3 -m pytest 'test/test_serializer.py::test_rdf_type' -rA --log-level DEBUG -vvv
============================================================================ test session starts ============================================================================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /home/iwana/sw/d/github.com/iafork/rdflib/.venv/bin/python3
cachedir: .pytest_cache
rootdir: /home/iwana/sw/d/github.com/iafork/rdflib, configfile: tox.ini
plugins: subtests-0.5.0, cov-3.0.0, monkeytype-1.1.0
collected 10 items                                                                                                                                                          

test/test_serializer.py::test_rdf_type[turtle-0-False] PASSED                                                                                                         [ 10%]
test/test_serializer.py::test_rdf_type[turtle-1-True] PASSED                                                                                                          [ 20%]
test/test_serializer.py::test_rdf_type[turtle-2-False] PASSED                                                                                                         [ 30%]
test/test_serializer.py::test_rdf_type[n3-0-False] PASSED                                                                                                             [ 40%]
test/test_serializer.py::test_rdf_type[n3-1-True] PASSED                                                                                                              [ 50%]
test/test_serializer.py::test_rdf_type[n3-2-False] PASSED                                                                                                             [ 60%]
test/test_serializer.py::test_rdf_type[trig-0-False] PASSED                                                                                                           [ 70%]
test/test_serializer.py::test_rdf_type[trig-1-True] PASSED                                                                                                            [ 80%]
test/test_serializer.py::test_rdf_type[trig-2-False] PASSED                                                                                                           [ 90%]
test/test_serializer.py::test_rdf_type[trig-3-False] PASSED                                                                                                           [100%]

================================================================================== PASSES ===================================================================================
_______________________________________________________________________ test_rdf_type[turtle-0-False] _______________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
INFO     root:test_serializer.py:41 data = @prefix eg: <example:> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

rdf:type eg:pred eg:obj .
_______________________________________________________________________ test_rdf_type[turtle-1-True] ________________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
INFO     root:test_serializer.py:41 data = @prefix eg: <example:> .

eg:subj a eg:obj .
_______________________________________________________________________ test_rdf_type[turtle-2-False] _______________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
INFO     root:test_serializer.py:41 data = @prefix eg: <example:> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

eg:subj eg:pred rdf:type .
_________________________________________________________________________ test_rdf_type[n3-0-False] _________________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
INFO     root:test_serializer.py:41 data = @prefix eg: <example:> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

rdf:type eg:pred eg:obj .
_________________________________________________________________________ test_rdf_type[n3-1-True] __________________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
INFO     root:test_serializer.py:41 data = @prefix eg: <example:> .

eg:subj a eg:obj .
_________________________________________________________________________ test_rdf_type[n3-2-False] _________________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
INFO     root:test_serializer.py:41 data = @prefix eg: <example:> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

eg:subj eg:pred rdf:type .
________________________________________________________________________ test_rdf_type[trig-0-False] ________________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
INFO     root:test_serializer.py:41 data = @prefix eg: <example:> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

eg:graph {
    rdf:type eg:pred eg:obj .
}
________________________________________________________________________ test_rdf_type[trig-1-True] _________________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
INFO     root:test_serializer.py:41 data = @prefix eg: <example:> .

eg:graph {
    eg:subj a eg:obj .
}
________________________________________________________________________ test_rdf_type[trig-2-False] ________________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
INFO     root:test_serializer.py:41 data = @prefix eg: <example:> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

eg:graph {
    eg:subj eg:pred rdf:type .
}
________________________________________________________________________ test_rdf_type[trig-3-False] ________________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
INFO     root:test_serializer.py:41 data = @prefix eg: <example:> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

rdf:type {
    eg:subj eg:pred eg:obj .
}
========================================================================== short test summary info ==========================================================================
PASSED test/test_serializer.py::test_rdf_type[turtle-0-False]
PASSED test/test_serializer.py::test_rdf_type[turtle-1-True]
PASSED test/test_serializer.py::test_rdf_type[turtle-2-False]
PASSED test/test_serializer.py::test_rdf_type[n3-0-False]
PASSED test/test_serializer.py::test_rdf_type[n3-1-True]
PASSED test/test_serializer.py::test_rdf_type[n3-2-False]
PASSED test/test_serializer.py::test_rdf_type[trig-0-False]
PASSED test/test_serializer.py::test_rdf_type[trig-1-True]
PASSED test/test_serializer.py::test_rdf_type[trig-2-False]
PASSED test/test_serializer.py::test_rdf_type[trig-3-False]
============================================================================ 10 passed in 0.09s =============================================================================

@aucampia aucampia force-pushed the iwana-20220123T0031-jsonld_rdf_prefix branch from 394879e to ed58b97 Compare January 23, 2022 00:55
@aucampia aucampia force-pushed the iwana-20220123T0031-jsonld_rdf_prefix branch 2 times, most recently from d495c8b to edf477e Compare January 23, 2022 01:00
Previously if `rdf:type` occurred in subject or object of a triple then
turtle would have not added a prefix for rdf as it considered `rdf:type`
to be a keyword regardless of where in the triple it occurred.

This changeset ensures that rdf:type is only considered a keyword if it
occurs as the predicate of a triple.
@aucampia aucampia force-pushed the iwana-20220123T0031-jsonld_rdf_prefix branch from edf477e to acb1a10 Compare January 23, 2022 01:05
Copy link
Member

@nicholascar nicholascar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix @aucampia

@aucampia aucampia merged commit b1dc449 into RDFLib:master Jan 29, 2022
@aucampia aucampia deleted the iwana-20220123T0031-jsonld_rdf_prefix branch April 9, 2022 14:13
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

Successfully merging this pull request may close these issues.

rdf prefix is not emitted when saving to turtle when only rdf:type is used
2 participants