Skip to content

Commit

Permalink
feat: Check for JSON result format to get_bindings_from_query_result
Browse files Browse the repository at this point in the history
The default return format for SPARQLWrapper is XML, since the format
option cannot be set from an already retrieved QueryResult set and the
function depends on JSON results, raise an error if the set result
format is not JSON.
  • Loading branch information
lu-pl committed Jul 26, 2024
1 parent f4c0448 commit 712e27e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rdfproxy/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

def get_bindings_from_query_result(query_result: QueryResult) -> Iterator[dict]:
"""Extract just the bindings from a SPARQLWrapper.QueryResult."""
if (result_format := query_result.requestedFormat) != "json":
raise Exception(
"Only QueryResult objects with JSON format are currently supported. "
f"Received object with requestedFormat '{result_format}'."
)

query_json = cast(Mapping, query_result.convert())
bindings = map(
lambda binding: valmap(lambda v: v["value"], binding),
Expand Down

0 comments on commit 712e27e

Please sign in to comment.