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

Added a fix for parsing rdflib literals. #229

Merged
merged 7 commits into from
Jul 4, 2024

Conversation

jesper-friis
Copy link
Contributor

@jesper-friis jesper-friis commented Jun 29, 2024

Description

We cannot use the value attribute of an rdflib.Literal to access its value, since it is None for some datatypes (at least for rdf:JSON).
Seems more robust to use the existence of the n3() method to test for a literal and the string representation to access its value.

Type of change

  • Bug fix and code cleanup
  • New feature
  • Documentation update
  • Testing

Checklist for the reviewer

This checklist should be used as a help for the reviewer.

  • Is the change limited to one issue?
  • Does this PR close the issue?
  • Is the code easy to read and understand?
  • Do all new feature have an accompanying new test?
  • Has the documentation been updated as necessary?
  • Is the code properly tested?

Copy link

codecov bot commented Jul 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.44%. Comparing base (225fc78) to head (0a1da48).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #229      +/-   ##
==========================================
+ Coverage   78.41%   78.44%   +0.02%     
==========================================
  Files          18       18              
  Lines        1696     1698       +2     
==========================================
+ Hits         1330     1332       +2     
  Misses        366      366              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

tripper/utils.py Outdated Show resolved Hide resolved
# This will handle rdflib literals correctly and probably most other
# literal representations as well.
# This should handle rdflib literals correctly (and probably most other
# literal representations as well)
if hasattr(literal, "value"):
Copy link
Contributor

Choose a reason for hiding this comment

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

But can a literal not have the attribute? Isn't it always there, but sometimes with value None? (I thought the reason for this fix is exactly that)

Copy link
Contributor Author

@jesper-friis jesper-friis Jul 1, 2024

Choose a reason for hiding this comment

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

Agree, the argument name literal is not very well chosen. It may be any Python object that can be converted to a literal (most of these do not have a value attribute). It was changed by Casper from obj to literal in one of his early reviews. Should we revert?

jesper-friis and others added 2 commits July 1, 2024 22:48
Co-authored-by: Francesca L. Bleken <48128015+francescalb@users.noreply.github.com>
@jesper-friis jesper-friis requested a review from francescalb July 1, 2024 20:55
@jesper-friis jesper-friis merged commit f76cdd5 into master Jul 4, 2024
18 of 19 checks passed
@jesper-friis jesper-friis deleted the fix-for-rdflib-literals branch July 4, 2024 06:51
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.

2 participants