Skip to content

Commit

Permalink
ADTsbase replaced with ADTsCore - Only contains neccessary ADT featur…
Browse files Browse the repository at this point in the history
…es for RelationTerm so far.

RelationTerm now compiling.
  • Loading branch information
cscaff committed Oct 18, 2024
1 parent 11df8de commit b21091f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 100 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
CompTime = "0fb5dd42-039a-4ca4-a1d7-89a96eae6d39"
Compose = "a81c6b42-2e10-5240-aca2-a61377ecd94b"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
DiagrammaticEquations = "6f00c28b-6bed-4403-80fa-30e0dc12f317"
GATlab = "f0ffcf3b-d13a-433e-917c-cc44ccf5ead2"
GeneralizedGenerated = "6b9d7cbe-bcb9-11e9-073f-15a7a543e2eb"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
Expand Down
4 changes: 2 additions & 2 deletions src/ADTs/ADTs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module ADTs

using Reexport

include("ADTsCore.jl")
include("RelationTerm.jl")
include("ADTsBase.jl")

@reexport using .ADTsCore
@reexport using .RelationTerm
@reexport using .ADTsBase

end
68 changes: 0 additions & 68 deletions src/ADTs/ADTsBase.jl

This file was deleted.

37 changes: 37 additions & 0 deletions src/ADTs/ADTsCore.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
""" This module contains the basic components of an Abstract Term for constructing an ADT
"""

module ADTsCore

using MLStyle

export AbstractTerm

""" AbstractTerm
The super type for all ADT types. This abstract type exists so that we can write generic methods that work on any term in any of the domain specific syntaxes.
For example, serializing to a Dictionary uses some reflection snippet that works for arbitrary types, but we only want to apply it to things that should be serialized like a Term.
"""
abstract type AbstractTerm end

""" Header
1. Marks the header of our UWDModel. Provides basic metadata.
2. amr_to_string() allows us to represent the header as a string.
"""

@as_record struct Header <: AbstractTerm
name::String
schema::String
description::String
schema_name::String
model_version::String
end

function amr_to_string(amr)
@match amr begin
Header(name, s, d, sn, mv) => "\"\"\"\nASKE Model Representation: $name$mv :: $sn \n $s\n\n$d\n\"\"\""
end
end

end
30 changes: 5 additions & 25 deletions src/ADTs/RelationTerm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,17 @@ module RelationTerm

export Var, Typed, Untyped, Statement, UWDExpr, UWDModel, UWDTerm, context

using ..ADTsBase

using MLStyle
using StructTypes
using ..ADTsCore
using ...Programs.RelationalPrograms
using ...WiringDiagrams.UndirectedWiringDiagrams
import Base: show


@doc """ Header
1. Marks the header of our UWDModel. Provides basic metadata.
2. amr_to_string() allows us to represent the header as a string.
"""

@as_record struct Header <: AbstractTerm
name::String
schema::String
description::String
schema_name::String
model_version::String
end

function amr_to_string(amr)
@match amr begin
Header(name, s, d, sn, mv) => "\"\"\"\nASKE Model Representation: $name$mv :: $sn \n $s\n\n$d\n\"\"\""
end
@data Var <: AbstractTerm begin
Untyped(var::Symbol)
Typed(var::Symbol, type::Symbol)
end

@doc """ Var
Expand All @@ -48,10 +32,6 @@ Subtypes include:
which are used for representing typed or untyped variables.
"""
@data Var <: AbstractTerm begin
Untyped(var::Symbol)
Typed(var::Symbol, type::Symbol)
end

Var

Expand All @@ -62,7 +42,7 @@ StructTypes.subtypes(::Type{Var}) = (Untyped=Untyped, Typed=Typed)
@data UWDTerm <: AbstractTerm begin
Statement(relation::Symbol, variables::Vector{Var})
UWDExpr(context::Vector{Var}, statements::Vector{Statement})
UWDModel(header::AMR.Header, uwd::UWDExpr)
UWDModel(header::ADTsCore.Header, uwd::UWDExpr)
end

@doc """ UWDTerm
Expand Down
9 changes: 4 additions & 5 deletions test/parsers/RelationalParser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ __precompile__(false) #REMOVE
# ## Testing our parser
module ParserTests
using Test
using SyntacticModels
using SyntacticModels.ASKEMUWDs
using Catlab.ADTs.RelationTerm
using Catlab.Programs.RelationalPrograms
using Catlab.Parsers.RelationalParser

Expand Down Expand Up @@ -70,7 +69,7 @@ end
@test uwd("""{R(a,b); S(b,c);}
where {a:A,b:B,c:C}""")[1].statements == [Statement(:R, [Typed(:a, :A), Typed(:b, :B)]),
Statement(:S, [Typed(:b, :B), Typed(:c, :C)])]
@test uwd("""{R(a,b); S(b,c);} where {a:A,b:B,c:C}""")[1] isa ASKEMUWDs.UWDExpr
@test uwd("""{R(a,b); S(b,c);} where {a:A,b:B,c:C}""")[1] isa RelationTerm.UWDExpr
end

# Test Error Handling:
Expand Down Expand Up @@ -128,7 +127,7 @@ end
s = [Statement(:R, [v1,v2]),
Statement(:S, [v2,v3])]
u = UWDExpr(c, s)
uwd_result = ASKEMUWDs.construct(RelationDiagram, u)
uwd_result = RelationTerm.construct(RelationDiagram, u)

@test parsed_result == uwd_result

Expand Down Expand Up @@ -156,7 +155,7 @@ end
Statement(:S, [v2,v3]),
Statement(:T, [v3,v2, v4])]
u = UWDExpr(c, s)
uwd_result = ASKEMUWDs.construct(RelationDiagram, u)
uwd_result = RelationTerm.construct(RelationDiagram, u)

@test parsed_result == uwd_result

Expand Down

0 comments on commit b21091f

Please sign in to comment.