-
Notifications
You must be signed in to change notification settings - Fork 136
String xsd:double value crash toRdf()
#202
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
Closed
anatoly-scherbakov
wants to merge
3
commits into
digitalbazaar:master
from
iolanta-tech:to-rdf-crashing-on-string-xsd-double
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| """ | ||
| Tests for to_rdf functionality, specifically focusing on double/float handling bugs. | ||
| """ | ||
|
|
||
| import json | ||
mielvds marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import sys | ||
| import os | ||
| import unittest | ||
|
|
||
| # Add the lib directory to the path so we can import pyld | ||
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'lib')) | ||
|
|
||
| import pyld.jsonld | ||
|
|
||
|
|
||
| class TestDoubleToRdf(unittest.TestCase): | ||
| """Test cases for to_rdf functionality with double/float values.""" | ||
|
|
||
| def test_offline_pyld_bug_reproduction(self): | ||
| """Test reproducing the PyLD bug with captured Wikidata data structure.""" | ||
| # This is the exact problematic data structure captured from Wikidata Q399 | ||
mielvds marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # The bug occurs when PyLD tries to convert this to RDF | ||
| data = { | ||
| "@context": { | ||
| "xsd": "http://www.w3.org/2001/XMLSchema#", | ||
| "geoLongitude": "http://www.w3.org/2003/01/geo/wgs84_pos#longitude" | ||
| }, | ||
| "@graph": [ | ||
| { | ||
| "@id": "http://www.wikidata.org/entity/Q399", | ||
| "geoLongitude": { | ||
| "@type": "xsd:double", | ||
| "@value": "45" # This string number causes the PyLD bug | ||
| } | ||
| } | ||
| ] | ||
| } | ||
mielvds marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # This should work now that the bug is fixed | ||
| # The bug was in PyLD's _object_to_rdf method where string values | ||
| # with @type: "xsd:double" were not being converted to float | ||
| result = pyld.jsonld.to_rdf(data) | ||
|
|
||
mielvds marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Expected result after bug fix | ||
| expected = { | ||
| "@default": [ | ||
| { | ||
| "subject": { | ||
| "type": "IRI", | ||
| "value": "http://www.wikidata.org/entity/Q399" | ||
| }, | ||
| "predicate": { | ||
| "type": "IRI", | ||
| "value": "http://www.w3.org/2003/01/geo/wgs84_pos#longitude" | ||
| }, | ||
| "object": { | ||
| "type": "literal", | ||
| "value": "4.5E1", | ||
| "datatype": "http://www.w3.org/2001/XMLSchema#double" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| self.assertEqual(result, expected) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.