AlgebraicJulia / AlgebraicJulia/Catlab.jl

Schema for schemas

未关闭
#826 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
acsets enhancement
主要语言
Julia
星标
724
派生
73
PR 合并指标
30 天内没有已合并 PR

描述

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:
```julia
# 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)
```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。