Skip to content

Commit 8fd719a

Browse files
committed
Introduced leafmodelname
1 parent cbd1a6d commit 8fd719a

File tree

3 files changed

+6
-35
lines changed

3 files changed

+6
-35
lines changed

src/print.jl

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ end
162162

163163
function printmodel(
164164
io::IO,
165-
m::ConstantModel;
165+
m::LeafModel;
166166
header = DEFAULT_HEADER,
167167
indentation_str = "",
168168
show_subtree_info = false,
@@ -186,40 +186,7 @@ function printmodel(
186186
"" : "\n$(indentation_str)Info: $(info(m))")")
187187
end
188188
depth == 0 && show_symbols && print(io, MODEL_SYMBOL)
189-
print(io, " $(outcome(m))")
190-
(show_subtree_metrics || show_metrics != false) && print(io, " : $(get_metrics_string(m; (show_metrics isa NamedTuple ? show_metrics : [])...))")
191-
show_shortforms != false && haskey(info(m), :shortform) && print(io, "\t\t\t\t\t\t\tSHORTFORM: $(@_antecedent_syntaxstring info(m)[:shortform] m parenthesize_atoms syntaxstring_kwargs kwargs)")
192-
println(io, "")
193-
nothing
194-
end
195-
196-
function printmodel(
197-
io::IO,
198-
m::FunctionModel;
199-
header = DEFAULT_HEADER,
200-
indentation_str = "",
201-
depth = 0,
202-
show_subtree_info = false,
203-
show_subtree_metrics = false,
204-
show_metrics = false,
205-
show_shortforms = false,
206-
show_intermediate_finals = false,
207-
tree_mode = false,
208-
show_symbols = true,
209-
syntaxstring_kwargs = (;),
210-
parenthesize_atoms = true,
211-
kwargs...,
212-
)
213-
if header != false
214-
_typestr = string(header == true ? typeof(m) :
215-
header == :brief ? nameof(typeof(m)) :
216-
error("Unexpected value for parameter header: $(header).")
217-
)
218-
println(io, "$(indentation_str)$(_typestr)$((length(info(m)) == 0) ?
219-
"" : "\n$(indentation_str)Info: $(info(m))")")
220-
end
221-
depth == 0 && show_symbols && print(io, MODEL_SYMBOL)
222-
print(io, " $(f(m))")
189+
print(io, " $(leafmodelname(m))")
223190
(show_subtree_metrics || show_metrics != false) && print(io, " : $(get_metrics_string(m; (show_metrics isa NamedTuple ? show_metrics : [])...))")
224191
show_shortforms != false && haskey(info(m), :shortform) && print(io, "\t\t\t\t\t\t\tSHORTFORM: $(@_antecedent_syntaxstring info(m)[:shortform] m parenthesize_atoms syntaxstring_kwargs kwargs)")
225192
println(io, "")

src/types/model.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ abstract type LeafModel{O} <: AbstractModel{O} end
386386

387387
LeafModel(o) = wrap(o)
388388

389+
leafmodelname(o::LeafModel) = error("Please, provide method leafmodelname(::$(typeof(o))).")
390+
389391
immediatesubmodels(m::LeafModel{O}) where {O} = Vector{<:AbstractModel{<:O}}[]
390392
nimmediatesubmodels(m::LeafModel) = 0
391393
listimmediaterules(m::LeafModel) = [Rule(⊤, m)]

src/utils/models/leaf.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Return the constant outcome wrapped by `m`.
5656
See also [`ConstantModel`](@ref).
5757
"""
5858
outcome(m::ConstantModel) = m.outcome
59+
leafmodelname(m::ConstantModel) = string(outcome(m))
5960

6061
iscomplete(::ConstantModel) = true
6162

@@ -172,6 +173,7 @@ See also [`FunctionModel`](@ref),
172173
[FunctionWrappers](https://github.com/yuyichao/FunctionWrappers.jl).
173174
"""
174175
f(m::FunctionModel) = m.f
176+
leafmodelname(m::FunctionModel) = string(f(m))
175177

176178
iscomplete(::FunctionModel) = true
177179

0 commit comments

Comments
 (0)