Skip to content

Use rdflib 6.0.1 features #15

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

Merged
merged 2 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 4 additions & 24 deletions case_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,13 @@

__version__ = "0.2.1"

import warnings

import rdflib.util

from . import local_uuid

def guess_format(fpath, fmap=None):
"""
This function is a wrapper around rdflib.util.guess_format(), adding that the .json extension should be recognized as JSON-LD.

:param fpath: File path.
:type fpath: string

:param fmap: Mapper dictionary; see rdflib.util.guess_format() for further description. Note that as in rdflib 5.0.0, supplying this argument overwrites, not augments, the suffix format map used by rdflib.
:type fmap: dict

:returns: RDF file format, fit for rdflib.Graph.parse() or .serialize(); or, None if file extension not mapped.
:rtype: string
"""

assert fmap is None or isinstance(fmap, dict), "Type check failed"

if fmap is None:
updated_fmap = {key:rdflib.util.SUFFIX_FORMAT_MAP[key] for key in rdflib.util.SUFFIX_FORMAT_MAP}
if not "json" in updated_fmap:
updated_fmap["json"] = "json-ld"
if not "jsonld" in updated_fmap:
updated_fmap["jsonld"] = "json-ld"
else:
updated_fmap = {k:fmap[k] for k in fmap}
warnings.warn("The functionality in case_utils.guess_format is now upstream. Please revise your code to use rdflib.util.guess_format. The function arguments remain the same. case_utils.guess_format will be removed in case_utils 0.4.0.", DeprecationWarning)

return rdflib.util.guess_format(fpath, updated_fmap)
return rdflib.util.guess_format(fpath, fmap)
2 changes: 1 addition & 1 deletion case_utils/case_sparql_construct/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def main():

in_graph = rdflib.Graph()
for in_graph_filename in args.in_graph:
in_graph.parse(in_graph_filename, format=case_utils.guess_format(in_graph_filename))
in_graph.parse(in_graph_filename)
_logger.debug("len(in_graph) = %d.", len(in_graph))

out_graph = rdflib.Graph()
Expand Down
2 changes: 1 addition & 1 deletion case_utils/case_sparql_select/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def main():

graph = rdflib.Graph()
for in_graph_filename in args.in_graph:
graph.parse(in_graph_filename, format=case_utils.guess_format(in_graph_filename))
graph.parse(in_graph_filename)

# Inherit prefixes defined in input context dictionary.
nsdict = {k:v for (k,v) in graph.namespace_manager.namespaces()}
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers =
install_requires =
pandas
pyparsing < 3.0.0
rdflib >= 6.0.0
rdflib >= 6.0.1
requests
tabulate
packages = find:
Expand Down
2 changes: 1 addition & 1 deletion tests/case_file/test_case_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

def load_graph(filename):
in_graph = rdflib.Graph()
in_graph.parse(filename, format=rdflib.util.guess_format(filename))
in_graph.parse(filename)
return in_graph

@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _test_templates_with_blank_nodes_result(filename):
ground_truth_negative = set()

graph = rdflib.Graph()
graph.parse(filename, format=case_utils.guess_format(filename))
graph.parse(filename)

computed = set()
query_string = """\
Expand Down
2 changes: 0 additions & 2 deletions tests/case_utils/test_guess_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ def test_rdflib_util_guess_format_ttl_default():
def test_rdflib_util_guess_format_ttl_fmap():
assert rdflib.util.guess_format(PATH_TO_TTL, FMAP_XHTML_GRDDL) == "turtle", "Failed to recognize .ttl RDF file extension when using fmap"

@pytest.mark.xfail(reason="rdflib 5.0.0 known to not recognize .json", strict=True)
def test_rdflib_util_guess_format_json():
assert rdflib.util.guess_format(PATH_TO_JSON) == "json-ld", "Failed to recognize .json RDF file extension"

@pytest.mark.xfail(reason="rdflib 5.0.0 known to not recognize .jsonld", strict=True)
def test_rdflib_util_guess_format_jsonld():
assert rdflib.util.guess_format(PATH_TO_JSONLD) == "json-ld", "Failed to recognize .jsonld RDF file extension"

Expand Down
4 changes: 2 additions & 2 deletions tests/src/glom_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
def main():
g = rdflib.Graph()
for in_graph in args.in_graph:
g.parse(in_graph, format=case_utils.guess_format(in_graph))
g.serialize(args.out_graph, format=case_utils.guess_format(args.out_graph))
g.parse(in_graph)
g.serialize(args.out_graph)

if __name__ == "__main__":
import argparse
Expand Down
4 changes: 2 additions & 2 deletions tests/src/isomorphic_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def main():
g1 = rdflib.Graph()
g2 = rdflib.Graph()

g1.parse(args.in_graph_1, format=case_utils.guess_format(args.in_graph_1))
g2.parse(args.in_graph_2, format=case_utils.guess_format(args.in_graph_2))
g1.parse(args.in_graph_1)
g2.parse(args.in_graph_2)

#_logger.debug("type(g1) = %r.", type(g1))
#_logger.debug("type(g2) = %r.", type(g2))
Expand Down