Term

Struct Term 

Source
pub struct Term { /* private fields */ }
Expand description

作为「结构」的词项

  • 🚩更多通过「复合」而非「抽象特征-具体实现」复用代码
    • 📍【2024-04-20 21:13:20】目前只需实现OpenNARS 1.5.8的东西

! ⚠️【2024-04-20 21:47:08】暂不实现「变量 < 原子 < 复合」的逻辑

  • 🎯OpenNARS中有关「词项顺序」的概念,目的是保证「无序不重复集合」的唯一性

    • 🚩然而此实现的需求用「派生Ord」虽然造成逻辑不同,但可以满足需求
    • 📌核心逻辑:实现需求就行,没必要(也很难)全盘照搬
  • ⚠️Hash特征不能在手动实现的PartialEq中实现,否则会破坏「散列一致性」

  • 📝OpenNARS在「记忆区构造词项」时,就会进行各种预处理

    • 📄<(-, {A, B}, {A}) --> x> 会产生 <{B} --> x>(外延「差」规则)
  • 📝OpenNARS中的词项基本只能通过make系列方法(从外部)构造

    • 💭这似乎意味着它是一种「记忆区专用」的封闭数据类型
  • 📌【2024-06-16 11:42:25】目前应手动实现Ord

    • ⚠️在「重排唯一化」的需求场景下需要「变量之间均相等」
      • 🚩目前要对「重排唯一化」做单独实现:Ord需要与PartialEq对齐
    • 💭大多情况下不会用到「比大小」逻辑,场景如「排序」
    • ⚠️不能破坏「比对为等」和「直接判等」的一致性:原先不比对is_constant字段,就已经破坏了这点

§📄OpenNARS

Term is the basic component of Narsese, and the object of processing in NARS. A Term may have an associated Concept containing relations with other Terms. It is not linked in the Term, because a Concept may be forgot while the Term exists. Multiple objects may represent the same Term.

§作为特征的「实现」

§Cloneable => Clone

Make a new Term with the same name.

§equals => Eq

Equal terms have identical name, though not necessarily the same reference.

§hashCode => Hash

Produce a hash code for the term

§compareTo => Ord

Orders among terms: variable < atomic < compound

§toString => [Display]

The same as getName by default, used in display only.

@return The name of the term as a String

Implementations§

Source§

impl Term

Source

pub fn make_word(name: impl Into<String>) -> Term

制作「词语」

Source

pub fn make_placeholder() -> Term

制作「占位符」

Source

pub fn make_var_i(to_max: impl MaximumVariableId) -> Term

制作「独立变量」

Source

pub fn make_var_d(to_max: impl MaximumVariableId) -> Term

制作「非独变量」

Source

pub fn make_var_q(to_max: impl MaximumVariableId) -> Term

制作「查询变量」

Source

pub fn make_var_similar(from: &Term, id: impl Into<usize>) -> Term

制作「与现有变量类型相同」的变量

  • 🚩类型相同但编号不同
  • 🎯用于「变量推理」中的「重命名变量」
Source

