WSaiOS EOM模拟人工认知工程理论
第三十六章:WSaiOS EOM认知应用开发流程——从需求分析到完整PHP MVC系统部署
36.1 从理论研究进入应用开发
前面章节完成:
EOM理论体系:
信息
↓
元素
↓
对象
↓
关系
↓
知识
↓
匹配
↓
决策
↓
行动
↓
经验
↓
记忆
工程体系:
PHP OOP
↓
MVC
↓
Smarty
↓
MySQL
↓
Cognitive Engine
但是:
一个完整人工认知系统不能停留在模型设计。
必须解决:
如何从零开发一个可运行的WSaiOS应用?
因此:
本章研究:
WSaiOS应用工程开发流程。
36.2 WSaiOS应用开发思想
传统软件开发:
流程:
需求
↓
数据库设计
↓
页面开发
↓
业务代码
WSaiOS:
增加:
认知设计阶段。
完整流程:
业务需求
↓
认知对象分析
↓
对象模型设计
↓
关系模型设计
↓
知识库设计
↓
记忆模型设计
↓
PHP Class设计
↓
MVC实现
↓
页面展示
↓
应用运行
36.3 第一步:业务需求分析
案例:
开发:
GEO商业认知分析系统
用户需求:
输入:
electric toothbrush distributor Miami Florida
系统输出:
市场机会分析
供应商匹配
SEO页面建议
商业关系分析
传统分析:
认为:
关键词。
EOM分析:
认为:
商业认知对象。
36.4 第二步:建立认知对象模型
分析输入:
electric toothbrush distributor Miami Florida
拆分:
元素
electric toothbrush
distributor
Miami
Florida
USA
形成:
对象
Demand Object
{
Product:
Electric Toothbrush
Role:
Distributor
Location:
Miami
Market:
USA
}
设计PHP类:
class DemandObject
{
public $product;
public $role;
public $city;
public $state;
}
36.5 第三步:设计对象关系
对象不是孤立。
建立:
供应关系。
结构:
Supplier
|
supplies
|
Product
|
sold in
|
Market
PHP:
class Relationship
{
public $source;
public $type;
public $target;
}
实例:
new Relationship(
"Supplier A",
"supply",
"Electric Toothbrush"
);
36.6 第四步:设计知识模型
知识:
不是表格。
而是:
结构。
例如:
知识:
供应商A
生产
电动牙刷
适合
美国市场
PHP:
class Knowledge
{
private $object;
private $relation;
private $experience;
}
36.7 第五步:设计Memory模型
系统运行以后:
需要学习。
保存:
短期记忆
当前分析。
长期记忆
历史供应商评价。
时序记忆
供应商变化。
概率记忆
成功率。
PHP:
class Memory
{
public $type;
public $content;
public $weight;
}
36.8 第六步:建立工程目录
完整PHP MVC:
wsaios-app/
app/
├── controllers/
│
│── GeoController.php
├── models/
│
│── ObjectModel.php
│── KnowledgeModel.php
│── MemoryModel.php
├── services/
│── ElementService.php
│── ObjectService.php
│── MatchingService.php
│── DecisionService.php
├── classes/
│── CognitiveObject.php
│── Relationship.php
│── Knowledge.php
│── Memory.php
├── views/
│── smarty/
│ └── geo.tpl
config/
database/
public/
36.9 第七步:数据库初始化
创建:
认知对象表。
CREATE TABLE cognitive_objects
(
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
type VARCHAR(100),
attributes TEXT
);
关系表:
CREATE TABLE relationships
(
id INT AUTO_INCREMENT PRIMARY KEY,
source INT,
relation VARCHAR(100),
target INT
);
记忆表:
CREATE TABLE memory
(
id INT AUTO_INCREMENT PRIMARY KEY,
object_id INT,
experience TEXT,
weight INT
);
36.10 第八步:Service层开发
为什么需要Service?
因为:
Controller不能承担认知逻辑。
错误:
Controller
里面写:
对象分析
匹配
评分
数据库
正确:
Controller
↓
Service
↓
Model
例如:
MatchingService:
class MatchingService
{
public function match($object)
{
//对象匹配
//关系匹配
//记忆评分
return $result;
}
}
36.11 第九步:Controller设计
Controller负责:
协调。
代码:
class GeoController
{
public function analyze()
{
$input=$_POST["keyword"];
$result=
$this->matchingService
->match($input);
$this->smarty
->assign(
"result",
$result
);
$this->smarty
->display(
"geo.tpl"
);
}
}
Controller:
不负责认知。
只负责流程控制。
36.12 第十步:Smarty表现层
Smarty:
展示认知结果。
geo.tpl:
<h1>
GEO分析结果
</h1>
产品:
{$result.product}
城市:
{$result.city}
角色:
{$result.role}
评分:
{$result.score}
输出:
GEO认知分析
产品:
Electric Toothbrush
地区:
Miami
角色:
Distributor
匹配:
90%
36.13 第十一步:认知系统运行流程
完整运行:
用户输入
↓
GeoController
↓
ElementService
↓
ObjectService
↓
KnowledgeService
↓
MatchingService
↓
MemoryService
↓
Result
↓
Smarty
↓
页面
36.14 一个完整案例
输入:
electric toothbrush supplier Los Angeles
Element分析
得到:
Product:
Electric Toothbrush
Role:
Supplier
City:
Los Angeles
Object形成
Demand Object
Knowledge匹配
查询:
Supplier Objects
Memory评价
读取:
历史合作记录
Decision
输出:
推荐供应商
生成SEO页面
36.15 部署结构
服务器:
Apache/Nginx
↓
PHP
↓
MySQL
↓
Smarty
↓
WSaiOS Cognitive Engine
本地开发:
WAMP:
Apache
PHP 5.6+
MySQL
符合:
单机部署。
36.16 WSaiOS工程开发原则
原则一:
认知模型先于代码。
不是:
先写数据库。
而是:
先定义:
对象。
原则二:
对象先于表。
数据库:
服务对象模型。
原则三:
业务逻辑进入Service。
保持:
MVC清晰。
原则四:
记忆驱动更新。
系统运行越久:
能力越强。
36.17 本章总结
WSaiOS应用开发流程:
需求分析
↓
EOM对象设计
↓
PHP Class设计
↓
Service开发
↓
MVC组织
↓
MySQL存储
↓
Smarty展示
↓
应用运行
最终形成:
WSaiOS
=
EOM认知模型
+
PHP OOP
+
MVC
+
Smarty
+
Knowledge Base
+
Memory Engine
+
Business Application
下一章:
第三十七章:WSaiOS EOM认知系统实际案例——GEO商业智能分析平台完整实现
重点研究:
- GEO分析业务需求;
- 城市、产品、角色对象模型;
- 关键词工厂如何转换为认知对象;
- MySQL实际表结构;
- PHP代码调用流程;
- 自动生成商业分析结果。