Hi everyone,
I’d like to announce the Metadata.jl. It attempts to provide a generic and common interface for attaching and extracting metadata. This is mostly done by assuming that metadata has Symbol
keys. Metadata can be attached to anything using attach_metadata
and extracted using metadata
julia> using Metadata
julia> x = attach_metadata(ones(2, 2), Dict{Symbol,Any}(:x => 1, :y => 2, :suppress=> [:x]))
2×2 attach_metadata(::Array{Float64,2}, ::Dict{Symbol,Any}
• metadata:
y = 2
x = <suppressed>
)
1.0 1.0
1.0 1.0
julia> metadata(x) == Dict{Symbol,Any}(:x => 1, :y => 2, :suppress=>[:x])
true
julia> metadata(x, :x)
1
julia> metadata!(x, :z, 3);
julia> x
2×2 attach_metadata(::Array{Float64,2}, ::Dict{Symbol,Any}
• metadata:
y = 2
z = 3
x = <suppressed>
)
1.0 1.0
1.0 1.0
It also provides macros inspired by the design of Base.Doc
and this converstion. These macros use the object id (objectid
) of an instance to store metadata in a global dictionary within a given module. In the following example you can see this permits attaching metadata to a type without having to wrap it in a structure.
julia> x = ones(2,2);
julia> @attach_metadata(x, Dict{Symbol,Any}(:x => 1, :y => 2))
julia> @metadata(x)
Dict{Symbol,Any} with 3 entries:
:y => 2
:x => 1
julia> @metadata!(x, :z, 3)
Dict{Symbol,Any} with 4 entries:
:y => 2
:z => 3
:x => 1
This isn’t an exhaustive list of all the methods provided (more on that in the README and docs), but hopefully it’s a helpful place for most people to start.