Skip to content

Commit

Permalink
minor changes:
Browse files Browse the repository at this point in the history
* Changed the tests to use an in-module fixture instead of the
  `test_ontology.owl` graph and removed the `test_ontology.owl` file. The
  problem with arbitrary test data is that it is hard to evolve. If possible
  test data should be kept as terse as possible. In this case I just created a
  namespace manager with three namespaces added, of which only two will be
  effective because of <#2077>.
* Added a warning to `NamespaceManager.curie` to warn users that it is not a
  pure function and explain the specific side effects.
  • Loading branch information
aucampia committed May 18, 2023
1 parent 21d4151 commit 598f967
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 371 deletions.
23 changes: 20 additions & 3 deletions rdflib/namespace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,27 @@ def qname(self, uri: str) -> str:
return ":".join((prefix, name))

def curie(self, uri: str) -> str:
"""From a URI, generate a valid CURIE.
"""
From a URI, generate a valid CURIE.
Result is guaranteed to contain a colon separating the prefix from the
name, even if the prefix is an empty string.
.. warning::
If there is no matching namespace for the URI in the namespace
manager then a new namespace will be added with prefix
``ns{index}``.
Because of this side effect this is not a pure function.
This is the same behaviour as `NamespaceManager.qname`.
:param uri: URI to generate CURIE for.
:return: CURIE for the URI.
Result is guaranteed to contain a colon separating the prefix from the name,
even if the prefix is an empty string.
"""
prefix, namespace, name = self.compute_qname(uri)
return ":".join((prefix, name))
Expand Down
315 changes: 0 additions & 315 deletions test/data/owl/test_ontology.owl

This file was deleted.

Loading

0 comments on commit 598f967

Please sign in to comment.