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

BREAKING CHANGE: Make Literal more standards compliant #2460

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

aucampia
Copy link
Member

@aucampia aucampia commented Jun 20, 2023

  • Literal's datatype attribute is now no longer optional and will never
    be None.
  • Constructing a literal with only a language tag will set the datatype
    to rdf:langString.

Related issues:

WhiteGobo and others added 3 commits August 16, 2023 22:12
Raise an error when nested graphs occur in TriG.

With this change, the <http://www.w3.org/2013/TriGTests/#trig-graph-bad-07> test passes.

---------

Co-authored-by: WhiteGobo <richardfechner@posteo.net>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Iwan Aucamp <aucampia@gmail.com>
Skip the following tests that rely on SPARQL 1.0 grammar
and are incompatible with the SPARQL 1.1 grammar:

- <http://www.w3.org/2001/sw/DataAccess/tests/data-r2/basic/manifest#term-6>
- <http://www.w3.org/2001/sw/DataAccess/tests/data-r2/basic/manifest#term-7>

---------

Co-authored-by: WhiteGobo <richardfechner@posteo.net>
Co-authored-by: Iwan Aucamp <aucampia@gmail.com>
TBD

checkpoint

aucampia/20230609T2355-literal_datatype: checkpoint 20230817T000443
Comment on lines +714 to +728
if lang is not None or datatype == _RDF_LANGSTRING:
if lang is None:
raise ValueError(f"language cannot be None if datatype is {datatype}")
if not lang:
raise ValueError("language cannot be empty string")
if not _lang_tag_regex.match(lang):
raise ValueError(
"language tag must match the pattern "
"^[a-zA-Z]+(?:-[a-zA-Z0-9]+)*$ "
f"but was {lang}"
)

if datatype is None:
datatype = _RDF_LANGSTRING

Copy link
Contributor

@WhiteGobo WhiteGobo Sep 25, 2023

Choose a reason for hiding this comment

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

Let q=Literal("ex", datatype=something). This will also overwrite any datatype given to a new Literal Literal(q, lang="en").

#prevous:
Literal(q, lang="en")
# >> Literal("ex", lang="en", datatype=something)

# now:
Literal(q, lang="en")
# >> Literal("ex", lang="en", datatype=RDF.langString)

Before the datatype was inherited. But i havent seen this behaviour documented, so there was no expected behaviour before. But we could mention this change in behaviour nonetheless.
Also this will handle issue #2603

_XSD_PFX = "http://www.w3.org/2001/XMLSchema#"
_RDF_PFX = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"

_RDF_LANGSTRING = URIRef(_RDF_PFX + "langString")
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be more useful to make _RDF_LANGSTRING a class attribute for Literal. Then someone can change the default datatype for langstring by using a childclass instead of changing it programwide.
But im not sure

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