Skip to main content

TermComponents

Enum TermComponents 

Source
pub enum TermComponents {
    Empty,
    Word(String),
    Variable(usize),
    Compound(Box<[Term]>),
}
Expand description

复合词项组分

  • ⚠️

Variants§

§

Empty

不包含任何组分

  • 📄占位符
§

Word(String)

仅包含一个字符串作为「名称」

  • 📄词语
§

Variable(usize)

仅包含一个非负整数作为「变量」

  • 📄变量
§有关「变量命名」的笔记
  • 📝在NAL中,变量词项的语义仅在单个词项之内有效
    • 📄这两个词项是语义等价的:<A --> $x><B --> $y>
    • 📄这两个词项同样是语义等价的:(&&,<#1 --> lock>,<#2 --> key>)(&&,<#1 --> key>,<#2 --> lock>)
  • ✨具体原理:单个词项之内,变量名的改变不会影响其逻辑语义,只要名字不发生冲突(重命名后不和任一变量名相同)
    • 📌这意味着:若需确定「带变量词项」的唯一性,就需要一套「自动重命名」机制来保证变量「语义相等」
      • 📄此即:重命名后,可以直接通过「数据判等」实现「语义判等」逻辑
§

Compound(Box<[Term]>)

一般复合词项

  • 📌一元、二元、多元词项
  • 🚩【2024-06-12 21:18:23】现在统一「一元复合词项」「二元复合词项」和「多元复合词项」
    • 📌统一使用「构造后定长数组」实现,无需复杂match匹配(少两个分支)
    • 📌统一「可交换」与「不可交换」两类词项(无需考虑复合词项数目)
    • 📌使用堆分配的「构造后定长数组」规避「循环包含」问题

词项类型举例:

  • 📄乘积
  • 📄否定
  • 📄继承、蕴含
  • 🚩通过「构造时自动去重并排序」实现「集合无序性」
    • 📄外延差、内涵差
    • 📄外延集、内涵集
    • 📄外延交、内涵交
    • 📄合取、析取
    • 📄相似、等价
§【2024-06-12 22:12:25】有关「像」的结构实现 笔记
  • 📝实际上,「有索引」和「使用占位符」是两个相同的方案
  • 🎯这两个方案的核心目标皆为「在『外延像/内涵像』中取到『像占位符』的位置」
  • 📄差别仅在手段不同
    • 📌「有索引」的方法:多加一个字段,特别标识「像占位符位置」以便快速索引
    • 📌「使用占位符」的方法:允许「占位符」独立作为词项,在「获取像占位符位置」时依靠「索引像占位符」获取位置
  • 💭两个方案各有优劣
    • ⚠️「有索引」的方法:以设计换性能——需要多添加字段,在不应「另创新类」的情况下徒增许多模式匹配需要
    • ⚠️「使用占位符」的方法:以性能换设计——在每次「检索像占位符位置」均需要O(内容词项数)的时间复杂度
  • 🚩【2024-06-12 22:11:47】综合多方考量,最终确定(并唯一选择)第二种「使用占位符」的方案

Implementations§

Source§

impl TermComponents

内建属性

Source

pub fn len(&self) -> usize

获取「组分」的大小

  • ⚠️对于「带索引序列」不包括「索引」
    • 📄对「像」不包括「像占位符」
Source

pub fn is_empty(&self) -> bool

获取「组分是否为空」

  • 🎯自clippy提示而设
Source

pub fn get(&self, index: usize) -> Option<&Term>

获取指定位置的组分(不一定有)

  • ⚠️对于「带索引序列」不受「索引」影响
    • 📄对「像」不受「像占位符」影响
Source

pub unsafe fn get_unchecked(&self, index: usize) -> &Term

获取指定位置的组分(不检查,直接返回元素)

  • ⚠️对于「带索引序列」不受「索引」影响
    • 📄对「像」不受「像占位符」影响
§Safety

⚠️只有在「确保索引不会越界」才不会引发panic和未定义行为(UB)

Source

pub fn iter(&self) -> impl Iterator<Item = &Term>

获取其中「所有元素」的迭代器

  • 🚩返回一个迭代器,迭代其中所有「元素」
  • ⚠️并非「深迭代」:仅迭代自身的下一级词项,不会递归深入
Source

pub fn sort_dedup_terms(terms: Box<[Term]>) -> Box<[Term]>

在不可变长数组中对数组进行排序并去重

Source

pub fn sort_dedup_term_vec(terms: &mut Vec<Term>)

对「词项数组」重排并去重

Source

pub fn clone_to_vec(&self) -> Vec<Term>

获取内部所有词项,拷贝成变长数组

  • 🎯用于复合词项增删相关
Source

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

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

  • 🎯支持「词项」中的方法,递归判断「是否含有变量」
  • 🚩【2024-04-21 20:35:23】目前直接基于迭代器
    • 📌牺牲一定性能,加快开发速度
Source

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

判断「结构模式上是否匹配」

  • 🚩判断二者在「结构大小」与(可能有的)「结构索引」是否符合
  • ⚠️非递归:不会递归比较「组分是否对应匹配」
  • 🎯变量替换中的「相同结构之模式替换」
  • 📄variable::find_substitute
Source§

impl TermComponents

Source

pub fn contain_var(&self) -> bool

判断「是否包含变量(词项)」

  • 🎯支持「词项」中的方法,递归判断「是否含有变量」
  • 🚩【2024-04-21 20:35:23】目前直接基于迭代器
    • 📌牺牲一定性能,加快开发速度

Trait Implementations§

Source§

impl Clone for TermComponents

Source§

fn clone(&self) -> TermComponents

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TermComponents

Source§

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

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

impl Eq for TermComponents

Source§

impl From<TermComponents> for Vec<Term>

Source§

fn from(value: TermComponents) -> Self

将「词项组分」转换为「可变数组<词项>」

  • 🚩原子词项⇒空数组
  • 🚩复合词项⇒其内所有词项构成的数组
Source§

impl From<TermComponents> for Box<[Term]>

Source§

fn from(value: TermComponents) -> Self

将「词项组分」转换为「定长数组<词项>」

  • 🚩原子词项⇒空数组
  • 🚩复合词项⇒其内所有词项构成的数组
  • ℹ️与上述对Vec的转换不同:此处直接使用Box::new([])构造空数组
Source§

impl Hash for TermComponents

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 Ord for TermComponents

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for TermComponents

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for TermComponents

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 StructuralPartialEq for TermComponents

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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)