首页 理论 架构 工程 文档 白皮书 著作 研究 案例 下载 博客 关于 开始使用 →

第八篇 Element / Object / Relation

第八篇 Element / Object / Relation

第29章 Element

本章大纲

  1. Element 定义
  2. Element 类型
  3. Element 值
  4. Element 来源
  5. Element 状态
  6. Element 标识
  7. Element 匹配
  8. Element Manager
  9. Element 实例

29.1 Element 定义

Element(元素)是 SAI Framework 对信息中可以被独立识别、描述、比较、匹配和进一步组织的最基础信息单元。

简单来说:

Element 是 SAI 从 Information 或 Scene 中提取出来、可以参与后续认知处理的基本单位。

前面的数据流程是:

Information
    ↓
Perception
    ↓
Element
    ↓
Object
    ↓
Relation
    ↓
Cognition

因此 Element 是连接:

信息世界

与:

对象世界

之间的重要基础。


29.1.1 为什么需要 Element?

假设 SAI 收到一个场景:

房间温度 32°C
一个人正在房间内
风扇处于关闭状态

原始信息是一个整体:

Information

但 SAI 后续处理需要把它拆分成可以独立处理的部分:

Element
├── temperature
├── 32
├── person
├── present
├── fan
└── off

进一步组织:

Element
   ↓
Object
   ↓
Property
   ↓
Relation

例如:

temperature = 32

可以形成:

Object: Room
Property: temperature
Value: 32

所以:

Element 是信息结构化和对象化的重要基础。


29.1.2 Element 的基本特征

一个 Element 至少需要能够描述:

Element
├── ID
├── Type
├── Value
├── Source
└── State

完整一些:

Element
{
    id
    type
    value
    source
    state
    time
    metadata
}

其中:

id       → 它是谁
type     → 它是什么类型
value    → 它的具体值
source   → 它来自哪里
state    → 它当前处于什么状态
time     → 什么时候产生/获取
metadata → 其他描述

29.2 Element 类型

Element 必须能够区分不同类型。

最基础的 Element 类型可以包括:

Element
├── Object Element
├── Property Element
├── Value Element
├── State Element
├── Relation Element
├── Event Element
├── Location Element
├── Time Element
└── Measurement Element

29.2.1 Object Element

表示一个可能形成对象的基本元素。

例如:

person
fan
room
sensor
car
robot

例如:

{
    type: "object",
    value: "fan"
}

后续可以形成:

Object
Fan

29.2.2 Property Element

描述对象的某个属性。

例如:

temperature
speed
color
weight
state

例如:

{
    type: "property",
    value: "temperature"
}

29.2.3 Value Element

表示具体值:

32
ON
OFF
5m
present
living-room

例如:

{
    type: "value",
    value: 32
}

29.2.4 State Element

表示状态信息:

online
offline
on
off
present
absent
running
stopped

例如:

{
    type: "state",
    value: "off"
}

29.2.5 Relation Element

表示关系中的关系词。

例如:

located_at
contains
controls
detects
belongs_to
near

例如:

{
    type: "relation",
    value: "located_at"
}

后续可以形成:

Person
   ↓ located_at
LivingRoom

29.2.6 Location Element

表示空间位置:

living-room
kitchen
warehouse
x=10,y=20
latitude
longitude

29.2.7 Time Element

表示时间:

2026-09-12 15:30

或者:

start_time
end_time
duration

29.2.8 Measurement Element

表示测量结果:

temperature = 32°C
distance = 5m
speed = 20km/h

可以结构化为:

Measurement Element
├── value
├── unit
├── source
└── time

29.3 Element 值

Element 的 value 是非常重要的部分。

例如:

Element
{
    type: "temperature",
    value: 32
}

这里:

type  = temperature
value = 32

两者不能混淆。


29.3.1 Type 与 Value

例如:

temperature = 32

可以拆成:

Element A
type  = property
value = temperature

以及:

Element B
type  = value
value = 32

再通过关系组织:

temperature
      ↓
     has
      ↓
     32

