Skip to content

Commit

Permalink
Added context argument to get_prefixes()
Browse files Browse the repository at this point in the history
  • Loading branch information
jesper-friis committed Dec 30, 2024
1 parent 9b53f5e commit 26ee518
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 4 additions & 0 deletions tests/dataset/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def test_get_prefixes():
assert prefixes["dcat"] == "http://www.w3.org/ns/dcat#"
assert prefixes["emmo"] == "https://w3id.org/emmo#"

# Test context argument
prefixes2 = get_prefixes(context={"onto": "http://example.com/onto#"})
assert prefixes2["onto"] == "http://example.com/onto#"


def test_get_shortnames():
"""Test get_shortnames()."""
Expand Down
19 changes: 13 additions & 6 deletions tripper/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,22 @@ def get_jsonld_context(
return ctx


# TODO: update this to take an initial argument `context`.
# See get_jsonld_context()
def get_prefixes(timeout: float = 5) -> dict:
def get_prefixes(
context: "Optional[Union[str, dict, Sequence[Union[str, dict]]]]" = None,
timeout: float = 5,
fromfile: bool = True,
) -> dict:
"""Loads the JSON-LD context and returns a dict mapping prefixes to
their namespace URL."""
context = get_jsonld_context(timeout=timeout)
their namespace URL.
For arguments, see get_jsonld_context().
"""
ctx = get_jsonld_context(
context=context, timeout=timeout, fromfile=fromfile
)
prefixes = {
k: v
for k, v in context.items()
for k, v in ctx.items()
if isinstance(v, str) and v.endswith(("#", "/"))
}
return prefixes
Expand Down

0 comments on commit 26ee518

Please sign in to comment.