Skip to content

Commit

Permalink
Branch docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
mauro-milella committed Oct 25, 2024
1 parent 374e12b commit 5a5a6e8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 38 deletions.
1 change: 0 additions & 1 deletion src/SoleModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export posconsequent, negconsequent
export DecisionList
export rulebase, defaultconsequent


export DecisionTree
export root

Expand Down
71 changes: 34 additions & 37 deletions src/utils/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,6 @@ wrap(o::FunctionWrapper{O}) where {O} = FunctionModel{O}(o)
####################################### Rule ###############################################
############################################################################################

# this is never used
doc_symbolic_basics = """
Symbolic modeling builds onto two basic building blocks, which are `AbstractModel`s
themselves:
- `Rule`: IF (antecedent) THEN (consequent) END
- `Branch`: IF (antecedent) THEN (posconsequent) ELSE (negconsequent) END
The *antecedent* is a formula of a certain logic, that can typically evaluate to true or
false when the model is applied on an instance object;
the *consequent*s are `AbstractModel`s themselves, that are to be applied to the instance
object in order to obtain an outcome.
"""

"""
struct Rule{O} <: AbstractModel{O}
antecedent::Formula
Expand All @@ -235,7 +223,7 @@ julia> Rule(CONJUNCTION(Atom("p"), Atom("q")), ConstantModel(2))
▣ (p) ∧ (q) ↣ 2
```
See also [`AbstractModel`](@ref). [`antecedent`](@ref), [`consequent`](@ref),
See also [`AbstractModel`](@ref), [`antecedent`](@ref), [`consequent`](@ref),
`SoleLogics.Formula`.
"""
struct Rule{O} <: AbstractModel{O}
Expand Down Expand Up @@ -376,18 +364,13 @@ the semantics:
IF (antecedent) THEN (positive consequent) ELSE (negative consequent) END
where the antecedent is a formula to be checked and the consequents are the feasible
local outcomes of the block. If checking the antecedent evaluates to the top of the algebra,
then the positive consequent is applied; otherwise, the negative consequenti is applied.
where the [`antecedent`](@ref) is a formula to be checked and the [`consequent`](@ref)s are
the feasible local outcomes of the block. If checking the antecedent evaluates to the top
of the algebra, then the positive consequent is applied; otherwise, the negative
consequent is applied.
See also
[`antecedent`](@ref),
[`posconsequent`](@ref),
[`negconsequent`](@ref),
[`SoleLogics.check`](@ref),
[`SoleLogics.Formula`](@ref),
[`Rule`](@ref), [`AbstractModel`](@ref).
See also [`AbstractModel`](@ref), [`antecedent`](@ref), `SoleLogics.check`,
`SoleLogics.Formula`, [`negconsequent`](@ref), [`posconsequent`](@ref), [`Rule`](@ref).
"""
struct Branch{O} <: AbstractModel{O}
antecedent::Formula
Expand Down Expand Up @@ -423,24 +406,20 @@ antecedent(m::Branch) = m.antecedent
"""
posconsequent(m::Branch)::AbstractModel
Return the positive consequent of a branch;
that is, the model to be applied if the antecedent evaluates to `true`.
Return the positive consequent of a branch, that is, the model to be applied if the
[`antecedent`](@ref) evaluates to `true`.
See also
[`antecedent`](@ref),
[`Branch`](@ref).
See also [`antecedent`](@ref), [`Branch`](@ref), [`negconsequent`](@ref).
"""
posconsequent(m::Branch) = m.posconsequent

"""
negconsequent(m::Branch)::AbstractModel
Return the negative consequent of a branch;
that is, the model to be applied if the antecedent evaluates to `false`.
Return the negative [`consequent`](@ref) of a branch; that is, the model to be applied if
the antecedent evaluates to `false`.
See also
[`antecedent`](@ref),
[`Branch`](@ref).
See also [`antecedent`](@ref), [`Branch`](@ref), [`posconsequent`](@ref).
"""
negconsequent(m::Branch) = m.negconsequent

Expand Down Expand Up @@ -519,6 +498,8 @@ end

# Helper: slice a Branch's antecedent
# TODO remove?
# from michi and mauro, 25/10/24:
# currently this is not covered by tests here, but could be used in SolePostHoc.jl
function Base.getindex(
m::Branch{O},
idxs::AbstractVector,
Expand All @@ -531,9 +512,25 @@ end
############################################################################################
############################################################################################

checkantecedent(m::Union{Rule,Branch}, i::AbstractInterpretation, args...; kwargs...) = check(antecedent(m), i, args...; kwargs...)
checkantecedent(m::Union{Rule,Branch}, d::AbstractInterpretationSet, i_instance::Integer, args...; kwargs...) = check(antecedent(m), d, i_instance, args...; kwargs...)
checkantecedent(m::Union{Rule,Branch}, d::AbstractInterpretationSet, args...; kwargs...) = check(antecedent(m), d, args...; kwargs...)
checkantecedent(
m::Union{Rule,Branch},
i::AbstractInterpretation,
args...;
kwargs...
) = check(antecedent(m), i, args...; kwargs...)
checkantecedent(
m::Union{Rule,Branch},
d::AbstractInterpretationSet,
i_instance::Integer,
args...;
kwargs...
) = check(antecedent(m), d, i_instance, args...; kwargs...)
checkantecedent(
m::Union{Rule,Branch},
d::AbstractInterpretationSet,
args...;
kwargs...
) = check(antecedent(m), d, args...; kwargs...)

# TODO remove:
# checkantecedent(::Union{Rule{O,Top},Branch{O,Top}}, i::AbstractInterpretation, args...; kwargs...) where {O} = true
Expand Down

0 comments on commit 5a5a6e8

Please sign in to comment.