29.3.2 Value 可以是什么?

Value 不一定是字符串。

可以是:

String
Integer
Float
Boolean
Array
Object Reference
DateTime
Coordinate
Measurement

例如:

array(
    'type' => 'temperature',
    'value' => 32
);

位置:

array(
    'type' => 'position',
    'value' => array(
        'x' => 10,
        'y' => 20
    )
);

状态:

array(
    'type' => 'state',
    'value' => 'online'
);

29.3.3 Value 不等于 Meaning

这是 SAI 中非常重要的区分。

例如:

temperature = 32

Element 只表示:

value = 32

它本身不必直接产生:

很热

或者:

需要打开风扇

这些属于后续的:

Cognition
Reasoning
Decision

因此:

Element
→ 保存/描述元素

Cognition
→ 理解元素

Reasoning
→ 根据元素和规则推导

Decision
→ 选择行为

29.4 Element 来源

Element 必须知道来源。

因为同一个值可能来自不同来源。

例如:

32

可能来自:

TemperatureSensor
Human
Database
API
Scene
Device

因此:

Element
├── value = 32
└── source = temperature-sensor-001

29.4.1 Source 与 Element

关系:

InformationSource
       ↓
Information
       ↓
Perception
       ↓
Element

例如:

TemperatureSensor
       ↓
Temperature Information
       ↓
Perception
       ↓
Element

形成:

Element
{
    type: "temperature",
    value: 32,
    source: "temperature-001"
}

29.4.2 为什么需要 Source?

因为后续可能出现:

Sensor A → 32°C
Sensor B → 28°C
Human → “房间很热”

如果没有来源:

32
28
很热

SAI 很难追踪:

谁提供的?
什么时候提供的?
是否可信?

所以 Source 是 Element 的重要属性。


29.5 Element 状态

Element 本身也可以具有状态。

例如:

valid
invalid
active
inactive
confirmed
unconfirmed
changed
expired

可以表示:

Element
├── value = 32
├── state = valid
└── time = ...

29.5.1 Element 状态与 Object 状态

两者必须区分。

例如:

Fan
state = OFF

这是:

Object State

而:

Element
{
    type: "state",
    value: "off",
    state: "valid"
}

这里:

off

是 Element 的值;

valid

是 Element 自身的数据状态。

因此:

Object.state
≠
Element.state

29.5.2 Element 状态变化

例如:

32°C
 ↓
33°C

可以形成:

Element
old_value = 32
new_value = 33
state = changed

或者通过两个时间点的 Element 进行比较:

Element A
time = 15:00
value = 32

Element B
time = 15:01
value = 33

后续可以由 State、Event、Experience 等模块处理。


29.6 Element 标识

每一个 Element 都应该具有唯一标识。

例如:

element-000001
element-000002
element-000003

基本结构:

Element
├── id
├── type
├── value
└── source

29.6.1 ID 的作用

ID 用于:

识别
引用
比较
管理
追踪
关联

例如:

element-000001

表示某一个具体 Element。


29.6.2 ID 与 Value

不能混淆:

ID
→ Element 的身份

Value
→ Element 当前携带的值

例如:

id = element-000001
value = 32

如果下一次:

value = 33

可以是:

同一逻辑元素

也可以产生新的元素记录,取决于系统的数据生命周期设计。

因此:

ID ≠ Value

29.7 Element 匹配

Element Matching 是后续 Cognition 和理解的重要基础。

它的作用是:

判断两个或多个 Element 是否具有相同、相近、关联或可组合的特征。


29.7.1 最简单的匹配

例如:

Element A
type = temperature
value = 32
Element B
type = temperature
value = 32

可以判断:

Type Match = true
Value Match = true

29.7.2 类型匹配

例如:

temperature

与:

temperature

匹配。

而:

temperature

与:

distance

不匹配。


29.7.3 值匹配

例如:

32

与:

32

完全匹配。

而:

32

与:

33

不完全相同。

但在某些场景下,可以定义数值距离:

distance = |32 - 33|
         = 1

再根据规则判断:

distance <= threshold

是否属于近似匹配。

这属于后续 Matching 机制,而不是 Element 自身进行复杂认知。


29.7.4 来源匹配

例如:

Element A
source = sensor-001
Element B
source = sensor-001

来源一致。

也可以:

source A ≠ source B

但二者的类型和值相同。

这时可以保留两个 Element,而不是错误地把它们直接合并。


29.7.5 多条件匹配

可以建立简单的匹配条件:

Type
+
Value
+
Source
+
State
+
Context

例如:

A:
type = temperature
value = 32
source = sensor-001

B:
type = temperature
value = 32
source = sensor-001

得到:

Type Match   = 1
Value Match  = 1
Source Match = 1

最终:

Match = true

29.7.6 Element Matching 的作用

Element Matching 可以服务于:

Element
   ↓
Object Matching
   ↓
Relation Matching
   ↓
Cognition

也可以服务于:

Current Element
      ↓
Memory Element
      ↓
Match
      ↓
Recall

因此 Element 是后续匹配系统的基础数据单元。


29.8 Element Manager

当系统中 Element 数量增加以后,就需要统一管理。

因此建立:

ElementManager(元素管理器)

它负责:

注册
创建
获取
删除
更新
查询
匹配

29.8.1 ElementManager 结构

ElementManager
├── create()
├── register()
├── get()
├── has()
├── update()
├── remove()
├── all()
└── match()

29.8.2 Element 基础 PHP 类

<?php

namespace SAI\Element;

class Element
{
    protected $id;

    protected $type;

    protected $value;

    protected $source;

    protected $state;

    protected $time;

    protected $metadata = array();


    public function __construct(
        $id,
        $type,
        $value,
        $source = null
    ) {
        $this->id = $id;
        $this->type = $type;
        $this->value = $value;
        $this->source = $source;
        $this->state = 'valid';
        $this->time = time();
    }


    public function getId()
    {
        return $this->id;
    }


    public function getType()
    {
        return $this->type;
    }


    public function getValue()
    {
        return $this->value;
    }


    public function setValue($value)
    {
        $this->value = $value;
        $this->state = 'changed';
    }


    public function getSource()
    {
        return $this->source;
    }


    public function getState()
    {
        return $this->state;
    }


    public function setState($state)
    {
        $this->state = $state;
    }


    public function getTime()
    {
        return $this->time;
    }


    public function setMetadata($key, $value)
    {
        $this->metadata[$key] = $value;
    }


    public function getMetadata($key)
    {
        if (!isset($this->metadata[$key])) {
            return null;
        }

        return $this->metadata[$key];
    }


    public function getMetadata()
    {
        return $this->metadata;
    }
}

29.8.3 ElementManager 实现

<?php

namespace SAI\Element;

class ElementManager
{
    protected $elements = array();


    public function register(Element $element)
    {
        $this->elements[$element->getId()] = $element;
    }


    public function get($id)
    {
        if (!isset($this->elements[$id])) {
            return null;
        }

        return $this->elements[$id];
    }


    public function has($id)
    {
        return isset($this->elements[$id]);
    }


    public function remove($id)
    {
        unset($this->elements[$id]);
    }


    public function all()
    {
        return $this->elements;
    }


    public function count()
    {
        return count($this->elements);
    }
}

29.8.4 Element 匹配器

可以独立建立:

ElementMatcher

而不是把所有匹配逻辑都塞进 ElementManager。

<?php

namespace SAI\Element;

class ElementMatcher
{
    public function match(
        Element $a,
        Element $b
    ) {
        if ($a->getType() !== $b->getType()) {
            return false;
        }

        if ($a->getValue() !== $b->getValue()) {
            return false;
        }

        return true;
    }
}

基本规则:

Type 相同
AND
Value 相同
        ↓
Match = true

这样保持职责清晰:

Element
→ 描述元素

ElementManager
→ 管理元素

ElementMatcher
→ 匹配元素

29.9 Element 实例

下面用房间场景建立完整实例。

场景:

房间温度 32°C
有人
风扇关闭

