Skip to content
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

resolve issue1868, add a method to expand qname to URI #1869

Merged
merged 15 commits into from Apr 28, 2022
Merged

resolve issue1868, add a method to expand qname to URI #1869

merged 15 commits into from Apr 28, 2022

Conversation

ghost
Copy link

@ghost ghost commented Apr 25, 2022

Summary of changes

In response to issue #1868:

“I sometimes need use the reverse of qname() to make the URI input more human-friendly. It would be great if we have something like resolve_qname() which would translate a qname ns:obj back to http://example.com/ns#object”

Seems a reasonable enough request and trivial to resolve... add NamespaceManager method expand_qname and tests.

Checklist

  • Checked that there aren't other open pull requests for
    the same change.
  • Added tests for any changes that have a runtime impact.
  • Checked that all tests and type checking passes.
  • For changes that have a potential impact on users of this project:
    • Updated relevant documentation to avoid inaccuracies.
    • Considered adding additional documentation.
    • Considered adding an example in ./examples for new features.
    • Considered updating our changelog (CHANGELOG.md).
  • Considered granting push permissions to the PR branch,
    so maintainers can fix minor issues and keep your PR up to date.

rdflib/namespace/__init__.py Outdated Show resolved Hide resolved
rdflib/namespace/__init__.py Outdated Show resolved Hide resolved
Copy link
Member

@aucampia aucampia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to make the suggested changes if you want.

ns = self.store.namespace(curie.split(":")[0])
if ns is not None:
return URIRef(str(ns) + curie.split(":")[1])
return None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also a bit on the fence on returning None, I would just raise an error, but I would not say this is wrong, would like to hear some other opinions on the matter.

CC: @RDFLib/core-reviewers

Copy link
Member

@nicholascar nicholascar Apr 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer raising an error: if the thing asked for cannot be calculated, an error should be returned, not None which just indicates it doesn't exist. This is a calculation function, not a look up value function.

@aucampia
Copy link
Member

aucampia commented Apr 26, 2022

Made a PR against your branch changes logic slightly to be more compliant with CURIE spec:

Fix handling of blank CURIE reference and references with multiple colons
@aucampia aucampia requested a review from a team April 26, 2022 21:13
Copy link
Member

@aucampia aucampia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @gjhiggins, very useful method to have.

Copy link
Contributor

@edmondchuc edmondchuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, looks good.

@nicholascar nicholascar merged commit 047f805 into RDFLib:master Apr 28, 2022
@ghost ghost deleted the issue1868 branch April 28, 2022 09:56
@dany-nonstop
Copy link

many thanks @gjhiggins for answering the feature request and adding this new feature. It works beautifully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants