Skip to content

Commit

Permalink
fixed label support
Browse files Browse the repository at this point in the history
  • Loading branch information
olynch committed Jul 19, 2021
1 parent a9fe63b commit 2fadb75
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/Examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ using ..Boxes
ot::Hom(O,T)
os::Hom(O,S)
N::Data
L::Data
rate::Attr(T,N)
concentration::Attr(S,N)
species_label::Attr(S,L)
transitions_label::Attr(T,L)
end

const ReactionNet = ACSetType(TheoryReactionNet)

@semagramschema ReactionNetSema(TheoryReactionNet) begin
@box S Circle
@box T Square
@box S Circle :species_label
@box T Square :transitions_label
@wire I(is,it)
@wire O(ot,os)
@data N Numeric
Expand Down
10 changes: 6 additions & 4 deletions src/Muesli.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ generic_to_json(x) = Dict(string(fn)=>to_json(getfield(x,fn)) for fn ∈ fieldna
and and attempts to convert to the type passed in.
"""
from_json(x,T) = convert(T,x) # fallback
from_json(x::String,::Type{Symbol}) = Symbol(x)
from_json(x::String, ::Type{Symbol}) = Symbol(x)
from_json(x::String, ::Type{Union{Symbol, Nothing}}) = Symbol(x)
from_json(x::Symbol, ::Type{String}) = string(x)

function from_json(x::Vector{Any},::Type{Vector{T}}) where {T}
map(y -> from_json(y,T), x)
Expand All @@ -62,8 +64,8 @@ function from_json(d::Dict{String,Any}, ::Type{Dict{Symbol,T}}) where {T}
Dict(Symbol(k) => from_json(v,T) for (k,v) in d)
end

function from_json(d::Vector{Tuple{Int,T}}, ::Type{Dict{Int,T}}) where {T}
Dict(Int(i) => x for (i,x) in d)
function from_json(d::Vector{Tuple{Int,T}}, ::Type{Dict{Int,S}}) where {T,S}
Dict(Int(i) => from_json(x,S) for (i,x) in d)
end

function from_json(s::String, ::Type{T}) where {T <: Real}
Expand All @@ -75,7 +77,7 @@ function generic_from_json(d::Dict{String,<:Any},::Type{T}) where {T}
for (i,fn) in enumerate(fieldnames(T))
sfn = string(fn)
if sfn keys(d)
augmented[fn] = from_json(d[string(fn)],fieldtypes(T)[i])
augmented[fn] = from_json(d[sfn],fieldtypes(T)[i])
else
augmented[fn] = missing
end
Expand Down
6 changes: 3 additions & 3 deletions src/Schema.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ end
struct BoxProperties
weights::Vector{Tuple{AttributeType, Symbol}}
shape::String
label::Union{Symbol,Missing}
label::Union{Symbol,Nothing}
end

to_json(x::BoxProperties) = generic_to_json(x)
Expand Down Expand Up @@ -80,8 +80,8 @@ from_json(d::Dict{String, <:Any}, ::Type{SemagramSchema}) = generic_from_json(d,
struct BoxDesc
name::Symbol
shape::SVGNode
label::Union{Symbol,Missing}
function BoxDesc(name,shape=Circle,label=missing)
label::Union{Symbol,Nothing}
function BoxDesc(name,shape=Circle,label=nothing)
new(name,shape, label)
end
end
Expand Down

0 comments on commit 2fadb75

Please sign in to comment.