From 364530340987aed0958792f59b0311c6d5383fbd Mon Sep 17 00:00:00 2001 From: giopaglia <24519853+giopaglia@users.noreply.github.com> Date: Thu, 7 Dec 2023 18:35:28 +1100 Subject: [PATCH] Minor and add parenthesize_modforms --- src/logisets/multilogiset.jl | 10 ++++++++-- src/logisets/supported-logiset.jl | 2 +- src/models/symbolic-utils.jl | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/logisets/multilogiset.jl b/src/logisets/multilogiset.jl index 7676b03..a9f83cf 100644 --- a/src/logisets/multilogiset.jl +++ b/src/logisets/multilogiset.jl @@ -225,6 +225,7 @@ function syntaxstring( f::MultiFormula; hidemodality = false, variable_names_map::Union{Nothing,AbstractDict,AbstractVector,AbstractVector{<:Union{AbstractDict,AbstractVector}}} = nothing, + parenthesize_modforms = true, kwargs... ) map_is_multimodal = begin @@ -240,8 +241,13 @@ function syntaxstring( end join([begin _variable_names_map = map_is_multimodal ? variable_names_map[i_modality] : variable_names_map - φ = syntaxstring(modforms(f)[i_modality]; variable_names_map = _variable_names_map, kwargs...) - hidemodality ? "$φ" : "{$(i_modality)}($φ)" + φ = modforms(f)[i_modality] + str = syntaxstring(φ; variable_names_map = _variable_names_map, kwargs...) + parenthesize = !(φ isa SyntaxBranch) || (φ isa SyntaxBranch && SoleLogics.isunary(token(φ))) + if parenthesize && parenthesize_modforms + str = "($str)" + end + hidemodality ? "$str" : "{$(i_modality)}$str" end for i_modality in sort(collect(keys(modforms(f))))], " $(CONJUNCTION) ") end diff --git a/src/logisets/supported-logiset.jl b/src/logisets/supported-logiset.jl index c1df0e6..6edd447 100644 --- a/src/logisets/supported-logiset.jl +++ b/src/logisets/supported-logiset.jl @@ -287,7 +287,7 @@ function displaystructure( ) padattribute(l,r) = string(l) * lpad(r,32+length(string(r))-(length(indent_str)+2+length(l))-1) pieces = [] - push!(pieces, "SupportedLogiset with $(nsupports(X)) supports ($(humansize(X)))") + push!(pieces, "SupportedLogiset with $(nsupports(X)) $(nsupports(X) == 1 ? "support" : "supports") ($(humansize(X)))") if ismissing(include_worldtype) || include_worldtype != worldtype(X) push!(pieces, " " * padattribute("worldtype:", worldtype(X))) end diff --git a/src/models/symbolic-utils.jl b/src/models/symbolic-utils.jl index e813688..544b144 100644 --- a/src/models/symbolic-utils.jl +++ b/src/models/symbolic-utils.jl @@ -123,6 +123,7 @@ _submodels(m::DecisionForest) = [Iterators.flatten(_submodels.(immediatesubmodel _submodels(m::MixedSymbolicModel) = [Iterators.flatten(_submodels.(immediatesubmodels(m)))...] nsubmodels(m::AbstractModel) = 1 + sum(nsubmodels, immediatesubmodels(m)) +nsubmodels(m::LeafModel) = 1 nsubmodels(m::DecisionList) = sum(nsubmodels, immediatesubmodels(m)) nsubmodels(m::DecisionTree) = sum(nsubmodels, immediatesubmodels(m)) nsubmodels(m::DecisionForest) = sum(nsubmodels, immediatesubmodels(m))