/
citeurn.jl
35 lines (30 loc) · 990 Bytes
/
citeurn.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""Constructs an `AbbreviatedUrn` string from a `Cite2Urn`.
$(SIGNATURES)
Example:
```julia-repl
julia> abbreviate(Cite2Urn("urn:cite2:kanones:lsj.v1:n123"))
"lsj.n123"
```
Example: a pipeline abbreviating a `Cite2Urn` and forming a `LexemeUrn`
from the abbreviated string value.
```julia-repl
julia> Cite2Urn("urn:cite2:kanones:lsj.v1:n123") |> abbreviate |> LexemeUrn
LexemeUrn("lsj", "n123")
```
"""
function abbreviate(urn::Cite2Urn)::String
string(collectionid(urn), ".", objectcomponent(urn))
end
"""Constructs a `Cite2Urn` from an `AbbreviatedUrn`
and a dictionary mapping collection identifiers in
AbbreviatedUrns's to full `Cite2Urn`s for a
versioned collection.
"""
function expand(au::AbbreviatedUrn, registry::Dict)
if au.collection in keys(registry)
Cite2Urn(registry[au.collection] * au.objectid)
else
msg = string("In abbreviated urn ", au, ", collection ", au.collection, " not in registry." )
throw(ArgumentError(msg))
end
end