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」虽然造成逻辑不同,但可以满足需求 - 📌核心逻辑:实现需求就行,没必要(也很难)全盘照搬
- 🚩然而此实现的需求用「派生
-
📝OpenNARS在「记忆区构造词项」时,就会进行各种预处理
- 📄
<(-, {A, B}, {A}) --> x>会产生<{B} --> x>(外延「差」规则)
- 📄
-
📝OpenNARS中的词项基本只能通过
make系列方法(从外部)构造- 💭这似乎意味着它是一种「记忆区专用」的封闭数据类型
-
📌【2024-06-16 11:42:25】目前应手动实现
Ord
§📄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
impl Term
Sourcepub fn make_placeholder() -> Term
pub fn make_placeholder() -> Term
制作「占位符」
Sourcepub fn make_var_i(to_max: impl MaximumVariableId) -> Term
pub fn make_var_i(to_max: impl MaximumVariableId) -> Term
制作「独立变量」
Sourcepub fn make_var_d(to_max: impl MaximumVariableId) -> Term
pub fn make_var_d(to_max: impl MaximumVariableId) -> Term
制作「非独变量」
Sourcepub fn make_var_q(to_max: impl MaximumVariableId) -> Term
pub fn make_var_q(to_max: impl MaximumVariableId) -> Term
制作「查询变量」
Sourcepub fn make_var_similar(from: &Term, id: impl Into<usize>) -> Term
pub fn make_var_similar(from: &Term, id: impl Into<usize>) -> Term
制作「与现有变量类型相同」的变量
- 🚩类型相同但编号不同
- 🎯用于「变量推理」中的「重命名变量」
Sourcepub fn make_compound_term(
template: CompoundTermRef<'_>,
components: Vec<Term>,
) -> Option<Term>
pub fn make_compound_term( template: CompoundTermRef<'_>, components: Vec<Term>, ) -> Option<Term>
📄OpenNARS public static Term makeCompoundTerm(CompoundTerm compound, ArrayList<Term> components)
pub fn make_compound_term_or_statement( template: CompoundTermRef<'_>, components: Vec<Term>, ) -> Option<Term>
Sourcepub fn make_compound_term_from_identifier(
identifier: impl AsRef<str>,
argument: Vec<Term>,
) -> Option<Term>
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)
Sourcepub fn make_set_ext(t: Term) -> Option<Term>
pub fn make_set_ext(t: Term) -> Option<Term>
制作一个外延集
Sourcepub fn make_set_int(t: Term) -> Option<Term>
pub fn make_set_int(t: Term) -> Option<Term>
制作一个内涵集
pub fn make_intersection_ext(term1: Term, term2: Term) -> Option<Term>
Sourcepub fn make_intersection_ext_arg(argument: Vec<Term>) -> Option<Term>
pub fn make_intersection_ext_arg(argument: Vec<Term>) -> Option<Term>
- 📝同时包括「用户输入」与「从参数构造」两种来源
- 📄来源1:结构规则「structuralCompose2」
- 🆕现在构造时也会用reduce逻辑尝试合并
pub fn make_intersection_int(term1: Term, term2: Term) -> Option<Term>
Sourcepub fn make_intersection_int_arg(argument: Vec<Term>) -> Option<Term>
pub fn make_intersection_int_arg(argument: Vec<Term>) -> Option<Term>
- 📝同时包括「用户输入」与「从参数构造」两种来源
- 📄来源1:结构规则「structuralCompose2」
- 🆕现在构造时也会用reduce逻辑尝试合并
pub fn make_difference_ext(left: Term, right: Term) -> Option<Term>
pub fn make_difference_int(left: Term, right: Term) -> Option<Term>
pub fn make_product_arg(argument: Vec<Term>) -> Option<Term>
Sourcepub fn make_product(
image: CompoundTermRef<'_>,
component: &Term,
) -> Option<[Term; 2]>
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「占位符不作词项」逻辑的不同
Sourcepub fn make_image_ext_vec(argument: impl Into<Vec<Term>>) -> Option<Term>
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,_)”
Sourcepub fn make_image_ext_from_product(
product: CompoundTermRef<'_>,
relation: &Term,
index: usize,
) -> Option<Term>
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,)”
Sourcepub fn make_image_ext_from_image(
old_image: CompoundTermRef<'_>,
component: &Term,
index: usize,
) -> Option<[Term; 2]>
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)”
pub fn make_image_int_vec(argument: impl Into<Vec<Term>>) -> Option<Term>
pub fn make_image_int_from_product( product: CompoundTermRef<'_>, relation: &Term, index: usize, ) -> Option<Term>
Sourcepub fn make_image_int_from_image(
old_image: CompoundTermRef<'_>,
component: &Term,
index: usize,
) -> Option<[Term; 2]>
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,_)
ℹ️更多例子详见单元测试用例
pub fn make_conjunction_arg(argument: Vec<Term>) -> Option<Term>
pub fn make_conjunction(term1: Term, term2: Term) -> Option<Term>
pub fn make_disjunction_arg(argument: Vec<Term>) -> Option<Term>
pub fn make_disjunction(term1: Term, term2: Term) -> Option<Term>
pub fn make_negation(t: Term) -> Option<Term>
Sourcepub fn make_statement_relation(
copula: impl AsRef<str>,
subject: Term,
predicate: Term,
) -> Option<Term>
pub fn make_statement_relation( copula: impl AsRef<str>, subject: Term, predicate: Term, ) -> Option<Term>
从一个「陈述系词」中构造
Sourcepub fn make_statement(
template: &Term,
subject: Term,
predicate: Term,
) -> Option<Term>
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- 📌目前保持「依照『模板词项』的标识符制作陈述」的语义
- ✅由此也兼容了「实例/属性/实例属性」等外部系词
Sourcepub fn make_statement_symmetric(
template: &Term,
subject: Term,
predicate: Term,
) -> Option<Term>
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
pub fn make_inheritance(subject: Term, predicate: Term) -> Option<Term>
Sourcepub fn make_instance_property(subject: Term, predicate: Term) -> Option<Term>
pub fn make_instance_property(subject: Term, predicate: Term) -> Option<Term>
- 🚩转发 ⇒ 继承 + 外延集 + 内涵集
pub fn make_similarity(subject: Term, predicate: Term) -> Option<Term>
pub fn make_implication(subject: Term, predicate: Term) -> Option<Term>
pub fn make_equivalence(subject: Term, predicate: Term) -> Option<Term>
Source§impl Term
内建属性
impl Term
内建属性
Sourcepub fn identifier(&self) -> &str
pub fn identifier(&self) -> &str
只读的「标识符」属性
Sourcepub fn components(&self) -> &TermComponents
pub fn components(&self) -> &TermComponents
只读的「组分」属性
Sourcepub fn is_placeholder(&self) -> bool
pub fn is_placeholder(&self) -> bool
判断其是否为「占位符」
- 🎯【2024-04-21 01:04:17】在「词法折叠」中首次使用
Sourcepub fn id_comp(&self) -> (&str, &TermComponents)
pub fn id_comp(&self) -> (&str, &TermComponents)
快捷获取「标识符-组分」二元组
- 🎯用于很多地方的「类型匹配」
Sourcepub fn unwrap_id_comp(self) -> (String, TermComponents)
pub fn unwrap_id_comp(self) -> (String, TermComponents)
解包「标识符-组分」二元组,丢弃其它字段
- 📌【2024-09-08 16:54:28】目前没有其它字段
Sourcepub fn contain_type(&self, identifier: &str) -> bool
pub fn contain_type(&self, identifier: &str) -> bool
判断「是否包含指定类型的词项」
- 🎯支持「词项」中的方法,递归判断「是否含有变量」
Sourcepub fn for_each_atom(&self, f: &mut impl FnMut(&Term))
pub fn for_each_atom(&self, f: &mut impl FnMut(&Term))
遍历其中所有原子词项
- 🎯找到其中所有的变量
- ⚠️外延像/内涵像 中的占位符
- ⚠️需要传入闭包的可变引用,而非闭包本身
- 📌中间「递归深入」需要重复调用(传入)闭包
- 📄词语、变量
- 📄占位符
Source§impl Term
impl Term
Sourcepub fn from_lexical(lexical: TermLexical) -> Result<Self>
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)」的「不完整简化」现象
- 🎯应对类似「
Sourcepub fn from_dialect(input: &str) -> Result<Self>
pub fn from_dialect(input: &str) -> Result<Self>
尝试从「方言」转换
- 🎯支持「方言解析」
- 📌【2024-05-15 02:33:13】目前仍只有「从字符串到词项」这一种形式
- 🆕附加功能,与核心「数据算法」「推理控制」无关
Source§impl Term
词项⇒字符串
impl Term
词项⇒字符串
- 🎯用于更好地打印「词项」名称
- 🎯用于从「词法Narsese」中解析
- 考虑「变量语义」
Sourcepub fn format_name(&self) -> String
pub fn format_name(&self) -> String
格式化名称
- 🚩以方便打印的「内部方言语法」呈现Narsese
- 📌括号全用 圆括号
- 📌无逗号分隔符
Sourcepub fn to_lexical(&self) -> TermLexical
pub fn to_lexical(&self) -> TermLexical
从「内部Narsese」转换为「词法Narsese」
- 🚩基本无损转换(无需考虑失败情况)
Sourcepub fn format_ascii(&self) -> String
pub fn format_ascii(&self) -> String
转换为显示呈现上的ASCII格式
- 📌对标OpenNARS的默认呈现
- ⚠️【2024-07-02 00:52:54】目前需要「词法Narsese」作为中间格式,可能会有性能损失
Source§impl Term
📄OpenNARS nars.language.Term
impl Term
📄OpenNARS nars.language.Term
Sourcepub fn name(&self) -> String
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
Sourcepub fn complexity(&self) -> usize
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
Sourcepub fn is_zero_complexity(&self) -> bool
pub fn is_zero_complexity(&self) -> bool
🆕判断是否为「零复杂度」
- 🎯用于部分「除以复杂度」的函数
Sourcepub fn is_same_type(&self, other: &Self) -> bool
pub fn is_same_type(&self, other: &Self) -> bool
🆕用于替代Java的x.getClass() == y.getClass()
Source§impl Term
impl Term
Sourcepub fn instanceof_compound_pure(&self) -> bool
pub fn instanceof_compound_pure(&self) -> bool
🆕用于判断是否为「纯复合词项」
- ⚠️不包括陈述
Sourcepub fn as_compound_type(
&self,
compound_class: impl AsRef<str>,
) -> Option<CompoundTermRef<'_>>
pub fn as_compound_type( &self, compound_class: impl AsRef<str>, ) -> Option<CompoundTermRef<'_>>
Sourcepub fn unwrap_compound_components(self) -> Option<Box<[Term]>>
pub fn unwrap_compound_components(self) -> Option<Box<[Term]>>
Sourcepub fn unwrap_compound_type_components(
self,
compound_class: impl AsRef<str>,
) -> Option<Box<[Term]>>
pub fn unwrap_compound_type_components( self, compound_class: impl AsRef<str>, ) -> Option<Box<[Term]>>
Sourcepub fn instanceof_compound(&self) -> bool
pub fn instanceof_compound(&self) -> bool
🆕用于判断是否为「复合词项」
- ⚠️包括陈述
- 📄OpenNARS
instanceof CompoundTerm逻辑
Sourcepub fn instanceof_set_ext(&self) -> bool
pub fn instanceof_set_ext(&self) -> bool
🆕用于判断是否为「外延集」
- 📄OpenNARS
instanceof SetExt逻辑 - 🎯
crate::inference推理规则分派
Sourcepub fn instanceof_set_int(&self) -> bool
pub fn instanceof_set_int(&self) -> bool
🆕用于判断是否为「内涵集」
- 📄OpenNARS
instanceof SetInt逻辑 - 🎯
crate::inference推理规则分派
Sourcepub fn instanceof_set(&self) -> bool
pub fn instanceof_set(&self) -> bool
🆕用于判断是否为「词项集」
- 📄OpenNARS
instanceof SetExt || instanceof SetInt逻辑
Sourcepub fn instanceof_intersection_ext(&self) -> bool
pub fn instanceof_intersection_ext(&self) -> bool
🆕用于判断是否为「外延交」
- 📄OpenNARS
instanceof IntersectionExt逻辑 - 🎯
crate::inference推理规则分派
Sourcepub fn instanceof_intersection_int(&self) -> bool
pub fn instanceof_intersection_int(&self) -> bool
🆕用于判断是否为「内涵交」
- 📄OpenNARS
instanceof IntersectionInt逻辑 - 🎯
crate::inference推理规则分派
Sourcepub fn instanceof_intersection(&self) -> bool
pub fn instanceof_intersection(&self) -> bool
🆕用于判断是否为「词项交集」
- 📄OpenNARS
instanceof IntersectionExt || instanceof IntersectionInt逻辑 - 🎯首次用于[
crate::inference::StructuralRules::__switch_order]
Sourcepub fn instanceof_difference_ext(&self) -> bool
pub fn instanceof_difference_ext(&self) -> bool
🆕用于判断是否为「外延差」
- 📄OpenNARS
instanceof DifferenceExt逻辑 - 🎯
crate::inference推理规则分派
Sourcepub fn instanceof_difference_int(&self) -> bool
pub fn instanceof_difference_int(&self) -> bool
🆕用于判断是否为「内涵差」
- 📄OpenNARS
instanceof DifferenceInt逻辑 - 🎯
crate::inference推理规则分派
Sourcepub fn instanceof_difference(&self) -> bool
pub fn instanceof_difference(&self) -> bool
🆕用于判断是否为「词项差集」
- 📄OpenNARS
instanceof DifferenceExt || instanceof DifferenceInt逻辑
Sourcepub fn instanceof_product(&self) -> bool
pub fn instanceof_product(&self) -> bool
🆕用于判断是否为「乘积」
- 📄OpenNARS
instanceof Product逻辑 - 🎯
crate::inference推理规则分派
Sourcepub fn instanceof_image_ext(&self) -> bool
pub fn instanceof_image_ext(&self) -> bool
🆕用于判断是否为「外延像」
- 📄OpenNARS
instanceof ImageExt逻辑 - 🎯
crate::inference推理规则分派
Sourcepub fn instanceof_image_int(&self) -> bool
pub fn instanceof_image_int(&self) -> bool
🆕用于判断是否为「内涵像」
- 📄OpenNARS
instanceof ImageInt逻辑 - 🎯
crate::inference推理规则分派
Sourcepub fn instanceof_image(&self) -> bool
pub fn instanceof_image(&self) -> bool
🆕用于判断是否为「像」
- 📄OpenNARS
instanceof ImageExt || instanceof ImageInt逻辑
Sourcepub fn instanceof_conjunction(&self) -> bool
pub fn instanceof_conjunction(&self) -> bool
🆕用于判断是否为「合取」
- 📄OpenNARS
instanceof Conjunction逻辑 - 🎯
crate::inference推理规则分派
Sourcepub fn instanceof_disjunction(&self) -> bool
pub fn instanceof_disjunction(&self) -> bool
🆕用于判断是否为「析取」
- 📄OpenNARS
instanceof Disjunction逻辑 - 🎯
crate::inference推理规则分派
Sourcepub fn instanceof_junction(&self) -> bool
pub fn instanceof_junction(&self) -> bool
🆕用于判断是否为「词项差集」
- 📄OpenNARS
instanceof Conjunction || instanceof Disjunction逻辑
Sourcepub fn instanceof_negation(&self) -> bool
pub fn instanceof_negation(&self) -> bool
🆕用于判断是否为「否定」
- 📄OpenNARS
instanceof Negation逻辑 - 🎯
crate::inference推理规则分派
Sourcepub fn is_commutative(&self) -> bool
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)
Sourcepub fn structural_match(&self, other: &Self) -> bool
pub fn structural_match(&self, other: &Self) -> bool
判断和另一词项是否「结构匹配」
- 🎯变量替换中的模式匹配
- 🚩类型匹配 & 组分匹配
- ⚠️非递归:不会递归比较「组分是否对应匹配」
Sourcepub fn is_compound(&self) -> bool
pub fn is_compound(&self) -> bool
🆕判断是否真的是「复合词项」
- 🚩通过判断「内部元素枚举」的类型实现
- 🎯用于后续「作为复合词项」使用
- ✨以此在程序层面表示「复合词项」类型
Sourcepub fn as_compound(&self) -> Option<CompoundTermRef<'_>>
pub fn as_compound(&self) -> Option<CompoundTermRef<'_>>
🆕尝试将词项作为「复合词项」
- 📌通过判断「内部元素枚举」的类型实现
- 🚩在其内部元素不是「复合词项」时,会返回
None
Sourcepub fn as_compound_and(
&self,
predicate: impl FnOnce(&CompoundTermRef<'_>) -> bool,
) -> Option<CompoundTermRef<'_>>
pub fn as_compound_and( &self, predicate: impl FnOnce(&CompoundTermRef<'_>) -> bool, ) -> Option<CompoundTermRef<'_>>
🆕尝试将词项作为「复合词项」
- 📌通过判断「内部元素枚举」的类型实现
- 🚩在其内部元素不是「复合词项」时,会返回
None
Sourcepub unsafe fn as_compound_unchecked(&self) -> CompoundTermRef<'_>
pub unsafe fn as_compound_unchecked(&self) -> CompoundTermRef<'_>
🆕尝试将词项作为「复合词项」(未检查)
- 🚩通过判断「内部元素枚举」的类型实现
§Safety
- ⚠️代码是不安全的:必须在解包前已经假定是「复合词项」
- 📄逻辑参考自
Option::unwrap_unchecked
Sourcepub fn as_compound_mut(&mut self) -> Option<CompoundTermRefMut<'_>>
pub fn as_compound_mut(&mut self) -> Option<CompoundTermRefMut<'_>>
🆕尝试将词项作为「复合词项」
- ℹ️
Self::as_compound的可变版本
Sourcepub unsafe fn as_compound_mut_unchecked(&mut self) -> CompoundTermRefMut<'_>
pub unsafe fn as_compound_mut_unchecked(&mut self) -> CompoundTermRefMut<'_>
🆕尝试将词项作为「可变复合词项」(未检查)
- 🚩通过判断「内部元素枚举」的类型实现
§Safety
- ⚠️代码是不安全的:必须在解包前已经假定是「复合词项」
- 📄逻辑参考自
Option::unwrap_unchecked
Source§impl Term
impl Term
Sourcepub fn instanceof_variable(&self) -> bool
pub fn instanceof_variable(&self) -> bool
用于判断是否为「变量词项」
- 📄OpenNARS
instanceof Variable逻辑 - 🎯判断「是否内含变量」
Sourcepub fn instanceof_variable_i(&self) -> bool
pub fn instanceof_variable_i(&self) -> bool
🆕用于判断「是否为独立变量」
Sourcepub fn instanceof_variable_d(&self) -> bool
pub fn instanceof_variable_d(&self) -> bool
🆕用于判断「是否为非独变量」
Sourcepub fn instanceof_variable_q(&self) -> bool
pub fn instanceof_variable_q(&self) -> bool
🆕用于判断「是否为查询变量」
Sourcepub fn as_variable(&self) -> Option<usize>
pub fn as_variable(&self) -> Option<usize>
尝试匹配出「变量」,并返回其中的编号(若有)
Sourcepub fn is_constant(&self) -> bool
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
Sourcepub fn contain_var(&self) -> bool
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
Sourcepub fn contain_var_i(&self) -> bool
pub fn contain_var_i(&self) -> bool
📄OpenNARS Variable.containVarI 方法
- 🎯判断「是否包含指定类型的变量」
- 🚩通过「判断是否包含指定标识符的词项」完成判断
Sourcepub fn contain_var_d(&self) -> bool
pub fn contain_var_d(&self) -> bool
📄OpenNARS Variable.containVarD 方法
- 🎯判断「是否包含指定类型的变量」
- 🚩通过「判断是否包含指定标识符的词项」完成判断
Sourcepub fn contain_var_q(&self) -> bool
pub fn contain_var_q(&self) -> bool
📄OpenNARS Variable.containVarQ 方法
- 🎯判断「是否包含指定类型的变量」
- 🚩通过「判断是否包含指定标识符的词项」完成判断
Sourcepub fn get_variable_type(&self) -> &str
pub fn get_variable_type(&self) -> &str
📄OpenNARS Variable.getType 方法
- 🎯在OpenNARS中仅用于「判断变量类型相等」
- 🚩归并到「判断词项标识符相等」
§📄OpenNARS
Get the type of the variable
Sourcepub fn maximum_variable_id_multi<'s>(
terms: impl IntoIterator<Item = &'s Term>,
) -> usize
pub fn maximum_variable_id_multi<'s>( terms: impl IntoIterator<Item = &'s Term>, ) -> usize
🆕获取多个词项中编号最大的变量词项id
Source§impl Term
impl Term
Sourcepub fn instanceof_statement(&self) -> bool
pub fn instanceof_statement(&self) -> bool
🆕用于判断是否为「陈述词项」
- 📄OpenNARS
instanceof Statement逻辑
Sourcepub fn is_statement_identifier(identifier: &str) -> bool
pub fn is_statement_identifier(identifier: &str) -> bool
🆕抽象出来的「标识符(对应的词项类型)是否『可交换』」
- 🎯同时用于「词项属性」与「词项转换」
- 📄参见[
super::_dialect]中的reform_term函数
- 📄参见[
Sourcepub fn instanceof_inheritance(&self) -> bool
pub fn instanceof_inheritance(&self) -> bool
🆕用于判断是否为「继承」
- 📄OpenNARS
instanceof Inheritance逻辑 - 📝OpenNARS中「继承」与「实例」「属性」「实例属性」没有继承关系
- 🎯[
crate::inference::RuleTables]推理规则分派
Sourcepub fn instanceof_similarity(&self) -> bool
pub fn instanceof_similarity(&self) -> bool
🆕用于判断是否为「相似」
- 📄OpenNARS
instanceof Similarity逻辑 - 🎯[
crate::inference::RuleTables]推理规则分派
Sourcepub fn instanceof_implication(&self) -> bool
pub fn instanceof_implication(&self) -> bool
🆕用于判断是否为「蕴含」
- 📄OpenNARS
instanceof Implication逻辑 - 🎯[
crate::inference::RuleTables]推理规则分派
Sourcepub fn instanceof_equivalence(&self) -> bool
pub fn instanceof_equivalence(&self) -> bool
🆕用于判断是否为「等价」
- 📄OpenNARS
instanceof Equivalence逻辑 - 🎯[
crate::inference::RuleTables]推理规则分派
Sourcepub fn is_statement(&self) -> bool
pub fn is_statement(&self) -> bool
🆕判断一个词项是否为「陈述词项」
- 🚩判断其「内部元素」的个数是否为2,并且要判断其标识符
- 🚩【2024-09-07 14:59:00】现在采用更严格的条件——需要判断是否为「陈述系词」
Sourcepub fn as_statement(&self) -> Option<StatementRef<'_>>
pub fn as_statement(&self) -> Option<StatementRef<'_>>
🆕将一个复合词项转换为「陈述词项」(不可变引用)
- 🚩转换为Option
- 🚩【2024-09-07 14:59:00】现在采用更严格的条件——需要判断是否为「陈述系词」
Sourcepub fn as_statement_type(
&self,
statement_class: impl AsRef<str>,
) -> Option<StatementRef<'_>>
pub fn as_statement_type( &self, statement_class: impl AsRef<str>, ) -> Option<StatementRef<'_>>
Sourcepub fn as_statement_mut(&mut self) -> Option<StatementRefMut<'_>>
pub fn as_statement_mut(&mut self) -> Option<StatementRefMut<'_>>
🆕将一个复合词项转换为「陈述词项」(可变引用)
- 🚩转换为Option
Sourcepub fn unwrap_statement_components(self) -> Option<[Term; 2]>
pub fn unwrap_statement_components(self) -> Option<[Term; 2]>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Term
impl<'de> Deserialize<'de> for Term
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl From<CompoundTerm> for Term
出口(转换成词项)
impl From<CompoundTerm> for Term
出口(转换成词项)
Source§fn from(value: CompoundTerm) -> Self
fn from(value: CompoundTerm) -> Self
Source§impl FromStr for Term
字符串解析
impl FromStr for Term
字符串解析
- 🎯同时兼容
str::parse与[str::try_into]
Source§impl GetCapacity for Term
从NAL语义上判断词项的「容量」
impl GetCapacity for Term
从NAL语义上判断词项的「容量」
Source§fn get_capacity(&self) -> TermCapacity
fn get_capacity(&self) -> TermCapacity
Source§fn is_capacity_atom(&self) -> bool
fn is_capacity_atom(&self) -> bool
Source§fn is_capacity_unary(&self) -> bool
fn is_capacity_unary(&self) -> bool
Source§fn is_capacity_binary(&self) -> bool
fn is_capacity_binary(&self) -> bool
Source§fn is_capacity_binary_vec(&self) -> bool
fn is_capacity_binary_vec(&self) -> bool
Source§fn is_capacity_binary_set(&self) -> bool
fn is_capacity_binary_set(&self) -> bool
Source§fn is_capacity_multi(&self) -> bool
fn is_capacity_multi(&self) -> bool
Source§fn is_capacity_vec(&self) -> bool
fn is_capacity_vec(&self) -> bool
Source§fn is_capacity_set(&self) -> bool
fn is_capacity_set(&self) -> bool
Source§impl GetCategory for Term
impl GetCategory for Term
Source§fn get_category(&self) -> TermCategory
fn get_category(&self) -> TermCategory
Source§fn is_compound(&self) -> bool
fn is_compound(&self) -> bool
Source§fn is_statement(&self) -> bool
fn is_statement(&self) -> bool
Source§impl MaximumVariableId for &Term
词项引用
impl MaximumVariableId for &Term
词项引用
fn maximum_variable_id(&self) -> usize
Source§impl MaximumVariableId for Term
词项本身
impl MaximumVariableId for Term
词项本身
Source§fn maximum_variable_id(&self) -> usize
fn maximum_variable_id(&self) -> usize
🆕获取一个词项中编号最大的变量词项id
Source§impl Ord for Term
impl Ord for Term
Source§impl PartialOrd for Term
impl PartialOrd for Term
Source§impl TLink<Term> for TermLink
impl TLink<Term> for TermLink
Source§impl TryFrom<&str> for Term
字符串解析路线:词法解析 ⇒ 词法折叠
impl TryFrom<&str> for Term
字符串解析路线:词法解析 ⇒ 词法折叠
- 🎯同时兼容
str::parse与[str::try_into] - 📌使用标准OpenNARS ASCII语法