pub fn make_compound_term( template: CompoundTermRef<'_>, components: Vec<Term>, ) -> Option<Term>

📄OpenNARS public static Term makeCompoundTerm(CompoundTerm compound, ArrayList<Term> components)

Source

pub fn make_compound_term_or_statement( template: CompoundTermRef<'_>, components: Vec<Term>, ) -> Option<Term>

Source

pub fn make_compound_term_from_identifier( identifier: impl AsRef<str>, argument: Vec<Term>, ) -> Option<Term>

📄OpenNARS public static Term makeCompoundTerm(String op, ArrayList<Term> arg)

Source

pub fn make_set_ext(t: Term) -> Option<Term>

制作一个外延集

Source

pub fn make_set_ext_arg(argument: Vec<Term>) -> Option<Term>

制作一个外延集

Source

pub fn make_set_int(t: Term) -> Option<Term>

制作一个内涵集

Source

pub fn make_set_int_arg(argument: Vec<Term>) -> Option<Term>

制作一个内涵集

Source

pub fn make_intersection_ext(term1: Term, term2: Term) -> Option<Term>

Source

pub fn make_intersection_ext_arg(argument: Vec<Term>) -> Option<Term>

  • 📝同时包括「用户输入」与「从参数构造」两种来源
  • 📄来源1:结构规则「structuralCompose2」
  • 🆕现在构造时也会用reduce逻辑尝试合并
Source

pub fn make_intersection_ext_vec(terms: Vec<Term>) -> Option<Term>

  • 🚩只依照集合数量进行化简
Source

pub fn make_intersection_int(term1: Term, term2: Term) -> Option<Term>

Source

pub fn make_intersection_int_arg(argument: Vec<Term>) -> Option<Term>

  • 📝同时包括「用户输入」与「从参数构造」两种来源
  • 📄来源1:结构规则「structuralCompose2」
  • 🆕现在构造时也会用reduce逻辑尝试合并
Source

pub fn make_intersection_int_vec(terms: Vec<Term>) -> Option<Term>

  • 🚩只依照集合数量进行化简
Source

pub fn make_difference_ext(left: Term, right: Term) -> Option<Term>

Source

pub fn make_difference_int(left: Term, right: Term) -> Option<Term>

Source

pub fn make_product_arg(argument: Vec<Term>) -> Option<Term>

Source

pub fn make_product( image: CompoundTermRef<'_>, component: &Term, ) -> Option<[Term; 2]>

  • 🚩从「外延像/内涵像」构造,用某个词项替换掉占位符处的元素,并返回新的关系词项
    • 📄(/, R, _, b), a => [(*, a, b), R]
  • 📝<a --> (/, R, _, b)> => <(*, a, b) --> R>,其中就要用 a 替换 [R,b] 中的R
  • ⚠️【2024-06-16 16:29:18】后续要留意其中与OpenNARS「占位符不作词项」逻辑的不同
Source

pub fn make_image_ext_vec(argument: impl Into<Vec<Term>>) -> Option<Term>

  • 🚩从解析器构造外延像
  • ⚠️参数argument中含有「占位符」词项
    • ✅这点和OpenNARS相同
§📄OpenNARS中的例子
  • 📄argList=[reaction, _, base] => argument=[reaction, base], index=0
    • => “(/,reaction,_,base)”
  • 📄argList=[reaction, acid, _] => argument=[acid, reaction], index=1
    • => “(/,reaction,acid,_)”
  • 📄argList=[neutralization, _, base] => argument=[neutralization, base], index=0
    • => “(/,neutralization,_,base)”
  • 📄argList=[open, $120, _] => argument=[$120, open], index=1
    • => “(/,open,$120,_)”
Source

pub fn make_image_ext_from_product( product: CompoundTermRef<'_>, relation: &Term, index: usize, ) -> Option<Term>

从一个「乘积」构造外延像

§📄OpenNARS中的例子
  • 📄product=“(*,$1,sunglasses)”, relation=“own”, index=1 => “(/,own,$1,_)”
  • 📄product=“(*,bird,plant)”, relation=“?1”, index=0 => “(/,?1,_,plant)”
  • 📄product=“(*,bird,plant)”, relation=“?1”, index=1 => “(/,?1,bird,_)”
  • 📄product=“(*,robin,worms)”, relation=“food”, index=1 => “(/,food,robin,_)”
  • 📄product=“(*,CAT,eat,fish)”, relation=“R”, index=0 => “(/,R,_,eat,fish)”
  • 📄product=“(*,CAT,eat,fish)”, relation=“R”, index=1 => “(/,R,CAT,_,fish)”
  • 📄product=“(*,CAT,eat,fish)”, relation=“R”, index=2 => “(/,R,CAT,eat,_)”
  • 📄product=“(,b,a)”, relation=“(,b,(/,like,b,))”, index=1 => “(/,like,b,)”
  • 📄product=“(,a,b)”, relation=“(,(/,like,b,),b)”, index=0 => “(/,like,b,)”
Source

pub fn make_image_ext_from_image( old_image: CompoundTermRef<'_>, component: &Term, index: usize, ) -> Option<[Term; 2]>

§📄OpenNARS中的例子
  • 📄oldImage=“(/,open,{key1},)”, component=“lock”, index=0 => “(/,open,,lock)”
  • 📄oldImage=“(/,uncle,,tom)”, component=“tim”, index=1 => “(/,uncle,tim,)”
  • 📄oldImage=“(/,open,{key1},)”, component=“$2”, index=0 => “(/,open,,$2)”
  • 📄oldImage=“(/,open,{key1},)”, component=“#1”, index=0 => “(/,open,,#1)”
  • 📄oldImage=“(/,like,,a)”, component=“b”, index=1 => “(/,like,b,)”
  • 📄oldImage=“(/,like,b,)”, component=“a”, index=0 => “(/,like,,a)”
Source

pub fn make_image_int_vec(argument: impl Into<Vec<Term>>) -> Option<Term>

Source

pub fn make_image_int_from_product( product: CompoundTermRef<'_>, relation: &Term, index: usize, ) -> Option<Term>

Source

pub fn make_image_int_from_image( old_image: CompoundTermRef<'_>, component: &Term, index: usize, ) -> Option<[Term; 2]>

§📄OpenNARS中的例子
  • 📄oldImage=(\,X,_,eat,fish), component=cat, index=2 => (\,X,cat,eat,_)
  • 📄oldImage=(\,reaction,acid,_), component=soda, index=0 => (\,reaction,_,soda)
  • 📄oldImage=(\,X,_,eat,fish), component=Y, index=2 => (\,X,Y,eat,_)
  • 📄oldImage=(\,neutralization,_,soda), component=acid, index=1 => (\,neutralization,acid,_)
  • 📄oldImage=(\,neutralization,acid,_), component=$1, index=0 => (\,neutralization,_,$1)
  • 📄oldImage=(\,REPRESENT,_,$1), component=Y, index=1 => (\,REPRESENT,Y,_)

ℹ️更多例子详见单元测试用例

Source

pub fn make_conjunction_arg(argument: Vec<Term>) -> Option<Term>

Source

pub fn make_conjunction(term1: Term, term2: Term) -> Option<Term>

Source

pub fn make_disjunction_arg(argument: Vec<Term>) -> Option<Term>

Source

pub fn make_disjunction(term1: Term, term2: Term) -> Option<Term>

Source

pub fn make_negation(t: Term) -> Option<Term>

Source

pub fn make_statement_relation( copula: impl AsRef<str>, subject: Term, predicate: Term, ) -> Option<Term>

从一个「陈述系词」中构造

Source

pub fn make_statement( template: &Term, subject: Term, predicate: Term, ) -> Option<Term>

从模板中制作「陈述」

  • 🎯推理规则
  • 🚩【2024-07-08 11:45:32】放宽对「词项类型」的限制
    • 📌实际上只需识别标识符
  • ♻️【2024-08-05 00:58:29】直接使用Self::make_statement_relation
    • 📌目前保持「依照『模板词项』的标识符制作陈述」的语义
    • ✅由此也兼容了「实例/属性/实例属性」等外部系词
Source

pub fn make_statement_symmetric( template: &Term, subject: Term, predicate: Term, ) -> Option<Term>

📄OpenNARS Statement.makeSym

  • 🚩通过使用「标识符映射」将「非对称版本」映射到「对称版本」
  • ⚠️目前只支持「继承」和「蕴含」,其它均会panic
  • 🚩【2024-07-23 15:35:41】实际上并不需要「复合词项引用」:只是对标识符做分派
§📄OpenNARS

Make a symmetric Statement from given components and temporal information, called by the rules

Source

pub fn make_inheritance(subject: Term, predicate: Term) -> Option<Term>

Source

pub fn make_instance(subject: Term, predicate: Term) -> Option<Term>

  • 🚩转发 ⇒ 继承 + 外延集
Source

pub fn make_property(subject: Term, predicate: Term) -> Option<Term>

  • 🚩转发 ⇒ 继承 + 内涵集
Source

pub fn make_instance_property(subject: Term, predicate: Term) -> Option<Term>

  • 🚩转发 ⇒ 继承 + 外延集 + 内涵集
Source

pub fn make_similarity(subject: Term, predicate: Term) -> Option<Term>

Source

pub fn make_implication(subject: Term, predicate: Term) -> Option<Term>

Source

pub fn make_equivalence(subject: Term, predicate: Term) -> Option<Term>

Source§

impl Term

内建属性

Source

pub fn identifier(&self) -> &str

只读的「标识符」属性

Source

pub fn components(&self) -> &TermComponents

只读的「组分」属性

Source

pub fn is_placeholder(&self) -> bool

判断其是否为「占位符」

  • 🎯【2024-04-21 01:04:17】在「词法折叠」中首次使用
Source

pub fn id_comp(&self) -> (&str, &TermComponents)

快捷获取「标识符-组分」二元组

  • 🎯用于很多地方的「类型匹配」
Source

pub fn unwrap_id_comp(self) -> (String, TermComponents)

解包「标识符-组分」二元组,丢弃其它字段

  • 📌【2024-09-08 16:54:28】目前没有其它字段
Source

pub fn contain_type(&self, identifier: &str) -> bool

判断「是否包含指定类型的词项」

  • 🎯支持「词项」中的方法,递归判断「是否含有变量」
Source

pub fn for_each_atom(&self, f: &mut impl FnMut(&Term))

遍历其中所有原子词项

  • 🎯找到其中所有的变量
  • ⚠️外延像/内涵像 中的占位符
  • ⚠️需要传入闭包的可变引用,而非闭包本身
    • 📌中间「递归深入」需要重复调用(传入)闭包
  • 📄词语、变量
  • 📄占位符
Source§

impl Term

Source

pub fn from_lexical(lexical: TermLexical) -> Result<Self>

尝试从「词法Narsese」转换

  • 💭【2024-04-21 14:44:15】目前此中方法「相较保守」
  • 📌与词法Narsese基本对应(ASCII)
  • ✅基本保证「解析结果均保证『合法』」
  • 🚩【2024-06-13 18:39:33】现在是「词法折叠」使用本处实现
  • ⚠️在「词法折叠」的过程中,即开始「变量匿名化」
    • 📌【2024-07-02 00:40:39】需要保证「格式化」的是个「整体」:变量只在「整体」范围内有意义
  • 🚩【2024-09-06 17:32:12】在「词法折叠」的过程中,即开始使用make系列方法
    • 🎯应对类似「(&&, A, A) => (&&, A)」的「不完整简化」现象
Source

pub fn from_dialect(input: &str) -> Result<Self>

尝试从「方言」转换

  • 🎯支持「方言解析」
  • 📌【2024-05-15 02:33:13】目前仍只有「从字符串到词项」这一种形式
  • 🆕附加功能,与核心「数据算法」「推理控制」无关
Source§

impl Term

词项⇒字符串

  • 🎯用于更好地打印「词项」名称
  • 🎯用于从「词法Narsese」中解析
    • 考虑「变量语义」
Source

pub fn format_name(&self) -> String

格式化名称

  • 🚩以方便打印的「内部方言语法」呈现Narsese
    • 📌括号全用 圆括号
    • 📌无逗号分隔符
Source

pub fn to_lexical(&self) -> TermLexical

从「内部Narsese」转换为「词法Narsese」

  • 🚩基本无损转换(无需考虑失败情况)
Source

pub fn format_ascii(&self) -> String

转换为显示呈现上的ASCII格式

  • 📌对标OpenNARS的默认呈现
  • ⚠️【2024-07-02 00:52:54】目前需要「词法Narsese」作为中间格式,可能会有性能损失
Source§

impl Term

📄OpenNARS nars.language.Term

Source

pub fn name(&self) -> String

模拟Term.getName

  • 🆕使用自身内建的「获取名称」方法
    • 相较OpenNARS更
    • 仍能满足OpenNARS的需求
  • 🎯OpenNARS原有需求
    • 📌保证「词项不同 ⇔ 名称不同」
    • 📌保证「可用于『概念』『记忆区』的索引」
§📄OpenNARS

Reporting the name of the current Term.

@return The name of the term as a String

Source

pub fn complexity(&self) -> usize

模拟Term.getComplexity

  • 🚩逻辑 from OpenNARS
    • 原子 ⇒ 1
    • 变量 ⇒ 0
    • 复合 ⇒ 1 + 所有组分复杂度之和
§📄OpenNARS
  • The syntactic complexity, for constant atomic Term, is 1.
  • The complexity of the term is the sum of those of the components plus 1
  • The syntactic complexity of a variable is 0, because it does not refer to * any concept.

@return The complexity of the term, an integer

Source

pub fn is_zero_complexity(&self) -> bool

🆕判断是否为「零复杂度」

  • 🎯用于部分「除以复杂度」的函数
Source

pub fn is_same_type(&self, other: &Self) -> bool

🆕用于替代Java的x.getClass() == y.getClass()

Source§

impl Term

Source

pub fn instanceof_compound_pure(&self) -> bool

🆕用于判断是否为「纯复合词项」

  • ⚠️包括陈述
Source

pub fn as_compound_type( &self, compound_class: impl AsRef<str>, ) -> Option<CompoundTermRef<'_>>

🆕用于判断词项是否为「指定类型的复合词项」,并尝试返回「复合词项」的引用信息

  • 📌包括陈述
  • 🚩模式匹配后返回一个Option,只在其为「符合指定类型的词项」时为Some
  • 🚩返回不可变引用
Source

pub fn unwrap_compound_id_components(self) -> Option<(String, Box<[Term]>)>

🆕用于判断词项是否为复合词项

  • 📌包括陈述
  • 🚩模式匹配后返回一个Option,只在其为「符合指定类型的词项」时为Some
  • 🚩返回标识符与内部所有元素的所有权
Source

pub fn unwrap_compound_components(self) -> Option<Box<[Term]>>

🆕用于判断词项是否为复合词项

  • 📌包括陈述
  • 🚩模式匹配后返回一个Option,只在其为「符合指定类型的词项」时为Some
  • 🚩返回内部所有元素的所有权
Source

pub fn unwrap_compound_type_components( self, compound_class: impl AsRef<str>, ) -> Option<Box<[Term]>>

🆕用于判断词项是否为「指定类型的复合词项」

  • 📌包括陈述
  • 🚩模式匹配后返回一个Option,只在其为「符合指定类型的词项」时为Some
  • 🚩返回内部所有元素的所有权
Source

pub fn instanceof_compound(&self) -> bool

🆕用于判断是否为「复合词项」

  • ⚠️包括陈述
  • 📄OpenNARS instanceof CompoundTerm 逻辑
Source

pub fn instanceof_set_ext(&self) -> bool

🆕用于判断是否为「外延集」

Source

pub fn instanceof_set_int(&self) -> bool

🆕用于判断是否为「内涵集」

Source

pub fn instanceof_set(&self) -> bool

🆕用于判断是否为「词项集」

  • 📄OpenNARSinstanceof SetExt || instanceof SetInt逻辑
Source

pub fn instanceof_intersection_ext(&self) -> bool

🆕用于判断是否为「外延交」

  • 📄OpenNARSinstanceof IntersectionExt逻辑
  • 🎯crate::inference推理规则分派
Source

pub fn instanceof_intersection_int(&self) -> bool

🆕用于判断是否为「内涵交」

  • 📄OpenNARSinstanceof IntersectionInt逻辑
  • 🎯crate::inference推理规则分派
Source

pub fn instanceof_intersection(&self) -> bool

🆕用于判断是否为「词项交集」

  • 📄OpenNARSinstanceof IntersectionExt || instanceof IntersectionInt逻辑
  • 🎯首次用于[crate::inference::StructuralRules::__switch_order]
Source

pub fn instanceof_difference_ext(&self) -> bool

🆕用于判断是否为「外延差」

  • 📄OpenNARSinstanceof DifferenceExt逻辑
  • 🎯crate::inference推理规则分派
Source

pub fn instanceof_difference_int(&self) -> bool

🆕用于判断是否为「内涵差」

  • 📄OpenNARSinstanceof DifferenceInt逻辑
  • 🎯crate::inference推理规则分派
Source

pub fn instanceof_difference(&self) -> bool

🆕用于判断是否为「词项差集」

  • 📄OpenNARSinstanceof DifferenceExt || instanceof DifferenceInt逻辑
Source

pub fn instanceof_product(&self) -> bool

🆕用于判断是否为「乘积」

Source

pub fn instanceof_image_ext(&self) -> bool

🆕用于判断是否为「外延像」

Source

pub fn instanceof_image_int(&self) -> bool

🆕用于判断是否为「内涵像」

Source

pub fn instanceof_image(&self) -> bool

🆕用于判断是否为「像」

  • 📄OpenNARSinstanceof ImageExt || instanceof ImageInt逻辑
Source

pub fn instanceof_conjunction(&self) -> bool

🆕用于判断是否为「合取」

  • 📄OpenNARSinstanceof Conjunction逻辑
  • 🎯crate::inference推理规则分派
Source

pub fn instanceof_disjunction(&self) -> bool

🆕用于判断是否为「析取」

  • 📄OpenNARSinstanceof Disjunction逻辑
  • 🎯crate::inference推理规则分派
Source

pub fn instanceof_junction(&self) -> bool

🆕用于判断是否为「词项差集」

  • 📄OpenNARSinstanceof Conjunction || instanceof Disjunction逻辑
Source

pub fn instanceof_negation(&self) -> bool

🆕用于判断是否为「否定」

Source

pub fn is_commutative(&self) -> bool

📄OpenNARS CompoundTerm.isCommutative

  • 📌对「零元/一元 词项」默认为「不可交换」
    • 📜返回false
    • 📄OpenNARS中Negation的定义(即默认「不可交换」)
§📄OpenNARS

Check if the order of the components matters

Commutative CompoundTerms: Sets, Intersections Commutative Statements: Similarity, Equivalence (except the one with a temporal order) Commutative CompoundStatements: Disjunction, Conjunction (except the one with a temporal order)

Source

pub fn structural_match(&self, other: &Self) -> bool

判断和另一词项是否「结构匹配」

  • 🎯变量替换中的模式匹配
  • 🚩类型匹配 & 组分匹配
  • ⚠️非递归:不会递归比较「组分是否对应匹配」
Source

pub fn is_compound(&self) -> bool

🆕判断是否真的是「复合词项」

  • 🚩通过判断「内部元素枚举」的类型实现
  • 🎯用于后续「作为复合词项」使用
    • ✨以此在程序层面表示「复合词项」类型
Source

pub fn as_compound(&self) -> Option<CompoundTermRef<'_>>

🆕尝试将词项作为「复合词项」

  • 📌通过判断「内部元素枚举」的类型实现
  • 🚩在其内部元素不是「复合词项」时,会返回None
Source

pub fn as_compound_and( &self, predicate: impl FnOnce(&CompoundTermRef<'_>) -> bool, ) -> Option<CompoundTermRef<'_>>

🆕尝试将词项作为「复合词项」

  • 📌通过判断「内部元素枚举」的类型实现
  • 🚩在其内部元素不是「复合词项」时,会返回None
Source

pub unsafe fn as_compound_unchecked(&self) -> CompoundTermRef<'_>

🆕尝试将词项作为「复合词项」(未检查)

  • 🚩通过判断「内部元素枚举」的类型实现
§Safety
  • ⚠️代码是不安全的:必须在解包前已经假定是「复合词项」
  • 📄逻辑参考自Option::unwrap_unchecked
Source

pub fn as_compound_mut(&mut self) -> Option<CompoundTermRefMut<'_>>

🆕尝试将词项作为「复合词项」

Source

pub unsafe fn as_compound_mut_unchecked(&mut self) -> CompoundTermRefMut<'_>

🆕尝试将词项作为「可变复合词项」(未检查)

  • 🚩通过判断「内部元素枚举」的类型实现
§Safety
  • ⚠️代码是不安全的:必须在解包前已经假定是「复合词项」
  • 📄逻辑参考自Option::unwrap_unchecked
Source§

impl Term

Source

pub fn instanceof_variable(&self) -> bool

用于判断是否为「变量词项」

Source

pub fn instanceof_variable_i(&self) -> bool

🆕用于判断「是否为独立变量」

Source

pub fn instanceof_variable_d(&self) -> bool

🆕用于判断「是否为非独变量」

Source

pub fn instanceof_variable_q(&self) -> bool

🆕用于判断「是否为查询变量」

Source

pub fn as_variable(&self) -> Option<usize>

尝试匹配出「变量」,并返回其中的编号(若有)

Source

pub fn is_constant(&self) -> bool

📄OpenNARS Term.isConstant 属性

  • 🚩检查其是否为「常量」:自身是否「不含变量」

  • 🎯决定其是否能成为一个「概念」(被作为「概念」存入记忆区)

  • ❓OpenNARS中在「构造语句」时又会将isConstant属性置为true,这是为何

    • 📝被Sentence(..)调用的CompoundTerm.renameVariables()会直接将词项「视作常量」
    • 💭这似乎是被认为「即便全是变量,只要是【被作为语句输入过】的,就会被认作是『常量』」
    • 📝然后这个「是否常量」会在「记忆区」中被认作「是否能从中获取概念」的依据:if (!term.isConstant()) { return null; }
  • 🚩【2024-04-21 23:46:12】现在变为「只读属性」:接受OpenNARS中有关「设置语句时/替换变量后 变为『常量』」的设定

    • 💫【2024-04-22 00:03:10】后续仍然有一堆复杂逻辑要考虑
  • ✅【2024-06-19 02:06:12】跟随最新改版更新,删去字段并铺开实现此功能

  • ♻️【2024-06-26 02:07:27】重构修正:禁止「占位符」作为「常量词项」

  • ♻️【2024-07-31 21:41:49】修正:不再将查询变量计入「常量词项」

§📄OpenNARS

Check whether the current Term can name a Concept.

  • A Term is constant by default
  • A variable is not constant
  • (for CompoundTerm) check if the term contains free variable
Source

pub fn contain_var(&self) -> bool

📄OpenNARS Variable.containVar 方法

  • 🚩检查其是否「包含变量」
    • 自身为「变量词项」或者其包含「变量词项」
  • 🎯用于决定复合词项是否为「常量」
  • 📝OpenNARS中对于复合词项的isConstant属性采用「惰性获取」的机制
    • isConstant作为!Variable.containVar(name)进行初始化
  • 🆕实现方法:不同于OpenNARS「直接从字符串中搜索子串」的方式,基于递归方法设计
§📄OpenNARS

Check whether a string represent a name of a term that contains a variable

Source

pub fn contain_var_i(&self) -> bool

📄OpenNARS Variable.containVarI 方法

  • 🎯判断「是否包含指定类型的变量」
  • 🚩通过「判断是否包含指定标识符的词项」完成判断
Source

pub fn contain_var_d(&self) -> bool

📄OpenNARS Variable.containVarD 方法

  • 🎯判断「是否包含指定类型的变量」
  • 🚩通过「判断是否包含指定标识符的词项」完成判断
Source

pub fn contain_var_q(&self) -> bool

📄OpenNARS Variable.containVarQ 方法

  • 🎯判断「是否包含指定类型的变量」
  • 🚩通过「判断是否包含指定标识符的词项」完成判断
Source

pub fn get_variable_type(&self) -> &str

📄OpenNARS Variable.getType 方法

  • 🎯在OpenNARS中仅用于「判断变量类型相等」
  • 🚩归并到「判断词项标识符相等」
§📄OpenNARS

Get the type of the variable

Source

pub fn maximum_variable_id_multi<'s>( terms: impl IntoIterator<Item = &'s Term>, ) -> usize

🆕获取多个词项中编号最大的变量词项id

Source§

impl Term

Source

pub fn instanceof_statement(&self) -> bool

🆕用于判断是否为「陈述词项」

  • 📄OpenNARS instanceof Statement 逻辑
Source

pub fn is_statement_identifier(identifier: &str) -> bool

🆕抽象出来的「标识符(对应的词项类型)是否『可交换』」

  • 🎯同时用于「词项属性」与「词项转换」
    • 📄参见[super::_dialect]中的reform_term函数
Source

pub fn instanceof_inheritance(&self) -> bool

🆕用于判断是否为「继承」

  • 📄OpenNARSinstanceof Inheritance逻辑
  • 📝OpenNARS中「继承」与「实例」「属性」「实例属性」没有继承关系
  • 🎯[crate::inference::RuleTables]推理规则分派
Source

pub fn instanceof_similarity(&self) -> bool

🆕用于判断是否为「相似」

  • 📄OpenNARSinstanceof Similarity逻辑
  • 🎯[crate::inference::RuleTables]推理规则分派
Source

pub fn instanceof_implication(&self) -> bool

🆕用于判断是否为「蕴含」

  • 📄OpenNARSinstanceof Implication逻辑
  • 🎯[crate::inference::RuleTables]推理规则分派
Source

pub fn instanceof_equivalence(&self) -> bool

🆕用于判断是否为「等价」

  • 📄OpenNARSinstanceof Equivalence逻辑
  • 🎯[crate::inference::RuleTables]推理规则分派
Source

pub fn is_statement(&self) -> bool

🆕判断一个词项是否为「陈述词项」

  • 🚩判断其「内部元素」的个数是否为2,并且要判断其标识符
  • 🚩【2024-09-07 14:59:00】现在采用更严格的条件——需要判断是否为「陈述系词」
Source

pub fn as_statement(&self) -> Option<StatementRef<'_>>

🆕将一个复合词项转换为「陈述词项」(不可变引用)

  • 🚩转换为Option
  • 🚩【2024-09-07 14:59:00】现在采用更严格的条件——需要判断是否为「陈述系词」
Source

pub fn as_statement_type( &self, statement_class: impl AsRef<str>, ) -> Option<StatementRef<'_>>

🆕用于判断词项是否为「指定类型的复合词项」,并尝试返回「复合词项」的引用信息

  • 📌包括陈述
  • 🚩模式匹配后返回一个Option,只在其为「符合指定类型的词项」时为Some
  • 🚩返回不可变引用
Source

pub fn as_statement_mut(&mut self) -> Option<StatementRefMut<'_>>

🆕将一个复合词项转换为「陈述词项」(可变引用)

  • 🚩转换为Option
Source

pub fn unwrap_statement_components(self) -> Option<[Term; 2]>

🆕用于判断词项是否为「陈述」并解包其中的主项和谓项

  • 🚩模式匹配后返回一个Option,只在其为「符合指定类型的词项」时为Some
  • 🚩返回内部所有元素的所有权
Source

pub fn unwrap_statement_id_components(self) -> Option<(Term, String, Term)>

🆕用于判断词项是否为「陈述」并解包其中的主项、系词和谓项

  • 🚩模式匹配后返回一个Option,只在其为「符合指定类型的词项」时为Some
  • 🚩返回标识符与内部所有元素的所有权
Source

pub fn unwrap_statement_type_components( self, statement_class: impl AsRef<str>, ) -> Option<[Term; 2]>

🆕用于判断词项是否为「指定类型的陈述」,并解包其中的主项和谓项

  • 🚩模式匹配后返回一个Option,只在其为「符合指定类型的词项」时为Some
  • 🚩返回内部所有元素的所有权

Trait Implementations§

Source§

impl Clone for Term

Source§

fn clone(&self) -> Term

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Term

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Term

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Term

实现[Display]

  • 🎯调试时便于展现内部结构
  • ⚡性能友好
  • ⚠️并非CommonNarsese语法
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&Term> for Term

词项⇒词法Narsese

Source§

fn from(term: &Term) -> Self

Converts to this type from the input type.
Source§

impl From<CompoundTerm> for Term

出口(转换成词项)

Source§

fn from(value: CompoundTerm) -> Self

Converts to this type from the input type.
Source§

impl From<Statement> for Term

出口(转换成词项)

Source§

fn from(value: Statement) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Term

字符串解析

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl GetCapacity for Term

从NAL语义上判断词项的「容量」

Source§

fn get_capacity(&self) -> TermCapacity

获取词项的「容量」属性
Source§

fn is_capacity_atom(&self) -> bool

在容量上是否为「原子」
Source§

fn is_capacity_unary(&self) -> bool

在容量上是否为「一元复合」
Source§

fn is_capacity_binary(&self) -> bool

在容量上是否为「二元」
Source§

fn is_capacity_binary_vec(&self) -> bool

在容量上是否为「二元序列」
Source§

fn is_capacity_binary_set(&self) -> bool

在容量上是否为「二元集合」
Source§

fn is_capacity_multi(&self) -> bool

在容量上是否为「多元」
Source§

fn is_capacity_vec(&self) -> bool

在容量上是否为「(多元)序列」
Source§

fn is_capacity_set(&self) -> bool

在容量上是否为「(多元)集合」
Source§

impl GetCategory for Term

Source§

fn get_category(&self) -> TermCategory

获取词项的「类别」属性
Source§

fn is_atom(&self) -> bool

(在类别上)是否为「原子」
Source§

fn is_compound(&self) -> bool

(在类别上)是否为「复合词项」
Source§

fn is_statement(&self) -> bool

(在类别上)是否为「陈述」
Source§

impl Hash for Term

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl MaximumVariableId for &Term

词项引用

Source§

impl MaximumVariableId for Term

词项本身

Source§

fn maximum_variable_id(&self) -> usize

🆕获取一个词项中编号最大的变量词项id

Source§

impl Ord for Term

Source§

fn cmp(&self, other: &Term) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Term

Source§

fn eq(&self, other: &Term) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Term

Source§

fn partial_cmp(&self, other: &Term) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Term

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

fn target<'r, 's: 'r>(&'s self) -> impl Deref<Target = Term> + 'r

链接所指目标 Read more
Source§

fn target_mut<'r, 's: 'r>(&'s mut self) -> impl DerefMut<Target = Term> + 'r

目标的可变引用 Read more
链接类型 Read more
Source§

fn indexes(&self) -> &[usize]

获取链接的「索引」,指向具体词项的位置 Read more
Source§

fn generate_key_base(link_type: TLinkType, indexes: &[usize]) -> String

Set the key of the link Read more
Source§

fn get_index(&self, index: usize) -> Option<&usize>

Get one index by level
Source§

fn index(&self, index: usize) -> usize

快速假定性获取索引 Read more
Source§

impl TryFoldInto<'_, Term, Error> for Term

词法折叠

Source§

type Folder = ()

类型占位符

Source§

fn try_fold_into(self, _: &Self::Folder) -> Result<Term>

尝试朝需要的类型进行「词法折叠」 Read more
Source§

impl TryFrom<&str> for Term

字符串解析路线:词法解析 ⇒ 词法折叠

  • 🎯同时兼容str::parse与[str::try_into]
  • 📌使用标准OpenNARS ASCII语法
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(s: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Term> for CompoundTerm

仅有的一处入口:从词项构造

Source§

type Error = Term

转换失败时,返回原始词项

Source§

fn try_from(term: Term) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Term> for Statement

仅有的一处入口:从词项构造

Source§

type Error = Term

转换失败时,返回原始词项

Source§

fn try_from(term: Term) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Term> for Term

基于「词法折叠」实现TryFrom

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: TermLexical) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Term

Source§

impl StructuralPartialEq for Term

Auto Trait Implementations§

§

impl Freeze for Term

§

impl RefUnwindSafe for Term

§

impl Send for Term

§

impl Sync for Term

§

impl Unpin for Term

§

impl UnwindSafe for Term

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> BoostWithOption for T

Source§

fn option<C>(self, criterion: C) -> Option<Self>
where C: FnOnce(&Self) -> bool,

根据某条件把自身变为可选值 Read more
Source§

fn some(self) -> Option<Self>

将自身封装为Some Read more
Source§

fn none(self) -> Option<Self>

将自身封装为None Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> JoinTo for T

Source§

fn join_to<S>(self, out: &mut String, sep: impl AsRef<str>)
where Self: Sized + Iterator<Item = S>, S: AsRef<str>,

将字串集中拼接到一个「目标字串」中,中途不创建任何辅助字符串 Read more
Source§

fn join_to_new<S>(self, sep: impl AsRef<str>) -> String
where Self: Sized + Iterator<Item = S>, S: AsRef<str>,

将字串集中拼接到一个新字串中 Read more
Source§

fn join_to_multi<S>(self, out: &mut String, sep: &[impl AsRef<str>])
where Self: Sized + Iterator<Item = S>, S: AsRef<str>,

将字串集中拼接到一个「目标字串」中,使用多个分隔符,中途不创建任何辅助字符串 Read more
Source§

fn join_to_multi_new<S>(self, sep: &[impl AsRef<str>]) -> String
where Self: Sized + Iterator<Item = S>, S: AsRef<str>,

将字串集中拼接到一个新字串中,使用多个分隔符 Read more
Source§

impl<T> JoinTo for T

Source§

fn join_to<S>(self, out: &mut String, sep: impl AsRef<str>)
where Self: Sized + Iterator<Item = S>, S: AsRef<str>,

将字串集中拼接到一个「目标字串」中,中途不创建任何辅助字符串 Read more
Source§

fn join_to_new<S>(self, sep: impl AsRef<str>) -> String
where Self: Sized + Iterator<Item = S>, S: AsRef<str>,

将字串集中拼接到一个新字串中 Read more
Source§

fn join_to_multi<S>(self, out: &mut String, sep: &[impl AsRef<str>])
where Self: Sized + Iterator<Item = S>, S: AsRef<str>,

将字串集中拼接到一个「目标字串」中,使用多个分隔符,中途不创建任何辅助字符串 Read more
Source§

fn join_to_multi_new<S>(self, sep: &[impl AsRef<str>]) -> String
where Self: Sized + Iterator<Item = S>, S: AsRef<str>,

将字串集中拼接到一个新字串中,使用多个分隔符 Read more
Source§

impl<T> ToDebug for T
where T: Debug,

Source§

fn to_debug(&self) -> String

将对象转换为「用Debug格式化的字符串」

Source§

impl<T> ToDebug for T
where T: Debug,

Source§

fn to_debug(&self) -> String

将对象转换为「用Debug格式化的字符串」

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Void for T

Source§

fn void(self)

Source§

impl<T> Void for T

Source§

fn void(self)

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,