Skip to content

Commit

Permalink
refactor(数据结构): ♻️ 现在抽象陈述也有参数「陈述类型」了
Browse files Browse the repository at this point in the history
外部扩展新类型陈述时,只需扩展新陈述类型并实现「新陈述具体类型 <: 抽象陈述{新陈述类型}」即可
  • Loading branch information
ARCJ137442 committed Aug 27, 2023
1 parent 73cafb3 commit 3818c01
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Conversion/template.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ function register_parser_string_flag_macro(expr::Expr)
push!(
blk.args,
:(Conversion.get_parser_from_flag(::Val{$flag_symbol})::TAbstractParser = $parser_symbol)
)
)
end
end

Expand Down
4 changes: 2 additions & 2 deletions src/Narsese/terms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ abstract type AbstractCompound{type <: AbstractCompoundType} <: AbstractTerm end
function terms end

"[NAL-1]陈述词项の基石 | 协议:支持`terms`、`ϕ1`和`ϕ2`方法(无需绑定属性)"
abstract type AbstractStatement <: AbstractTerm end
abstract type AbstractStatement{type <: AbstractStatementType} <: AbstractTerm end
function ϕ1 end; function ϕ2 end

# 具体结构定义
Expand Down Expand Up @@ -749,7 +749,7 @@ begin "陈述词项"
> (3)为了简化语言,「T \⇔ S」总是被表示为「S /⇔ T」,所以关联词「\⇔」实际上并不在Narsese语法中。
> - 译者注:此举与先前的「外延并/内涵并」类似
"""
struct Statement{type <: AbstractStatementType} <: AbstractStatement
struct Statement{type <: AbstractStatementType} <: AbstractStatement{type}
ϕ1::AbstractTerm # subject 主词
ϕ2::AbstractTerm # predicate 谓词

Expand Down
3 changes: 3 additions & 0 deletions test/test_narsese.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
# 构造 #
include("test_construction.jl")

# 类型 #
include("test_types.jl")

# 词项与数组等可迭代对象的联动方法 #
include("test_methods.jl")

Expand Down
33 changes: 33 additions & 0 deletions test/test_types.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
(@isdefined JuNarsese) || include("commons.jl") # 已在此中导入JuNarsese、Test

@testset "types" begin

# 测试各类「抽象类型」
@test Intension <: AbstractEI >: Extension
@test And <: AbstractLogicOperation >: Or
@test Not <: AbstractLogicOperation
@test VTIndependent <: AbstractVariableType
@test Sequential <: AbstractTemporalRelation >: Parallel

# 测试「原子词项」
@test Word <: Atom <: Term
@test IVar <: Variable{VTIndependent} <: Var <: Variable <: Atom <: Term

# 测试「复合词项类型」
@test CompoundTypeTermProduct <: AbstractCompoundType
CompoundTypeTermImage{Extension} <: CompoundTypeTermImage

@test TermProduct <: CommonCompound{CompoundTypeTermProduct} <: AbstractCompound{CompoundTypeTermProduct} <: AbstractCompound <: AbstractTerm
@test TermProduct <: CommonCompound{CompoundTypeTermProduct} <: CommonCompound <: AbstractCompound <: AbstractTerm
@test ExtImage <: TermImage{Extension} <: AbstractCompound{CompoundTypeTermImage{Extension}} <: AbstractCompound{CompoundTypeTermImage{Extension}} <: AbstractCompound
@test IntImage <: TermImage{Intension} <: TermImage <: AbstractCompound

# 测试「陈述类型」
@test STInheritance <: AbstractStatementType
@test STImplication <: StatementTypeImplication{Eternal} <: StatementTypeImplication <: AbstractStatementType
@test STEquivalence <: StatementTypeEquivalence{Eternal} <: StatementTypeEquivalence <: AbstractStatementType

@test Inheritance <: Statement{STInheritance} <: AbstractStatement{StatementTypeInheritance} <: AbstractStatement <: AbstractTerm
@test Inheritance <: Statement{STInheritance} <: Statement <: AbstractStatement <: AbstractTerm

end

0 comments on commit 3818c01

Please sign in to comment.