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

Compact URI Expansion #1

Open
Robsteranium opened this issue Jun 2, 2017 · 4 comments
Open

Compact URI Expansion #1

Robsteranium opened this issue Jun 2, 2017 · 4 comments

Comments

@Robsteranium
Copy link
Contributor

It would be nice to be able to expand CURIEs. We could do this with some sort of registry of prefixes.

Defining prefixes

We'd have an atom to act as a registry for prefixes. This would relate (with a hashmap) a prefix to a base URL.

(def prefix-registry (atom {}))
(defn defprefix [prefix uri] ...)

I'm not sure whether the prefix param should be a symbol, keyword (namespaced-keyword), or string... (or perhaps to provide an interface where more than one works).

(defprefix skos "http://www.w3.org/2004/02/skos/core#")
(defprefix :skos "http://www.w3.org/2004/02/skos/core#")
(defprefix ::skos "http://www.w3.org/2004/02/skos/core#")
(defprefix "skos" "http://www.w3.org/2004/02/skos/core#")

And we might want the uri to be a URI instead of a string... (coercing it might be more convenient)

(defprefix :skos (->uri "http://www.w3.org/2004/02/skos/core#"))

Using prefixes

(curie->uri "skos:Concept")
;;=> #<GrafterURL http://www.w3.org/2004/02/skos/core#Concept>

(uri->curie (->uri "http://www.w3.org/2004/02/skos/core#Concept"))
;;=> "skos:Concept"

Intern'd vars?

Not sure how this relates to e.g. skos:Concept - or if it even needs to...

@Robsteranium
Copy link
Contributor Author

@RickMoynihan has also suggested that these could be loaded into the registry as a consequence of loading the vocab namespace.

Also that:

I’d also recommend considering storing the prefix values in that map as tuples like [:skos :Concept] as I’d also like at some point to add data_readers for tagged literals like #grafter/uri [:skos :Concept] which would probably automatically load from edn as a URI…. also that tag would also work for #grafter/uri "http://"… we’d have a tag for #grafter/prefix [:skos :Concept] too — so e.g. #grafter/uri #grafter/prefix [:skos :Concept] would also do the right thing

@RickMoynihan
Copy link
Member

This is more or less exactly what I was thinking. Thanks for taking the time to write it up.

I think this should be the prefered way to define a prefix:

(defprefix :skos "http://www.w3.org/2004/02/skos/core#")

Also curie->uri should be a protocol so we can do the following:

(= (curie->uri "skos:Concept")
    (curie->uri [:skos :Concept])) ;; => true

I'd expect this to be two protocol definitions one for String and the other extending to the appropriate IPersistentVector. I think the canonical representation of a curie should be the vectorised form of [:skos :Concept] though so uri->curie should return that. I am all for having a convenience function for uri->curie-str though.

To clarify my above suggestion: "that these could be loaded into the registry as a consequence of loading the vocab namespace.". I think that this means loading the skos namespace should register the skos prefix for you too, but none skos prefixes shouldn't be loaded. i.e. we should do what you expect and no more.

@RickMoynihan
Copy link
Member

Oh also agree defprefix should be implemented to coerce strings and URI's; but all of them should be canonicalised to java.net.URI for reasons of equality etc.

@RickMoynihan
Copy link
Member

Terminology wise I think we should use the more common term prefix over curi though.

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

No branches or pull requests

2 participants