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

questions about DefinedNamespaces (OWL, RDFS, etc etc) #1593

Closed
jclerman opened this issue Dec 26, 2021 · 3 comments · Fixed by #1626
Closed

questions about DefinedNamespaces (OWL, RDFS, etc etc) #1593

jclerman opened this issue Dec 26, 2021 · 3 comments · Fixed by #1626

Comments

@jclerman
Copy link
Contributor

I have some questions about the new DefinedNamespace:

  1. Can we restore a non-private API to get the URI of the namespace itself? Something like the uri() method on the now-deprecated ClosedNamespace:
rdflib.OWL.uri()   # "http://www.w3.org/2002/07/owl#"
  1. I couldn't find a documented way to get the complete set of URIs within a DefinedNamespace. It appears necessary to do something like this:
from rdflib import OWL, URIRef
owl_uris: Set[URIRef] = {OWL[str(x)] for x in OWL.__annotations__}  # this can be generalized to a function

It would be nice to have the above functionality implemented as, say, a method (on DefinedNamespaceMeta?). On ClosedNamespace, it looks like it was possible to get this result via dir(OWL), since __dir__ was defined on that class.

@edmondchuc
Copy link
Contributor

Can we restore a non-private API to get the URI of the namespace itself? Something like the uri() method on the now-deprecated ClosedNamespace

You can get the URI of a DefinedNamespace by calling str() on it.

>>> import rdflib
>>> str(rdflib.OWL)
'http://www.w3.org/2002/07/owl#'

I couldn't find a documented way to get the complete set of URIs within a DefinedNamespace. It appears necessary to do something like this

I've added this as a feature in this PR #1626.

@jclerman
Copy link
Contributor Author

You can get the URI of a DefinedNamespace by calling str() on it.

Thanks @edmondchuc! I realized that I also seem to have figured that out in another part of my brain, since I used it in the 2nd part of my question.

I've added this [a way to get the complete set of URIs within a DefinedNamespace ] as a feature in this PR #1626.

Nice, thank you. Regarding that PR, upon further thought, overriding __dir__ is perhaps not the best approach - it'd break code for anyone relying on the default behavior of dir(OWL). Is there any reason not to create a method uris() on the DefinedNamespace class instead?

Related but separate: I'm not clear why OWL, RDF, etc aren't designed as instances of the DefinedNamespace class, instead of subclasses of it. I would have thought that making them instances would be more intuitive - is there an advantage to them being classes?

@jclerman
Copy link
Contributor Author

Regarding that PR, upon further thought, overriding dir is perhaps not the best approach - it'd break code for anyone relying on the default behavior of dir(OWL). Is there any reason not to create a method uris() on the DefinedNamespace class instead?

Update: Apologies, I realize now why a public method is a problem, since it could collide with a member of the namespace.

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 a pull request may close this issue.

2 participants