Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema for schemas #826

Open
KevinDCarlson opened this issue Jul 11, 2023 · 0 comments
Open

Schema for schemas #826

KevinDCarlson opened this issue Jul 11, 2023 · 0 comments

Comments

@KevinDCarlson
Copy link
Contributor

KevinDCarlson commented Jul 11, 2023

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants