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

第31章 Property

第31章 Property

本章大纲

  1. Property 定义
  2. 属性类型
  3. 属性值
  4. 属性状态
  5. 属性来源
  6. 属性变化
  7. 属性比较
  8. 属性匹配
  9. Property 示例

31.1 Property 定义

在 SAI Framework 中,Property(属性)是用于描述 Object 特征、参数、数值、状态描述或其他可描述信息的数据结构。

前一章已经建立:

Object
├── ID
├── Type
├── Property
├── Method
├── State
└── Relation

其中 Property 专门回答:

这个 Object 具有什么特征?

例如:

Object: Fan

可以具有:

Property
├── name = Living Room Fan
├── speed = 1200
├── power = 50
├── brand = ABC
└── location = living-room

所以:

Object → 是什么对象

Property → 对象具有什么特征

Property 在 SAI 中的位置

Information
      ↓
Perception
      ↓
Element
      ↓
Object
      ↓
Property
      ↓
Cognition

Property 是 Object 内部的重要结构,也是后续 Matching、Understanding、Reasoning、Decision 的基础数据之一。


31.2 属性类型

不同 Property 表示的数据形式不同,因此可以定义不同的属性类型。

1. String 属性

字符串:

name = "Living Room Fan"
brand = "ABC"
location = "living-room"

2. Number 属性

数字:

temperature = 32
speed = 1200
power = 50
weight = 5.6

3. Boolean 属性

布尔值:

enabled = true
connected = false

4. State 属性

描述对象状态的属性:

power_state = "on"
connection_state = "online"

需要注意:

Object State

和:

Property

在结构上可以分开管理。

例如:

Fan

Property:
    speed = 1200

State:
    power = on

也可以将某些状态信息以 Property 形式保存:

Property:
    power_state = on

具体采用哪种方式,可以由 SAI 的对象模型决定。


5. Measurement 属性

测量类属性:

temperature = 32°C
distance = 5m
speed = 10m/s
weight = 50kg

通常需要:

value
unit

例如:

temperature
value = 32
unit = C

6. Location 属性

空间位置:

location = living-room

或者:

location
{
    x = 100
    y = 200
    z = 0
}

7. Time 属性

时间信息:

created_at
updated_at
last_seen

例如:

last_seen = 2026-09-12 15:20:00

8. Collection 属性

一个属性也可以包含多个值:

tags
[
    "home",
    "fan",
    "device"
]

因此 Property 类型可以形成:

Property
├── String
├── Number
├── Boolean
├── State
├── Measurement
├── Location
├── Time
└── Collection

31.3 属性值

Property 最核心的部分是 Value(值)

例如:

temperature = 32

其中:

Property Name
temperature

Property Value
32

再例如:

color = white
name = Living Room Fan
speed = 1200

属性名称与属性值不能混淆

temperature = 32

这里:

temperature → 属性名称
32          → 属性值

同样:

speed = 1200
speed → Property
1200  → Value

因此:

Property
├── name
└── value

Value 可以是复杂结构

例如位置:

location
{
    x = 100
    y = 200
    z = 0
}

或者:

temperature
{
    value = 32
    unit = C
}

所以 Property Value 不一定只能是字符串或数字。


属性值的来源

例如:

temperature = 32

这个值可能来自:

TemperatureSensor

也可能来自:

Human
Database
API
Device
Scene

因此 Property 不应该只保存:

name
value

还应该能够追踪:

source
time
state

31.4 属性状态

Property 自身也可以具有状态。

例如:

temperature = 32
state = valid

常见属性状态:

valid
invalid
unknown
confirmed
unconfirmed
changed
expired

为什么 Property 需要 State?

因为:

temperature = 32

并不能说明这个值是否可靠。

可能:

temperature = 32
state = valid

也可能:

temperature = 32
state = expired

两者的意义不同。

因此:

Value
+
State

才能更完整地描述属性。


Property State 与 Object State

例如:

Fan

Object State:
    on

同时:

Property:
    speed = 1200
    state = valid

这里:

Object State
→ Fan 当前处于什么状态

Property State
→ speed=1200 这个属性数据当前是否有效

这是两个不同层次。


31.5 属性来源

Property Source 用于记录属性值从哪里获得。

例如:

temperature = 32
source = temperature-001

表示:

TemperatureSensor
        ↓
temperature = 32

Source 的作用

主要用于:

追踪
验证
比较
更新
冲突处理
历史记录

例如两个传感器:

Sensor-A → temperature = 32
Sensor-B → temperature = 31

如果没有 Source:

temperature = ?

很难知道两个值分别来自哪里。

如果保留 Source:

Property
├── value = 32
└── source = sensor-A

以及:

Property
├── value = 31
└── source = sensor-B

后续系统就可以进一步进行比较和判断。


Property Source 不等于 Object

例如:

Object
Room-001

属性:

temperature = 32

来源:

temperature-sensor-001

所以:

Object → 属性属于谁

Source → 属性值来自哪里

31.6 属性变化

Object 在运行过程中,其 Property 会不断变化。

例如:

Fan
speed = 0

启动后:

speed = 800

继续调整:

speed = 1200

形成:

0
↓
800
↓
1200

Property 本身没有改变身份:

Property Name = speed

变化的是:

Property Value

属性变化模型

可以表示为:

Property
{
    name
    oldValue
    newValue
    time
    source
}

例如:

name      = speed
oldValue  = 800
newValue  = 1200
time      = ...
source    = fan-controller

属性变化事件

当属性发生变化时,可以产生:

PropertyChanged

例如:

temperature
32 → 33

产生:

PropertyChanged

然后:

PropertyChanged
       ↓
Information
       ↓
Perception
       ↓
Cognition

这样,SAI 就能够持续感知对象变化。


属性变化不等于对象变化

例如:

Fan ID = fan-001

速度:

0 → 1200

Object 仍然是:

fan-001

只是:

Property.speed

发生变化。

所以:

Object Identity → 稳定

Property Value → 可变化

31.7 属性比较

Property Comparison(属性比较)用于判断两个属性之间的关系。

例如:

temperature = 32
temperature = 30

可以进行:

32 > 30
32 = 30
32 < 30

数值比较

对于 Number:

Property A = 32
Property B = 30

结果:

A > B

字符串比较

例如:

location = living-room

与:

location = bedroom

可以判断:

A != B

布尔比较

例如:

enabled = true

与:

enabled = false

结果:

A != B

状态比较

例如:

Fan A
power_state = on
Fan B
power_state = off

结果:

A != B

属性比较的基本逻辑

Property A
     ↓
Type
     ↓
Value
     ↓
Comparison
     ↓
Result

例如:

temperature
32

temperature
30

↓

32 > 30

属性比较是后续规则判断的重要基础。


31.8 属性匹配

Property Matching(属性匹配)与 Property Comparison 有联系,但不是完全相同。

比较

主要回答:

两个值之间是什么关系?

例如:

32 > 30

匹配

主要回答:

两个属性是否符合指定匹配条件?

例如:

Property A
temperature = 32

Property B
temperature = 32

可以判断:

Match = true

基本属性匹配

可以使用:

Name 相同
+
Type 相同
+
Value 相同

例如:

A:
name = temperature
type = number
value = 32
B:
name = temperature
type = number
value = 32

结果:

Match = true

部分匹配

有时不需要 Value 完全相同。

例如:

A:
temperature = 32

B:
temperature = 33

如果规则是:

temperature > 30

那么二者都可以满足:

Match = true

这已经属于条件匹配


范围匹配

例如:

temperature
value = 32

条件:

30 <= temperature <= 35

结果:

Match = true

属性匹配与 Cognition

Property 本身只提供:

Value
Comparison
Matching

它不负责最终理解。

例如:

temperature = 32

Property 可以进行:

32 > 30

但:

32 > 30
→ 房间很热

属于更高层的 Cognition/Rule/Understanding 处理。

因此:

Property
→ 提供结构化属性

PropertyMatcher
→ 执行属性匹配

Cognition
→ 对匹配结果进行认知组织

Reasoning
→ 根据规则进一步推理

31.9 Property 示例

下面建立一个完整的 Property PHP 类。

Property 类

<?php

namespace SAI\Object;

class Property
{
    protected $name;
    protected $type;
    protected $value;
    protected $state;
    protected $source;
    protected $time;

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

    public function getName()
    {
        return $this->name;
    }

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

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

