From f24b89f944a2d1f86a60f683d4c08c32b72264f4 Mon Sep 17 00:00:00 2001 From: giopaglia <24519853+giopaglia@users.noreply.github.com> Date: Mon, 24 Jul 2023 01:31:15 +0200 Subject: [PATCH 1/2] Clean syntaxstring and fix RCC accessibles --- .../full-dimensional-frame/Full1DFrame+RCC.jl | 12 +++---- src/general.jl | 31 ++++++++++--------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/algebras/frames/full-dimensional-frame/Full1DFrame+RCC.jl b/src/algebras/frames/full-dimensional-frame/Full1DFrame+RCC.jl index 20063b14..2eb03cca 100644 --- a/src/algebras/frames/full-dimensional-frame/Full1DFrame+RCC.jl +++ b/src/algebras/frames/full-dimensional-frame/Full1DFrame+RCC.jl @@ -2,12 +2,12 @@ # Refer to [`RCCRelation`](@ref). # Enumerate accessible worlds from a single world -_accessibles(fr::Full1DFrame, w::Interval, r::RCC8RelationFromIA) = Iterators.flatten((_accessibles(fr, w, IA_r) for IA_r in topo2IARelations(r))) -# _accessibles(fr::Full1DFrame, w::Interval, ::_Topo_DC) = Iterators.flatten((_accessibles(fr, w, IA_L), _accessibles(fr, w, IA_Li))) -# _accessibles(fr::Full1DFrame, w::Interval, ::_Topo_EC) = Iterators.flatten((_accessibles(fr, w, IA_A), _accessibles(fr, w, IA_Ai))) -# _accessibles(fr::Full1DFrame, w::Interval, ::_Topo_PO) = Iterators.flatten((_accessibles(fr, w, IA_O), _accessibles(fr, w, IA_Oi))) -# _accessibles(fr::Full1DFrame, w::Interval, ::_Topo_TPP) = Iterators.flatten((_accessibles(fr, w, IA_B), _accessibles(fr, w, IA_E))) -# _accessibles(fr::Full1DFrame, w::Interval, ::_Topo_TPPi) = Iterators.flatten((_accessibles(fr, w, IA_Bi), _accessibles(fr, w, IA_Ei))) +# _accessibles(fr::Full1DFrame, w::Interval, r::RCC8RelationFromIA) = Iterators.flatten((_accessibles(fr, w, IA_r) for IA_r in topo2IARelations(r))) +_accessibles(fr::Full1DFrame, w::Interval, ::_Topo_DC) = Iterators.flatten((_accessibles(fr, w, IA_L), _accessibles(fr, w, IA_Li))) +_accessibles(fr::Full1DFrame, w::Interval, ::_Topo_EC) = Iterators.flatten((_accessibles(fr, w, IA_A), _accessibles(fr, w, IA_Ai))) +_accessibles(fr::Full1DFrame, w::Interval, ::_Topo_PO) = Iterators.flatten((_accessibles(fr, w, IA_O), _accessibles(fr, w, IA_Oi))) +_accessibles(fr::Full1DFrame, w::Interval, ::_Topo_TPP) = Iterators.flatten((_accessibles(fr, w, IA_B), _accessibles(fr, w, IA_E))) +_accessibles(fr::Full1DFrame, w::Interval, ::_Topo_TPPi) = Iterators.flatten((_accessibles(fr, w, IA_Bi), _accessibles(fr, w, IA_Ei))) _accessibles(fr::Full1DFrame, w::Interval, ::_Topo_NTPP) = _accessibles(fr, w, IA_D) _accessibles(fr::Full1DFrame, w::Interval, ::_Topo_NTPPi) = _accessibles(fr, w, IA_Di) diff --git a/src/general.jl b/src/general.jl index 4ca2075f..2184ee49 100644 --- a/src/general.jl +++ b/src/general.jl @@ -55,7 +55,7 @@ where each syntactical element is wrapped in parentheses. # Examples ```julia-repl julia> syntaxstring((parsebaseformula("◊((p∧s)→q)"))) -"◊(p ∧ s) → q" +"◊((p ∧ s) → q)" julia> syntaxstring((parsebaseformula("◊((p∧s)→q)")); function_notation = true) "◊(→(∧(p, s), q))" @@ -657,10 +657,10 @@ function syntaxstring( parentheses_at_propositions = parentheses_at_propositions, )) - function _binary_infix_syntaxstring(t::SyntaxTree, ch::SyntaxTree; relation::Symbol=:left, kwargs...) + function _binary_infix_syntaxstring(tok::AbstractSyntaxToken, ch::SyntaxTree; relation::Symbol=:left) # syntaxstring triggered by a binary operator in infix notation - tok = token(t) chtok = token(ch) + chtokstring = syntaxstring(ch; ch_kwargs...) lpar, rpar = "", "" if !remove_redundant_parentheses @@ -668,10 +668,10 @@ function syntaxstring( end if arity(chtok) == 0 - if parentheses_at_propositions - return "($(syntaxstring(ch; kwargs...)))" + if chtok isa Proposition && parentheses_at_propositions + return "($(chtokstring))" else - return "$(lpar)$(syntaxstring(ch; kwargs...))$(rpar)" + return "$(lpar)$(chtokstring)$(rpar)" end end @@ -696,26 +696,27 @@ function syntaxstring( lpar, rpar = "(", ")" end - return "$(lpar)$(syntaxstring(ch; kwargs...))$(rpar)" + return "$(lpar)$(chtokstring)$(rpar)" end tok = token(t) + tokstr = syntaxstring(tok; ch_kwargs...) if arity(tok) == 0 - if parentheses_at_propositions - return "($(syntaxstring(tok; ch_kwargs...)))" + if tok isa Proposition && parentheses_at_propositions + return "($(tokstr))" else - return "$(syntaxstring(tok; ch_kwargs...))" + return tokstr end elseif arity(tok) == 2 && !function_notation # Previous idea # f = ch->arity(token(ch)) == 0 ? # "$(syntaxstring(ch; ch_kwargs...))" : # "$(lpar)$(syntaxstring(ch; ch_kwargs...))$(rpar)" - # "$(f(children(t)[1])) $(syntaxstring(tok; ch_kwargs...)) $(f(children(t)[2]))" + # "$(f(children(t)[1])) $(tokstr) $(f(children(t)[2]))" # Infix notation for binary operator - "$(_binary_infix_syntaxstring(t, children(t)[1]; relation=:left, ch_kwargs...)) $(syntaxstring(tok; ch_kwargs...)) $(_binary_infix_syntaxstring(t, children(t)[2]; relation=:right, ch_kwargs...))" - else + "$(_binary_infix_syntaxstring(tok, children(t)[1]; relation=:left)) $tokstr $(_binary_infix_syntaxstring(tok, children(t)[2]; relation=:right))" + else # Function notation lpar, rpar = "(", ")" if !function_notation && arity(tok) == 1 && arity(token(children(t)[1])) <= 1 # when not in function notation, print "¬p" instead of "¬(p)"; @@ -724,8 +725,8 @@ function syntaxstring( end length(children(t)) == 0 ? - syntaxstring(tok; ch_kwargs...) : - syntaxstring(tok; ch_kwargs...) * + tokstr : + tokstr * "$(lpar)" * join([syntaxstring(c; ch_kwargs...) for c in children(t)], ", ") * "$(rpar)" end end From c136b3dbc385bb8d06a17ce180843827f7268256 Mon Sep 17 00:00:00 2001 From: giopaglia <24519853+giopaglia@users.noreply.github.com> Date: Mon, 24 Jul 2023 01:31:24 +0200 Subject: [PATCH 2/2] Bump --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index d33175d3..ad54c3e6 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SoleLogics" uuid = "b002da8f-3cb3-4d91-bbe3-2953433912b5" authors = ["Mauro MILELLA", "Giovanni PAGLIARINI", "Eduard I. STAN"] -version = "0.4.4" +version = "0.4.5" [deps] DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"