Skip to content

Commit

Permalink
Add JSON-LD to guess_format()
Browse files Browse the repository at this point in the history
Now that the `rdflib` package provides the functionality formerly in the
package `rdflib-jsonld`, it would be helpful for the utility function
`guess_format` to recognize file extensions indicative of JSON-LD
content.

This patch adds recognition of two file extensions, preserving syntax of
the `SUFFIX_FORMAT_MAP` variable:
* `.json`
* `.jsonld`

The latter is in recognition of the IANA media type
`application/ld+json` reporting the `.jsonld` file extension.
References:
https://www.iana.org/assignments/media-types/application/ld+json
via https://www.iana.org/assignments/media-types/media-types.xhtml
via https://w3c.github.io/json-ld-syntax/#iana-considerations

Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
  • Loading branch information
ajnelson-nist committed Sep 7, 2021
1 parent 2721658 commit e778e94
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rdflib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ def parse_date_time(val):
"svg": "rdfa",
"nq": "nquads",
"trig": "trig",
"json": "json-ld",
"jsonld": "json-ld",
}


Expand All @@ -378,6 +380,8 @@ def guess_format(fpath, fmap=None):
'xml'
>>> guess_format('path/to/file.ttl')
'turtle'
>>> guess_format('path/to/file.json')
'json-ld'
>>> guess_format('path/to/file.xhtml')
'rdfa'
>>> guess_format('path/to/file.svg')
Expand Down

0 comments on commit e778e94

Please sign in to comment.