    public function setValue($value)
    {
        $oldValue = $this->value;

        $this->value = $value;
        $this->state = 'changed';
        $this->time = time();

        return $oldValue;
    }

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

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

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

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

这个类对应:

Property
├── Name
├── Type
├── Value
├── State
├── Source
└── Time

Property 实例

创建温度属性:

$temperature = new Property(
    'temperature',
    'number',
    32,
    'temperature-001'
);

得到:

Property
├── name   = temperature
├── type   = number
├── value  = 32
├── state  = valid
├── source = temperature-001
└── time   = 当前时间

修改属性

$oldValue = $temperature->setValue(33);

原来:

temperature = 32

修改后:

temperature = 33

同时:

state = changed

因此:

32
 ↓
33
 ↓
PropertyChanged

Property 比较示例

可以建立一个简单的比较器:

class PropertyComparator
{
    public function equal(Property $a, Property $b)
    {
        if ($a->getName() !== $b->getName()) {
            return false;
        }

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

        return $a->getValue() === $b->getValue();
    }

    public function greaterThan(Property $a, Property $b)
    {
        return $a->getValue() > $b->getValue();
    }

    public function lessThan(Property $a, Property $b)
    {
        return $a->getValue() < $b->getValue();
    }
}

例如:

$a = new Property(
    'temperature',
    'number',
    32
);

$b = new Property(
    'temperature',
    'number',
    30
);

执行:

$comparator = new PropertyComparator();

$result = $comparator->greaterThan(
    $a,
    $b
);

结果:

32 > 30

因此:

true

Property 匹配示例

class PropertyMatcher
{
    public function match(Property $a, Property $b)
    {
        if ($a->getName() !== $b->getName()) {
            return false;
        }

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

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

        return true;
    }
}

例如:

A:
temperature = 32

B:
temperature = 32

结果:

Match = true

而:

A:
temperature = 32

B:
temperature = 31

结果:

Match = false

31.10 Object + Property 完整结构

把第30章和第31章连接起来:

Object
│
├── ID
│   └── fan-001
│
├── Type
│   └── fan
│
├── Property
│   ├── name
│   │   └── Living Room Fan
│   │
│   ├── speed
│   │   └── 1200
│   │
│   ├── power
│   │   └── 50
│   │
│   └── location
│       └── living-room
│
├── State
│   └── on
│
├── Method
│   ├── turnOn()
│   ├── turnOff()
│   └── setSpeed()
│
└── Relation
    └── located_at → room-001

这里:

Object

是实体。

Property

是实体特征。

State

是实体当前状态。

Method

是实体可以执行的操作。

Relation

是实体与其他实体之间的联系。


31.11 Property 与 Element 的关系

上一章的 Element 是基础信息单元。

例如:

Element
type  = property
value = temperature

以及:

Element
type  = value
value = 32

经过组织:

Element
   ↓
Property
   ↓
temperature = 32
   ↓
Object
   ↓
Room

所以:

Element
    ↓
Property
    ↓
Object

并不是所有 Element 都直接成为 Property。

例如:

Element → Object
Element → Property
Element → State
Element → Relation

最终共同组成 Object。


31.12 Property 在 SAI 数据流中的位置

当前已经形成:

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

例如真实场景:

TemperatureSensor
        ↓
      32°C
        ↓
   Information
        ↓
      Scene
        ↓
     Element
        ↓
     Property
        ↓
Room.temperature = 32

然后才能进入更高层:

Property
temperature = 32
        ↓
Comparison
32 > 30
        ↓
Matching
temperature condition matched
        ↓
Cognition
        ↓
Reasoning
        ↓
Decision

本章小结

第31章建立了 SAI Framework 的 Property 属性层

核心定义:

Property 是用于描述 Object 特征、参数、数值、状态描述以及其他可描述信息的数据结构。

核心结构:

Property
├── Name
├── Type
├── Value
├── State
├── Source
└── Time

核心关系:

Element
   ↓
Object
   ↓
Property

核心能力:

Property
├── 保存属性值
├── 描述属性类型
├── 保存属性状态
├── 记录属性来源
├── 处理属性变化
├── 属性比较
└── 属性匹配

最重要的层次区别:

Object
→ 它是谁

Property
→ 它有什么特征

Property Value
→ 特征具体是什么

Property State
→ 这个属性数据当前是什么状态

Property Source
→ 这个属性值来自哪里

Property Comparison
→ 两个属性值有什么关系

Property Matching
→ 两个属性是否符合匹配条件

到这里,SAI Framework 已经从:

Information
→ Scene
→ Element
→ Object
→ Property

逐步形成了可用于认知处理的对象—属性结构

下一章将进入 第32章 Method,重点解决:

Object
   ↓
Method
   ↓
Object 能够执行什么操作

说明:以上 PHP 代码是本章的设计示例,用于说明 SAI Framework 的 OOP 结构,未作为实际项目代码执行验证。

Leave a Reply

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