Perception 从 Scene 中提取:

Element
├── temperature
├── 32
├── person
├── present
├── fan
└── off

29.9.1 创建 Temperature Element

$temperature = new Element(
    'element-000001',
    'temperature',
    32,
    'temperature-001'
);

得到:

ID
element-000001

Type
temperature

Value
32

Source
temperature-001

State
valid

29.9.2 创建 Person Element

$person = new Element(
    'element-000002',
    'object',
    'person',
    'scene-001'
);

29.9.3 创建 Person State Element

$personState = new Element(
    'element-000003',
    'state',
    'present',
    'scene-001'
);

29.9.4 创建 Fan Element

$fan = new Element(
    'element-000004',
    'object',
    'fan',
    'scene-001'
);

29.9.5 创建 Fan State Element

$fanState = new Element(
    'element-000005',
    'state',
    'off',
    'fan-001'
);

29.9.6 注册到 ElementManager

$manager = new ElementManager();

$manager->register($temperature);
$manager->register($person);
$manager->register($personState);
$manager->register($fan);
$manager->register($fanState);

现在:

ElementManager
│
├── element-000001 → temperature
├── element-000002 → person
├── element-000003 → present
├── element-000004 → fan
└── element-000005 → off

29.9.7 Element → Object

现在 Element 可以进一步组织为 Object。

例如:

Element
├── person
└── present

形成:

Object
Person
    │
    └── State = PRESENT

风扇:

Element
├── fan
└── off

形成:

Object
Fan
    │
    └── State = OFF

温度:

Element
├── temperature
└── 32

形成:

Object
Room
    │
    └── Property
          temperature = 32

这里就进入下一章:

Object(对象)


29.9.8 Element → Object → Relation

进一步组织:

Element
   ↓
Object
   ↓
Relation

例如:

Person
   ↓ located_at
LivingRoom

以及:

Fan
   ↓ located_at
LivingRoom

于是:

Person
   │
   │ located_at
   ▼
LivingRoom
   ▲
   │ located_at
   │
  Fan

这就是 EOM:

Element
   ↓
Object
   ↓
Relation
   ↓
Method

Element 是这一过程的基础。


本章完整数据流

经过前面第19~29章,可以形成:

External World
      ↓
InformationSource
      ↓
Sensor
      ↓
InformationReceiver
      ↓
Information
      ↓
SceneCollector
      ↓
Scene
      ↓
Central
      ↓
Dispatcher
      ↓
Coordinator
      ↓
Perception
      ↓
Element
      ↓
Object
      ↓
Property
      ↓
Relation
      ↓
Cognition

其中:

Information
→ 原始进入系统的信息

Scene
→ 时间、空间、对象、状态、关系组成的场景

Element
→ 可独立识别和处理的基础元素

Object
→ 由元素组织形成的对象

Relation
→ 对象之间的关系

本章小结

Element 是 SAI Framework 从信息/场景进入对象认知的重要基础层。

它主要解决:

信息中有什么?

例如:

32
temperature
person
present
fan
off

这些都可以首先成为 Element。

Element 的基本结构:

Element
├── ID
├── Type
├── Value
├── Source
├── State
├── Time
└── Metadata

Element 的核心职责:

识别
描述
保存
匹配
关联

而不是:

理解
推理
决策
行为

因此必须保持:

Element
   ↓
描述“是什么”

Cognition
   ↓
理解“意味着什么”

Reasoning
   ↓
推导“会发生什么/应该得到什么结论”

Decision
   ↓
决定“做什么”

最终,本章建立了 EOM 的第一层:

E
Element
 ↓
O
Object
 ↓
R
Relation
 ↓
M
Method

也就是:

Element 是 SAI Framework 中最基础的可识别信息单元,是从 Information、Scene 进入 Object、Relation 和后续 Cognition 的基础桥梁。

下一章进入 第30章 Object:重点解决 Element 如何组织成对象、Object 的身份、属性、状态、方法以及对象管理

Leave a Reply

Your email address will not be published. Required fields are marked *