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

第四十二章:PHP OOP认知对象框架设计——从EOM模型到程序对象

WSaiOS EOM模拟人工认知工程理论

第四十二章:PHP OOP认知对象框架设计——从EOM模型到程序对象


42.1 为什么需要认知对象框架

在前面的EOM模型中:

软件认知过程:

信息

↓

Element(认知元素)

↓

Object(认知对象)

↓

Relationship(对象关系)

↓

Knowledge(知识)

↓

Memory(记忆)

↓

Matching(匹配)

但是:

理论模型必须转换为程序结构。


PHP面向对象编程(OOP)的核心思想:

就是:

将现实世界中的事物转换为程序中的对象。


因此:

EOM与PHP OOP具有天然对应关系。


42.2 EOM对象模型与PHP Class对应

EOM:

对象包含:

Object

{

Elements

Attributes

State

Relations

Methods

}

PHP:

对应:

class Object
{

    //属性
    
    public $attributes;


    //状态
    
    public $state;


    //关系
    
    public $relations;


    //方法
    
    public function action()
    {


    }


}

也就是说:

EOM定义:

对象如何认知。


OOP实现:

对象如何运行。


42.3 WSaiOS核心对象基类设计

在工程中:

所有认知对象:

继承:

CognitiveObject。


目录:

app/

classes/

CognitiveObject.php

Element.php

Relationship.php

Knowledge.php

Memory.php

CognitiveObject:

<?php

class CognitiveObject
{


protected $id;


protected $name;


protected $type;


protected $attributes=[];


protected $state;


protected $relations=[];



public function setName($name)
{

$this->name=$name;

}



public function getName()
{

return $this->name;

}



public function addRelation($relation)
{

$this->relations[]=$relation;

}



}

?>

这个类:

就是:

EOM对象的程序基础。


42.4 Element认知元素类设计

Element:

是对象形成前的信息单位。


例如:

输入:

electric toothbrush supplier Miami

拆分:

electric toothbrush

supplier

Miami

PHP:

<?php

class Element
{


private $value;


private $type;



public function __construct(
$value,
$type
)
{

$this->value=$value;

$this->type=$type;

}



public function getValue()
{

return $this->value;

}



public function getType()
{

return $this->type;

}


}

?>

实例:

$product =
new Element(
"electric toothbrush",
"product"
);


$city =
new Element(
"Miami",
"location"
);

42.5 Object Builder对象生成器

Element不能直接使用。


需要:

元素组合成对象。


设计:

ObjectBuilder。


流程:

Element

↓

ObjectBuilder

↓

CognitiveObject

PHP:

class ObjectBuilder
{


public function build($elements)
{


$object=
new CognitiveObject();


foreach($elements as $element)
{


//分析元素


}


return $object;


}


}

作用:

把:

碎片信息。

转换:

结构化对象。


42.6 业务对象继承设计

CognitiveObject:

基础类。


具体对象:

继承。


例如:

供应商对象:

class SupplierObject 
extends CognitiveObject
{


private $capacity;


private $certification;



public function supply()
{

return "供应产品";

}


}

产品对象:

class ProductObject
extends CognitiveObject
{


private $material;


private $function;



public function describe()
{


}


}

形成:

对象体系。


结构:

CognitiveObject

        |

-----------------

|               |

Supplier      Product

Object        Object

42.7 Relationship关系对象设计

EOM认为:

对象不是孤立存在。


关系本身也是对象。


例如:

供应关系:

Supplier

   |

 supply

   |

Product

PHP:

class Relationship
{


private $source;


private $type;


private $target;



public function __construct(
$source,
$type,
$target
)
{

$this->source=$source;

$this->type=$type;

$this->target=$target;

}


}

实例:

$relation=
new Relationship(

$supplier,

"supply",

$product

);

42.8 Knowledge知识对象设计

知识:

不是简单文本。


在WSaiOS中:

知识由:

对象

+

关系

+

经验

组成。


PHP:

class Knowledge
{


private $objects=[];


private $relations=[];


private $experience;



public function addObject($object)
{

$this->objects[]=$object;

}



public function addRelation($relation)
{

$this->relations[]=$relation;

}


}

42.9 Memory记忆对象设计

记忆:

保存:

历史经验。


PHP:

class Memory
{


private $object;


private $type;


private $content;


private $weight;



public function update($value)
{

$this->weight=$value;

}


}

对应:

短期记忆

长期记忆

时序记忆

概率记忆

42.10 Object与数据库映射

PHP对象:

需要保存。


使用:

Model层。


对象:

SupplierObject

数据库:

cognitive_objects

Model:

class ObjectModel
{


public function save(
CognitiveObject $object
)
{


$sql="
INSERT INTO cognitive_objects
(name,type)
VALUES
(...)
";


}


}

形成:

ORM思想。


42.11 OOP封装认知能力

传统程序:

数据:

散落。


OOP:

对象封装。


例如:

供应商:

不仅保存:

名称

产品

地区

还具有:

行为:

供应

匹配

评价

推荐

PHP:

class SupplierObject
{


public function matchMarket($market)
{


//市场匹配逻辑


}



public function calculateScore()
{


//评分


}


}

42.12 EOM与OOP对应关系

EOM PHP OOP
认知元素 Element Class
认知对象 Object Class
对象属性 Class Property
对象状态 Object State
对象关系 Relationship Class
对象能力 Method
知识结构 Knowledge Class
经验 Memory Class

42.13 本章总结

本章完成:

EOM理论向PHP OOP转换。

核心:

现实信息

↓

认知对象

↓

PHP Class

↓

软件对象

↓

程序运行

WSaiOS工程核心不是:

建立复杂算法。

而是:

通过面向对象方法:

让软件中的Class结构对应认知结构。


下一章:

第四十三章:WSaiOS MVC认知应用架构实现——Controller、Service、Model分层设计

重点研究:

  • 为什么认知系统需要MVC;
  • Controller如何管理用户请求;
  • Service如何承载认知流程;
  • Model如何访问知识库;
  • MVC如何组织EOM认知模块。

Leave a Reply

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