Daniel Filonik suggested the idea today of an implementation of schemas as instances, with conversion functions between them. This is cool for defining functors on the category of schemas using data migrations. Daniel's suggested code is below:
# Something like this should be defined in Catlab
@present SchAcsetSchema(FreeSchema) begin
Ob::Ob
Hom::Ob
AttrType::Ob
Attr::Ob
Hom_src::Hom(Hom,Ob)
Hom_tgt::Hom(Hom,Ob)
Attr_src::Hom(Attr,Ob)
Attr_tgt::Hom(Attr,AttrType)
Name::AttrType
Ob_name::Attr(Ob,Name)
Hom_name::Attr(Hom,Name)
AttrType_name::Attr(AttrType,Name)
Attr_name::Attr(Attr,Name)
end
@acset_type AcsetSchema(SchAcsetSchema)
# Along with something like this:
#schPropertyGraph = schema_to_instance(SchPropertyGraph)
schPropertyGraph = @acset AcsetSchema{String} begin
Ob = 2
Hom = 2
AttrType = 1
Attr = 2
Hom_src = [1,1]
Hom_tgt = [2,2]
Attr_src = [1,2]
Attr_tgt = [1,1]
Ob_name = ["E", "V"]
Hom_name = ["src", "tgt"]
AttrType_name = ["Props"]
Attr_name = ["eprops","vprops"]
end
# Something like this would be defined in the visualization library
@present SchVisGraph <: SchGraph begin
Label::AttrType
V_label::Attr(V,Label)
E_label::Attr(E,Label)
#Color::AttrType
#V_color::Attr(V,Color)
#E_color::Attr(E,Color)
end
@acset_type VisGraph(SchVisGraph)
# User defined mapping into the visualization schema
F = @migration SchVisGraph SchAcsetSchema begin
V => @cases (ob::Ob; attrType::AttrType)
E => @cases (hom::Hom; attr::Attr)
src => (hom => ob ∘ Hom_src; attr => ob ∘ Attr_src)
tgt => (hom => ob ∘ Hom_tgt; attr => attrType ∘ Attr_tgt)
Label => Name
V_label => (ob => Ob_name; attrType => AttrType_name)
E_label => (hom => Hom_name; attr => Attr_name)
#Color => ???
#V_color => (ob => (x) -> "#fff"; attrType => (x) -> "#000")
#E_color => (x) -> "#000"
end
# Migrate to the visualization schema and visualize
g = migrate(VisGraph{String}, schPropertyGraph, F)
forceDirectedGraph(g)
Daniel Filonik suggested the idea today of an implementation of schemas as instances, with conversion functions between them. This is cool for defining functors on the category of schemas using data migrations. Daniel's suggested code is below: