第三十二章:WSaiOS EOM认知匹配系统工程实现——基于PHP OOP、MVC与Smarty架构
32.1 认知匹配工程目标
前面EOM定义:
认知匹配:
不是简单搜索。
传统搜索:
输入关键词
↓
数据库查询
↓
返回结果
EOM匹配:
用户需求
↓
需求对象
↓
对象属性分析
↓
关系匹配
↓
知识匹配
↓
经验评分
↓
输出结果
软件实现目标:
建立一个:
Cognitive Matching System(认知匹配系统)
32.2 面向对象思想与EOM对应关系
面向对象:
核心:
Class
↓
Object
↓
Property
↓
Method
EOM:
核心:
认知对象
↓
属性
↓
状态
↓
关系
↓
方法
二者对应:
| EOM | PHP OOP |
|---|---|
| 认知对象 | Class实例 |
| 对象属性 | Property |
| 对象能力 | Method |
| 对象关系 | Object Association |
| 对象状态 | Object State |
| 知识结构 | Object Network |
因此:
PHP OOP非常适合实现EOM。
32.3 MVC整体结构设计
WSaiOS匹配系统:
采用:
MVC + Cognitive Layer
结构:
用户
↓
View层
Smarty模板
↓
Controller层
↓
Cognitive Service层
--------------------------------
ElementService
ObjectService
RelationService
KnowledgeService
MatchingService
MemoryService
--------------------------------
↓
Model层
↓
MySQL
32.4 Model层设计
Model负责:
数据对象。
例如:
SupplierModel
供应商对象:
class SupplierModel
{
private $id;
private $name;
private $country;
private $products;
public function setName($name)
{
$this->name=$name;
}
public function getName()
{
return $this->name;
}
}
对应:
EOM:
供应商认知对象
32.5 Product对象设计
产品对象:
class ProductModel
{
private $name;
private $category;
private $attributes=[];
public function addAttribute(
$key,
$value
)
{
$this->attributes[$key]=$value;
}
}
例如:
生成:
Product Object
name:
electric toothbrush
attributes:
motor
battery
waterproof
32.6 Relationship对象设计
对象之间:
通过关系连接。
PHP:
class Relationship
{
private $source;
private $type;
private $target;
public function __construct(
$source,
$type,
$target
)
{
$this->source=$source;
$this->type=$type;
$this->target=$target;
}
}
例如:
建立:
Supplier
|
produces
|
↓
Product
32.7 Knowledge Model设计
知识对象:
class KnowledgeModel
{
private $objects=[];
private $relations=[];
private $experience;
public function addObject($object)
{
$this->objects[]=$object;
}
public function addRelation($relation)
{
$this->relations[]=$relation;
}
}
保存:
对象
+
关系
+
经验
32.8 MatchingService设计
核心:
匹配服务。
Service层:
负责业务逻辑。
结构:
Controller
↓
MatchingService
↓
KnowledgeModel
↓
Database
PHP:
class MatchingService
{
public function match(
$request
)
{
$result=[];
//对象匹配
//关系匹配
//经验评分
return $result;
}
}
32.9 对象匹配实现
例如:
用户需求:
美国电动牙刷供应商
转换:
Demand Object:
$demand=new SupplierModel();
$demand->country="USA";
$demand->product="electric toothbrush";
查询知识对象:
$suppliers=$knowledge
->getSuppliers();
比较:
if(
$supplier->country
==
$demand->country
)
{
$score+=30;
}
形成:
对象匹配。
32.10 属性匹配
对象属性:
例如:
供应商:
国家
产品
认证
产能
匹配:
class AttributeMatcher
{
public function compare(
$objectA,
$objectB
)
{
$score=0;
//属性比较
return $score;
}
}
32.11 关系匹配
不仅比较对象。
还比较关系。
例如:
需求:
采购
要求:
Supplier
↓
Supply
↓
Product
代码:
class RelationMatcher
{
public function match(
$relation
)
{
if(
$relation->type=="supply"
)
{
return true;
}
}
}
32.12 Memory评分模块
经验加入:
class MemoryService
{
public function getScore(
$object
)
{
return 85;
}
}
例如:
供应商:
基础:
70分
历史:
+15
最终:
85分
32.13 Controller调用流程
Controller:
接收用户请求。
class SearchController
{
public function action()
{
$keyword=$_POST["keyword"];
$result=
$this->matchingService
->match($keyword);
$smarty=
new Smarty();
$smarty->assign(
"result",
$result
);
$smarty->display(
"result.tpl"
);
}
}
完成:
MVC流程。
32.14 Smarty结果展示
Smarty:
只负责:
显示。
result.tpl:
<h2>
匹配结果
</h2>
{foreach $result as $item}
供应商:
{$item.name}
匹配度:
{$item.score}
{/foreach}
输出:
供应商A
匹配度:
90%
原因:
产品匹配
地区匹配
历史经验良好
32.15 完整工程运行流程
最终:
用户输入
↓
Controller
↓
MatchingService
↓
Object Matcher
↓
Relation Matcher
↓
Memory Service
↓
Knowledge Model
↓
MySQL
↓
Controller
↓
Smarty
↓
用户
32.16 与传统搜索系统区别
传统:
Keyword
↓
SQL LIKE
↓
Result
WSaiOS:
Keyword
↓
Element
↓
Object
↓
Relation
↓
Knowledge
↓
Memory
↓
Matching
↓
Decision
32.17 本章总结
本章完成:
EOM理论到PHP工程实现转换。
核心结构:
EOM认知对象
↓
PHP Class对象
↓
MVC Controller调用
↓
Service业务处理
↓
Knowledge Model
↓
Matching Engine
↓
Smarty展示
下一章应该进入:
第三十三章:WSaiOS GEO认知匹配应用系统实现——基于电动牙刷采购场景案例
重点:
- 产品对象模型;
- 城市对象模型;
- 采购角色对象模型;
- GEO关键词如何转换为认知对象;
- PHP/MySQL实际匹配流程;
- 自动生成采购机会分析页面。
这样才真正进入你的WSaiOS工程应用。