From 3818c01db599400bd1f2596f22b8583c0b79d0ec Mon Sep 17 00:00:00 2001 From: ARCJ137442 <61109168+ARCJ137442@users.noreply.github.com> Date: Sun, 27 Aug 2023 17:26:09 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84):?= =?UTF-8?q?=20:recycle:=20=E7=8E=B0=E5=9C=A8=E6=8A=BD=E8=B1=A1=E9=99=88?= =?UTF-8?q?=E8=BF=B0=E4=B9=9F=E6=9C=89=E5=8F=82=E6=95=B0=E3=80=8C=E9=99=88?= =?UTF-8?q?=E8=BF=B0=E7=B1=BB=E5=9E=8B=E3=80=8D=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 外部扩展新类型陈述时,只需扩展新陈述类型并实现「新陈述具体类型 <: 抽象陈述{新陈述类型}」即可 --- src/Conversion/template.jl | 2 +- src/Narsese/terms.jl | 4 ++-- test/test_narsese.jl | 3 +++ test/test_types.jl | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 test/test_types.jl diff --git a/src/Conversion/template.jl b/src/Conversion/template.jl index 419e1b1..858e10e 100644 --- a/src/Conversion/template.jl +++ b/src/Conversion/template.jl @@ -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 diff --git a/src/Narsese/terms.jl b/src/Narsese/terms.jl index dfc1622..35d6812 100644 --- a/src/Narsese/terms.jl +++ b/src/Narsese/terms.jl @@ -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 # 具体结构定义 @@ -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 谓词 diff --git a/test/test_narsese.jl b/test/test_narsese.jl index 403e765..099842e 100644 --- a/test/test_narsese.jl +++ b/test/test_narsese.jl @@ -17,6 +17,9 @@ # 构造 # include("test_construction.jl") + # 类型 # + include("test_types.jl") + # 词项与数组等可迭代对象的联动方法 # include("test_methods.jl") diff --git a/test/test_types.jl b/test/test_types.jl new file mode 100644 index 0000000..6a5948f --- /dev/null +++ b/test/test_types.jl @@ -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