第59章 从匹配理论到匹配算法
匹配是认知系统中非常核心的计算过程。
如果第58章解决的是:
理论对象
↓
数据对象
那么第59章进一步解决:
匹配理论
↓
匹配规则
↓
匹配算法
↓
匹配结果
核心思想是:
Matching 是理论层的认知关系,Matching Algorithm 是这一认知关系在工程系统中的可执行实现。
59.1 什么是匹配理论
匹配理论描述的是:
两个或多个认知对象之间,是否存在某种符合关系。
最基本的形式:
Object A
↓
Matching
↓
Object B
例如:
用户需求:
electric toothbrush supplier
对象:
Electric Toothbrush Supplier
系统需要判断:
二者是否匹配?
因此:
Matching(A, B)
不是简单的字符串相等,而是一种认知关系判断。
59.2 匹配的基本组成
一个完整的 Matching 可以定义为:
Matching
├── Subject
├── Target
├── Criteria
├── Evidence
├── Rule
├── Score
└── Result
分别表示:
Subject
匹配主体
Target
匹配目标
Criteria
匹配条件
Evidence
匹配证据
Rule
匹配规则
Score
匹配程度
Result
最终结果
因此:
Matching
=
Subject
+
Target
+
Criteria
+
Rule
+
Evaluation
59.3 匹配不是相等
这是匹配理论中的一个重要区别。
Equality
=
是否相等
而:
Matching
=
是否符合某种关系
例如:
electric toothbrush
与:
electric toothbrush supplier
字符串并不相等。
但是从搜索认知角度:
electric toothbrush
↓
product concept
↓
electric toothbrush supplier
↓
supplier concept
两者可能存在较强的语义关系。
所以:
Equal ≠ Match
59.4 匹配对象
匹配算法首先必须确定:
匹配什么?
在 WSaiOS 中,可以匹配:
Element
Object
Attribute
State
Relation
Class
Group
Individual
Keyword
Concept
Task
Context
Content
例如:
Keyword ↔ Object
Object ↔ Object
Object ↔ Class
Attribute ↔ Attribute
Relation ↔ Relation
Task ↔ Method
因此 Matching 本质上是一种认知结构之间的比较机制。
59.5 匹配条件
两个对象不能直接进行无限制比较。
必须定义 Criteria:
Criteria
├── Type
├── Name
├── Attribute
├── State
├── Relation
├── Context
└── Structure
例如:
Object A:
Electric Toothbrush Supplier
Object B:
Electric Toothbrush Manufacturer
系统可以比较:
Type
Product Category
Business Role
Keyword
Context
Relation
从而得到更加准确的匹配结果。
59.6 匹配规则
匹配规则决定:
什么情况下算匹配。
最简单的规则:
IF A = B
THEN MATCH
但是认知系统通常需要更复杂的规则:
IF
Type(A) = Type(B)
AND
Attribute(A) ≈ Attribute(B)
THEN
MATCH
进一步:
IF
NameMatch > threshold
AND
AttributeMatch > threshold
AND
RelationMatch > threshold
THEN
MATCH
因此:
Matching Rule
是匹配理论进入算法之前的重要中间层。
59.7 匹配算法
匹配算法就是:
按照匹配规则,对数据对象进行实际计算的过程。
基本过程:
Input A
Input B
↓
Extract Features
↓
Compare
↓
Evaluate Rules
↓
Calculate Score
↓
Determine Result
可以形式化为:
M(A,B)
=
Evaluate(
Compare(
Features(A),
Features(B)
)
)
59.8 最基本的匹配算法
最简单的算法可以定义为:
function match(A, B):
if A == B:
return MATCH
return NO_MATCH
但这只是:
Exact Matching
它只能处理完全一致的对象。
59.9 属性匹配
进一步可以对 Attribute 进行比较:
A.attributes
↓
Compare
↑
B.attributes
例如:
A:
material = ABS
battery = 120 min
waterproof = IPX7
B:
material = ABS
battery = 120 min
waterproof = IPX7
则:
Attribute Match = 3 / 3
可以得到:
score = 1.0
59.10 多维匹配
真正的认知匹配通常不是单维度的。
可以定义:
M(A,B)
=
w1 × NameMatch
+
w2 × TypeMatch
+
w3 × AttributeMatch
+
w4 × StateMatch
+
w5 × RelationMatch
+
w6 × ContextMatch
其中:
w1 ... w6
表示不同匹配维度的权重。
例如:
NameMatch 0.20
TypeMatch 0.25
AttributeMatch 0.20
StateMatch 0.10
RelationMatch 0.15
ContextMatch 0.10
总和:
1.00
这样就形成了一个标准化匹配评分模型。
59.11 匹配评分
匹配算法不一定只有:
MATCH
NO_MATCH
还可以产生:
score
例如:
1.00
0.92
0.75
0.53
0.21
0.00
可以定义:
0.90 - 1.00
Strong Match
0.70 - 0.89
Match
0.40 - 0.69
Weak Match
0.00 - 0.39
No Match
这样:
Matching
就从一个二值判断变成了一个可计算的认知评价过程。
59.12 匹配结果
匹配算法最终应该产生结构化结果。
例如:
Matching Result
可以表示为:
{
"subject": 10001,
"target": 20001,
"score": 0.92,
"result": "match",
"criteria": {
"type": 1.0,
"attribute": 0.90,
"relation": 0.95
}
}
因此:
Matching
最终变成:
Data
+
Rule
+
Algorithm
↓
Matching Result
59.13 匹配算法的层级
WSaiOS 可以把 Matching Algorithm 分成多个层级。
第一层:Exact Matching
A == B
判断完全相等。
第二层:Structural Matching
比较对象结构:
Class
Attribute
State
Relation
第三层:Attribute Matching
比较属性:
Attribute A
↕
Attribute B
第四层:Relation Matching
比较关系:
A → Relation → B
与:
C → Relation → D
是否具有相同关系结构。
第五层:Context Matching
加入上下文:
Object
+
Task
+
Environment
+
Time
+
User Context
进行匹配。
第六层:Composite Matching
将多个匹配结果组合:
Exact
+
Structural
+
Attribute
+
Relation
+
Context
形成综合匹配。
59.14 Matching Method
在前面的理论中:
Method
是认知任务的工程实现。
因此:
Matching
是认知概念,
而:
Matching Method
是具体实现。
例如:
Matching
↓
ExactMatchMethod
AttributeMatchMethod
RelationMatchMethod
ContextMatchMethod
CompositeMatchMethod
于是:
理论:
Matching
进入工程系统后:
算法:
match()
或者:
matchObject()
matchAttribute()
matchRelation()
matchContext()
59.15 匹配算法与 Object 的关系
匹配算法不是独立存在的。
它作用于:
Data Object
即:
Object A
↓
Matching Algorithm
↑
Object B
算法读取:
A.type
A.attributes
A.state
A.relations
以及:
B.type
B.attributes
B.state
B.relations
然后计算。
所以:
Data Object
↓
Matching Method
↓
Matching Result
构成一个完整的工程链。
59.16 匹配的递归性
匹配还具有一个非常重要的特点:
对象可以匹配对象,对象内部的结构也可以继续匹配。
例如:
Object A
├── Attribute A1
├── Attribute A2
└── Relation A3
与:
Object B
├── Attribute B1
├── Attribute B2
└── Relation B3
可以进行:
Object Match
↓
Attribute Match
↓
Relation Match
最终:
ObjectScore
=
f(
AttributeScores,
RelationScores,
StructureScore
)
因此 Matching 可以形成层级递归结构。
59.17 从匹配理论到工程算法
整个转换过程可以正式定义为:
Matching Theory
↓
Matching Model
↓
Matching Criteria
↓
Matching Rules
↓
Matching Features
↓
Matching Algorithm
↓
Matching Score
↓
Matching Result
这是第59章最核心的工程链。
59.18 与第58章连接
第58章:
理论对象
↓
数据对象
第59章:
匹配理论
↓
匹配算法
二者连接以后:
理论对象
↓
数据对象
↓
Matching Algorithm
↓
Matching Result
进一步:
Object
↓
Data Object
↓
Method
↓
Matching
↓
Result
于是 WSaiOS 开始形成真正的:
对象
+
数据
+
方法
+
计算
闭环。
59.19 核心定义
第59章可以最终形成三个定义。
定义一:Matching
Matching 是认知系统判断两个或多个认知对象之间符合程度与关系的理论过程。
定义二:Matching Rule
Matching Rule 是将匹配理论转化为可判断条件的规则集合。
定义三:Matching Algorithm
Matching Algorithm 是按照匹配规则,对数据对象进行比较、计算和评价,并产生匹配结果的工程方法。
因此:
Matching
=
理论
Matching Rule
=
规则
Matching Algorithm
=
方法
Matching Result
=
结果
最终形成:
理论层
│
Matching
│
↓
规则层
│
Matching Rule
│
↓
方法层
│
Matching Algorithm
│
↓
数据层
│
Data Objects
│
↓
结果层
│
Matching Result
这意味着 Matching 不再只是“相似度计算”,而成为 WSaiOS 中从认知关系 → 规则 → 工程方法 → 数据计算 → 认知结果的一条完整执行链。