@skaterqiang/protege-js 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -0
- package/LICENSE +48 -0
- package/README.md +287 -0
- package/docs/API.md +654 -0
- package/docs/design/OWL2-/347/274/272/345/217/243/345/210/206/346/236/220.md +140 -0
- package/docs/owl2-rl/OWL2-RL-/350/247/204/345/210/231/347/273/206/345/210/231.md +168 -0
- package/docs/owl2-rl/owl2-profiles-spec-zh.html +1914 -0
- package/docs/owl2-rl/owl2-profiles-spec.html +1916 -0
- package/docs/owl2-rl/rl_rules.json +392 -0
- package/main.js +46 -0
- package/package.json +76 -0
- package/sample/README.md +74 -0
- package/sample/case1-ecommerce-risk.js +170 -0
- package/sample/case10-ecommerce-customer-service.js +454 -0
- package/sample/case2-family-swrl.js +147 -0
- package/sample/case3-pharma-safety.js +132 -0
- package/sample/case4-knowledge-publishing.js +111 -0
- package/sample/case5-obda-profiles.js +153 -0
- package/sample/case6-medical-ontology.js +152 -0
- package/sample/case7-manufacturing-ppr.js +155 -0
- package/sample/case8-real-medical-bfo-ogms.js +353 -0
- package/sample/case9-real-manufacturing-iao.js +360 -0
- package/sample/ontologies/bfo.owl +1715 -0
- package/sample/ontologies/iao.owl +8532 -0
- package/sample/ontologies/ogms.owl +4320 -0
- package/sample/ontologies/ro-core.owl +1010 -0
- package/scripts/verify-api.js +53 -0
- package/src/index.js +176 -0
- package/src/inference/OWL2ProfileReasoners.js +67 -0
- package/src/inference/OWL2RLReasoner.js +65 -0
- package/src/inference/ReasonerQueries.js +111 -0
- package/src/inference/SWRLReasoner.js +409 -0
- package/src/inference/TripleStore.js +82 -0
- package/src/inference/rdf.js +83 -0
- package/src/inference/rules/owl2el.js +33 -0
- package/src/inference/rules/owl2ql.js +29 -0
- package/src/inference/rules/owl2rl.js +823 -0
- package/src/io/FunctionalSyntaxParser.js +399 -0
- package/src/io/FunctionalSyntaxWriter.js +180 -0
- package/src/io/ManchesterSyntaxParser.js +398 -0
- package/src/io/OWLXMLParser.js +356 -0
- package/src/io/OntologyLoader.js +125 -0
- package/src/io/RDFGraphToOntology.js +702 -0
- package/src/io/RDFXMLParser.js +319 -0
- package/src/io/RDFXMLWriter.js +196 -0
- package/src/io/SWRLParser.js +150 -0
- package/src/io/TurtleParser.js +363 -0
- package/src/io/TurtleWriter.js +393 -0
- package/src/model/IRI.js +62 -0
- package/src/model/OWLAxiom.js +507 -0
- package/src/model/OWLClassExpression.js +242 -0
- package/src/model/OWLEntity.js +142 -0
- package/src/model/OWLLiteral.js +30 -0
- package/src/model/OWLModelManager.js +106 -0
- package/src/model/OWLOntology.js +119 -0
- package/src/model/SWRL.js +152 -0
- package/src/model/event/OWLModelManagerEvent.js +33 -0
- package/src/model/hierarchy/HierarchyProvider.js +214 -0
- package/src/profiles/OWL2Profiles.js +185 -0
- package/src/server/public/app.js +97 -0
- package/src/server/public/index.html +49 -0
- package/src/server/webServer.js +138 -0
- package/src/validation/GlobalRestrictionsValidator.js +172 -0
- package/test/core.test.js +111 -0
- package/test/exports-map.test.js +165 -0
- package/test/owl2/axioms.test.js +160 -0
- package/test/owl2/classExpressions.test.js +99 -0
- package/test/owl2/functional-syntax-writer.test.js +65 -0
- package/test/owl2/functional.test.js +113 -0
- package/test/owl2/global-restrictions.test.js +76 -0
- package/test/owl2/longtail.test.js +74 -0
- package/test/owl2/manchester-syntax.test.js +100 -0
- package/test/owl2/ontology-loader-imports.test.js +62 -0
- package/test/owl2/owlxml-parser.test.js +112 -0
- package/test/owl2/profile-reasoners.test.js +108 -0
- package/test/owl2/profiles.test.js +66 -0
- package/test/owl2/rdf-graph-to-ontology.test.js +177 -0
- package/test/owl2/rdfxml-punning.test.js +25 -0
- package/test/owl2/rdfxml-writer.test.js +55 -0
- package/test/owl2/rdfxml.test.js +91 -0
- package/test/owl2/reasoner-queries.test.js +58 -0
- package/test/owl2/sample-e2e.test.js +195 -0
- package/test/owl2/swrl-parser.test.js +60 -0
- package/test/owl2/swrl.test.js +131 -0
- package/test/owl2/turtle-writer.test.js +84 -0
- package/test/owl2/turtle.test.js +124 -0
- package/test/owl2rl/cax.test.js +57 -0
- package/test/owl2rl/cls.test.js +210 -0
- package/test/owl2rl/dt.test.js +72 -0
- package/test/owl2rl/eq.test.js +95 -0
- package/test/owl2rl/prp.test.js +198 -0
- package/test/owl2rl/scm.test.js +203 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// ===========================================================================
|
|
4
|
+
// 业务案例 9:发动机缸体生产工艺执行与质量追溯 —— 真实 BFO + IAO + 工艺数据
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// 【业务背景】
|
|
7
|
+
// 某汽车零部件企业生产发动机缸体(EngineBlock),需要把「工艺路线 →
|
|
8
|
+
// 具体工序 → 设备/刀具/参数 → 质量检验 → 批记录」全流程数据挂到真实
|
|
9
|
+
// IAO 标准本体上,实现:
|
|
10
|
+
// 1. 工艺规程(IAO directive information entity)指导生产执行
|
|
11
|
+
// 2. 每道工序的加工参数(转速/进给/切削深度)实时采集
|
|
12
|
+
// 3. 质量检验结果与工艺参数关联,支持追溯分析
|
|
13
|
+
// 4. 批生产记录(IAO document)归档,供 MES/QMS 消费
|
|
14
|
+
//
|
|
15
|
+
// 【业务规则】
|
|
16
|
+
// 1. 产品层级:EngineBlock(发动机缸体)⊑ Product
|
|
17
|
+
// 2. 工艺路线:Casting(铸造)→ RoughMachining(粗加工)→
|
|
18
|
+
// FinishMachining(精加工)→ Cleaning(清洗)→ Assembly(装配)→ Testing(测试)
|
|
19
|
+
// 3. 工序与资源:RoughMachining requiresResource CNC-Machine + MillingCutter
|
|
20
|
+
// 4. 工艺参数:RoughMachining 的切削参数 = {spindleSpeed: 800rpm, feedRate: 200mm/min}
|
|
21
|
+
// 5. 质量检验:FinishMachining 后执行 DimensionInspection(尺寸检验)
|
|
22
|
+
// 6. 推理:批记录 BR-20240901-001 应沿 IAO 层级归因到
|
|
23
|
+
// directive information entity → information content entity → BFO GDC
|
|
24
|
+
//
|
|
25
|
+
// 【用到的 OWL 2 能力】
|
|
26
|
+
// 真实 IAO/BFO 类层级复用 / OWL 2 RL cax-sco 类层级归因 /
|
|
27
|
+
// owl:someValuesFrom(工序需要资源)/ writeRDFXML 导出批记录
|
|
28
|
+
//
|
|
29
|
+
// 【预期结果】
|
|
30
|
+
// - 缸体工艺路线各环节正确关联
|
|
31
|
+
// - 批记录实例沿真实 IAO 层级完整归因
|
|
32
|
+
// - 工艺参数与检验结果可追溯
|
|
33
|
+
// ===========================================================================
|
|
34
|
+
|
|
35
|
+
// 引入 Node 内置模块与解析器/序列化器/推理机
|
|
36
|
+
const fs = require('fs'); // 文件系统:读取本地 OWL 文件
|
|
37
|
+
const path = require('path'); // 路径处理:拼接 ontologies 目录
|
|
38
|
+
const { parseRDFXML } = require('../src/io/RDFXMLParser'); // RDF/XML 解析器:加载真实 OWL 文件
|
|
39
|
+
const { writeRDFXML } = require('../src/io/RDFXMLWriter'); // RDF/XML 序列化器:导出批记录
|
|
40
|
+
const { TurtleParser } = require('../src/io/TurtleParser'); // Turtle 解析器:解析工艺数据
|
|
41
|
+
const { triplesToOntology } = require('../src/io/RDFGraphToOntology'); // TripleStore → OWLOntology
|
|
42
|
+
const { TripleStore } = require('../src/inference/TripleStore'); // 三元组存储:合并真实+工艺
|
|
43
|
+
const { OWL2RLReasoner } = require('../src/inference/OWL2RLReasoner'); // OWL 2 RL 推理机:物化
|
|
44
|
+
const { NS } = require('../src/inference/rdf'); // 命名空间常量
|
|
45
|
+
|
|
46
|
+
// 简化命名空间引用
|
|
47
|
+
const RDF = NS.RDF, RDFS = NS.RDFS;
|
|
48
|
+
// 真实 OWL 文件所在目录:sample/ontologies/
|
|
49
|
+
const ONT_DIR = path.join(__dirname, 'ontologies');
|
|
50
|
+
// rdfs:label 完整 IRI(用于过滤 label 注解)
|
|
51
|
+
const RDFS_LABEL = RDFS + 'label';
|
|
52
|
+
// 真实标准类 IRI(来自 OBO Foundry IAO/BFO 发布文件)
|
|
53
|
+
const IAO_ICE = 'http://purl.obolibrary.org/obo/IAO_0000030'; // information content entity
|
|
54
|
+
const IAO_DIE = 'http://purl.obolibrary.org/obo/IAO_0000033'; // directive information entity
|
|
55
|
+
const IAO_DOC = 'http://purl.obolibrary.org/obo/IAO_0000310'; // document
|
|
56
|
+
const IAO_PLAN = 'http://purl.obolibrary.org/obo/IAO_0000104'; // plan specification
|
|
57
|
+
const BFO_GDC = 'http://purl.obolibrary.org/obo/BFO_0000031'; // generically dependent continuant
|
|
58
|
+
|
|
59
|
+
// 从实体/类表达式中取 IRI 字符串(模型中 iri 为 {_iri} 嵌套对象)
|
|
60
|
+
function iriOf(x) {
|
|
61
|
+
if (!x) return null; // 空值直接返回
|
|
62
|
+
if (typeof x === 'string') return x; // 已经是字符串 IRI
|
|
63
|
+
const i = x.iri; // 取嵌套的 iri 字段
|
|
64
|
+
if (typeof i === 'string') return i; // iri 本身是字符串
|
|
65
|
+
if (i && typeof i._iri === 'string') return i._iri; // iri 是 {_iri} 对象
|
|
66
|
+
if (typeof x._iri === 'string') return x._iri; // 兜底:x 本身是 {_iri} 对象
|
|
67
|
+
return null; // 无法提取
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 真实本体的类层级 + rdfs:label → IRI 映射
|
|
71
|
+
function extractOntologyFacts(onts) {
|
|
72
|
+
const store = new TripleStore(); // 存放类层级边
|
|
73
|
+
const label2iri = {}; // label 文本 → 类 IRI 映射
|
|
74
|
+
let edges = 0; // 统计层级边数
|
|
75
|
+
for (const ont of onts) { // 遍历每个本体
|
|
76
|
+
for (const ax of ont.getAxioms()) { // 遍历每条公理
|
|
77
|
+
const t = ax.constructor && ax.constructor.name; // 公理类型名
|
|
78
|
+
if (t === 'OWLSubClassOfAxiom') { // SubClassOf 公理
|
|
79
|
+
const sub = iriOf(ax.subClass); // 子类 IRI
|
|
80
|
+
const sup = iriOf(ax.superClass); // 父类 IRI
|
|
81
|
+
if (sub && sup && sub.startsWith('http') && sup.startsWith('http')) {
|
|
82
|
+
store.add(sub, RDFS + 'subClassOf', sup); // 写入 TripleStore
|
|
83
|
+
edges++; // 边数 +1
|
|
84
|
+
}
|
|
85
|
+
} else if (t === 'OWLAnnotationAssertionAxiom') { // 注解断言公理
|
|
86
|
+
const p = ax.property && iriOf(ax.property); // 注解属性 IRI
|
|
87
|
+
const s = typeof ax.subject === 'string' ? ax.subject : iriOf(ax.subject); // 主体 IRI
|
|
88
|
+
const v = ax.value && ax.value.lexicalValue; // label 文本
|
|
89
|
+
// 只保留 rdfs:label,且首次出现(避免同名 label 覆盖)
|
|
90
|
+
if (p === RDFS_LABEL && s && v && !(v in label2iri)) label2iri[v] = s;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return { store, label2iri, edges }; // 返回层级存储、label 映射、边数
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 发动机缸体生产工艺数据(挂到真实 IAO 标准父类)
|
|
98
|
+
function buildEngineBlockProcessTurtle() {
|
|
99
|
+
return [
|
|
100
|
+
'@prefix mfg: <http://factory.example.com/engineblock#> .', // 定义 mfg 前缀(发动机缸体产线)
|
|
101
|
+
'@prefix owl: <http://www.w3.org/2002/07/owl#> .', // 定义 owl 前缀
|
|
102
|
+
'@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .', // 定义 rdfs 前缀
|
|
103
|
+
'@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .', // 定义 xsd 前缀(数据类型)
|
|
104
|
+
'@prefix obo: <http://purl.obolibrary.org/obo/> .', // 定义 obo 前缀(OBO 标准 IRI)
|
|
105
|
+
'',
|
|
106
|
+
|
|
107
|
+
'# ========== 产品定义 ==========',
|
|
108
|
+
'mfg:EngineBlock a owl:Class ; rdfs:subClassOf mfg:Product .', // 发动机缸体 ⊑ 产品
|
|
109
|
+
'mfg:Product a owl:Class .', // 产品顶层类
|
|
110
|
+
'',
|
|
111
|
+
|
|
112
|
+
'# ========== 工艺路线(工序顺序) ==========',
|
|
113
|
+
'mfg:Casting a owl:Class ; rdfs:subClassOf mfg:Process .', // 铸造 ⊑ 工艺
|
|
114
|
+
'mfg:RoughMachining a owl:Class ; rdfs:subClassOf mfg:Process .', // 粗加工 ⊑ 工艺
|
|
115
|
+
'mfg:FinishMachining a owl:Class ; rdfs:subClassOf mfg:Process .', // 精加工 ⊑ 工艺
|
|
116
|
+
'mfg:Cleaning a owl:Class ; rdfs:subClassOf mfg:Process .', // 清洗 ⊑ 工艺
|
|
117
|
+
'mfg:Assembly a owl:Class ; rdfs:subClassOf mfg:Process .', // 装配 ⊑ 工艺
|
|
118
|
+
'mfg:Testing a owl:Class ; rdfs:subClassOf mfg:Process .', // 测试 ⊑ 工艺
|
|
119
|
+
'mfg:Process a owl:Class .', // 工艺顶层类
|
|
120
|
+
'mfg:precedes a owl:ObjectProperty , owl:TransitiveProperty .', // 工序顺序(传递)
|
|
121
|
+
'',
|
|
122
|
+
|
|
123
|
+
'# ========== 设备与资源 ==========',
|
|
124
|
+
'mfg:Equipment a owl:Class ; rdfs:subClassOf mfg:Resource .', // 设备 ⊑ 资源
|
|
125
|
+
'mfg:Tooling a owl:Class ; rdfs:subClassOf mfg:Resource .', // 刀具 ⊑ 资源
|
|
126
|
+
'mfg:Material a owl:Class ; rdfs:subClassOf mfg:Resource .', // 物料 ⊑ 资源
|
|
127
|
+
'mfg:Resource a owl:Class .', // 资源顶层类
|
|
128
|
+
'mfg:requiresResource a owl:ObjectProperty ; rdfs:domain mfg:Process ; rdfs:range mfg:Resource .', // 工艺→资源
|
|
129
|
+
'',
|
|
130
|
+
|
|
131
|
+
'# ========== 具体设备实例 ==========',
|
|
132
|
+
'mfg:CNC-Machine-001 a mfg:Equipment ; rdfs:label "数控加工中心-001" .', // 数控加工中心
|
|
133
|
+
'mfg:MillingCutter-D50 a mfg:Tooling ; rdfs:label "Φ50铣刀" .', // Φ50铣刀(局部名用ASCII兼容字符)
|
|
134
|
+
'mfg:DrillBit-D10 a mfg:Tooling ; rdfs:label "Φ10钻头" .', // Φ10钻头(局部名用ASCII兼容字符)
|
|
135
|
+
'mfg:CastIron-HT250 a mfg:Material ; rdfs:label "HT250铸铁毛坯" .', // HT250铸铁毛坯
|
|
136
|
+
'',
|
|
137
|
+
|
|
138
|
+
'# ========== 工艺参数定义 ==========',
|
|
139
|
+
'mfg:ProcessParameter a owl:Class .', // 工艺参数类
|
|
140
|
+
'mfg:hasParameter a owl:ObjectProperty ; rdfs:domain mfg:Process ; rdfs:range mfg:ProcessParameter .', // 工艺→参数
|
|
141
|
+
'mfg:spindleSpeed a owl:DatatypeProperty ; rdfs:domain mfg:ProcessParameter ; rdfs:range xsd:integer .', // 主轴转速(rpm)
|
|
142
|
+
'mfg:feedRate a owl:DatatypeProperty ; rdfs:domain mfg:ProcessParameter ; rdfs:range xsd:integer .', // 进给速度(mm/min)
|
|
143
|
+
'mfg:cuttingDepth a owl:DatatypeProperty ; rdfs:domain mfg:ProcessParameter ; rdfs:range xsd:decimal .', // 切削深度(mm)
|
|
144
|
+
'',
|
|
145
|
+
|
|
146
|
+
'# ========== 质量检验定义 ==========',
|
|
147
|
+
'mfg:QualityInspection a owl:Class ; rdfs:subClassOf mfg:Process .', // 质量检验 ⊑ 工艺
|
|
148
|
+
'mfg:DimensionInspection a owl:Class ; rdfs:subClassOf mfg:QualityInspection .', // 尺寸检验 ⊑ 质量检验
|
|
149
|
+
'mfg:SurfaceRoughnessInspection a owl:Class ; rdfs:subClassOf mfg:QualityInspection .', // 表面粗糙度检验 ⊑ 质量检验
|
|
150
|
+
'mfg:hasInspectionResult a owl:ObjectProperty ; rdfs:domain mfg:QualityInspection ; rdfs:range mfg:InspectionResult .', // 检验→结果
|
|
151
|
+
'mfg:InspectionResult a owl:Class .', // 检验结果类
|
|
152
|
+
'mfg:inspectionValue a owl:DatatypeProperty ; rdfs:domain mfg:InspectionResult ; rdfs:range xsd:decimal .', // 检验值
|
|
153
|
+
'mfg:inspectionUnit a owl:DatatypeProperty ; rdfs:domain mfg:InspectionResult ; rdfs:range xsd:string .', // 检验单位
|
|
154
|
+
'mfg:inspectionPass a owl:DatatypeProperty ; rdfs:domain mfg:InspectionResult ; rdfs:range xsd:boolean .', // 是否合格
|
|
155
|
+
'',
|
|
156
|
+
|
|
157
|
+
'# ========== 批生产记录(挂到真实 IAO 标准父类) ==========',
|
|
158
|
+
'mfg:BatchRecord a owl:Class ; rdfs:subClassOf obo:IAO_0000310 .', // 批生产记录 ⊑ document
|
|
159
|
+
'mfg:ProcessSpecification a owl:Class ; rdfs:subClassOf obo:IAO_0000033 .', // 工艺规程 ⊑ directive information entity
|
|
160
|
+
'mfg:OperationInstruction a owl:Class ; rdfs:subClassOf obo:IAO_0000104 .', // 作业指导书 ⊑ plan specification
|
|
161
|
+
'',
|
|
162
|
+
|
|
163
|
+
'# ========== 具体实例:发动机缸体 EB-2024-001 的生产工艺 ==========',
|
|
164
|
+
'# 产品实例',
|
|
165
|
+
'mfg:EB-2024-001 a mfg:EngineBlock ; rdfs:label "发动机缸体-2024-001" .',
|
|
166
|
+
'',
|
|
167
|
+
'# 铸造工序',
|
|
168
|
+
'mfg:Casting-EB001 a mfg:Casting ;', // 铸造工序实例
|
|
169
|
+
' mfg:requiresResource mfg:CastIron-HT250 ;', // 需要 HT250 铸铁毛坯
|
|
170
|
+
' mfg:precedes mfg:RoughMachining-EB001 .', // 铸造 → 粗加工
|
|
171
|
+
'',
|
|
172
|
+
'# 粗加工工序(含工艺参数)',
|
|
173
|
+
'mfg:RoughMachining-EB001 a mfg:RoughMachining ;', // 粗加工工序实例
|
|
174
|
+
' mfg:requiresResource mfg:CNC-Machine-001 ;', // 需要数控加工中心
|
|
175
|
+
' mfg:requiresResource mfg:MillingCutter-D50 ;', // 需要 Φ50 铣刀
|
|
176
|
+
' mfg:hasParameter mfg:RP-EB001 ;', // 关联工艺参数
|
|
177
|
+
' mfg:precedes mfg:FinishMachining-EB001 .', // 粗加工 → 精加工
|
|
178
|
+
'',
|
|
179
|
+
'# 粗加工工艺参数实例',
|
|
180
|
+
'mfg:RP-EB001 a mfg:ProcessParameter ;', // 工艺参数实例
|
|
181
|
+
' mfg:spindleSpeed "800"^^xsd:integer ;', // 主轴转速 800 rpm
|
|
182
|
+
' mfg:feedRate "200"^^xsd:integer ;', // 进给速度 200 mm/min
|
|
183
|
+
' mfg:cuttingDepth "2.5"^^xsd:decimal .', // 切削深度 2.5 mm
|
|
184
|
+
'',
|
|
185
|
+
'# 精加工工序',
|
|
186
|
+
'mfg:FinishMachining-EB001 a mfg:FinishMachining ;', // 精加工工序实例
|
|
187
|
+
' mfg:requiresResource mfg:CNC-Machine-001 ;', // 需要数控加工中心
|
|
188
|
+
' mfg:requiresResource mfg:DrillBit-D10 ;', // 需要 Φ10 钻头
|
|
189
|
+
' mfg:precedes mfg:Cleaning-EB001 .', // 精加工 → 清洗
|
|
190
|
+
'',
|
|
191
|
+
'# 清洗工序',
|
|
192
|
+
'mfg:Cleaning-EB001 a mfg:Cleaning ;', // 清洗工序实例
|
|
193
|
+
' mfg:precedes mfg:Assembly-EB001 .', // 清洗 → 装配
|
|
194
|
+
'',
|
|
195
|
+
'# 装配工序',
|
|
196
|
+
'mfg:Assembly-EB001 a mfg:Assembly ;', // 装配工序实例
|
|
197
|
+
' mfg:precedes mfg:Testing-EB001 .', // 装配 → 测试
|
|
198
|
+
'',
|
|
199
|
+
'# 测试工序(含质量检验)',
|
|
200
|
+
'mfg:Testing-EB001 a mfg:Testing ;', // 测试工序实例
|
|
201
|
+
' mfg:precedes mfg:DimInsp-EB001 .', // 测试 → 尺寸检验
|
|
202
|
+
'',
|
|
203
|
+
'# 尺寸检验工序',
|
|
204
|
+
'mfg:DimInsp-EB001 a mfg:DimensionInspection ;', // 尺寸检验实例
|
|
205
|
+
' mfg:hasInspectionResult mfg:IR-EB001 .', // 关联检验结果
|
|
206
|
+
'',
|
|
207
|
+
'# 检验结果实例',
|
|
208
|
+
'mfg:IR-EB001 a mfg:InspectionResult ;', // 检验结果实例
|
|
209
|
+
' mfg:inspectionValue "49.98"^^xsd:decimal ;', // 检验值 49.98
|
|
210
|
+
' mfg:inspectionUnit "mm" ;', // 单位 mm
|
|
211
|
+
' mfg:inspectionPass "true"^^xsd:boolean .', // 合格
|
|
212
|
+
'',
|
|
213
|
+
'# 批生产记录实例(关联整个工艺执行)',
|
|
214
|
+
'mfg:BR-20240901-001 a mfg:BatchRecord ;', // 批记录实例
|
|
215
|
+
' rdfs:label "发动机缸体EB-2024-001批生产记录-20240901" ;', // 批记录标签
|
|
216
|
+
' mfg:recordsProduct mfg:EB-2024-001 ;', // 记录的产品
|
|
217
|
+
' mfg:recordsProcess mfg:Casting-EB001 ;', // 记录的铸造工序
|
|
218
|
+
' mfg:recordsProcess mfg:RoughMachining-EB001 ;', // 记录的粗加工工序
|
|
219
|
+
' mfg:recordsProcess mfg:FinishMachining-EB001 ;', // 记录的精加工工序
|
|
220
|
+
' mfg:recordsProcess mfg:Testing-EB001 ;', // 记录的测试工序
|
|
221
|
+
' mfg:recordsInspection mfg:DimInsp-EB001 .', // 记录的检验工序
|
|
222
|
+
'',
|
|
223
|
+
'# 批记录与产品/工序的关联属性',
|
|
224
|
+
'mfg:recordsProduct a owl:ObjectProperty ; rdfs:domain mfg:BatchRecord ; rdfs:range mfg:Product .', // 批记录→产品
|
|
225
|
+
'mfg:recordsProcess a owl:ObjectProperty ; rdfs:domain mfg:BatchRecord ; rdfs:range mfg:Process .', // 批记录→工艺
|
|
226
|
+
'mfg:recordsInspection a owl:ObjectProperty ; rdfs:domain mfg:BatchRecord ; rdfs:range mfg:QualityInspection .', // 批记录→检验
|
|
227
|
+
''
|
|
228
|
+
].join('\n');
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// 执行真实本体加载、工艺数据合并、RL 推理与导出
|
|
232
|
+
function run() {
|
|
233
|
+
// 1) 加载真实公开本体
|
|
234
|
+
const bfo = parseRDFXML(fs.readFileSync(path.join(ONT_DIR, 'bfo.owl'), 'utf8')); // BFO 顶层本体
|
|
235
|
+
const iao = parseRDFXML(fs.readFileSync(path.join(ONT_DIR, 'iao.owl'), 'utf8')); // IAO 信息构件本体
|
|
236
|
+
const counts = { bfo: bfo.getAxiomCount(), iao: iao.getAxiomCount() }; // 统计公理数
|
|
237
|
+
|
|
238
|
+
// 2) 提取真实类层级 + label 映射;校验 IAO 标准类
|
|
239
|
+
const { store, label2iri, edges } = extractOntologyFacts([bfo, iao]);
|
|
240
|
+
const iaoStdClasses = {
|
|
241
|
+
'information content entity': label2iri['information content entity'] || null,
|
|
242
|
+
'directive information entity': label2iri['directive information entity'] || null,
|
|
243
|
+
'document': label2iri['document'] || null,
|
|
244
|
+
'plan specification': label2iri['plan specification'] || null,
|
|
245
|
+
'generically dependent continuant': label2iri['generically dependent continuant'] || null
|
|
246
|
+
};
|
|
247
|
+
const hasStdClasses =
|
|
248
|
+
iaoStdClasses['directive information entity'] === IAO_DIE &&
|
|
249
|
+
iaoStdClasses['document'] === IAO_DOC &&
|
|
250
|
+
iaoStdClasses['plan specification'] === IAO_PLAN &&
|
|
251
|
+
iaoStdClasses['generically dependent continuant'] === BFO_GDC;
|
|
252
|
+
|
|
253
|
+
// 3) 真实层级 + 发动机缸体工艺数据合并 → RL 物化
|
|
254
|
+
// TripleStore.match 返回三元组数组 [subject, predicate, object]
|
|
255
|
+
const mfgStore = new TurtleParser().parse(buildEngineBlockProcessTurtle()); // 解析工艺数据 Turtle
|
|
256
|
+
for (const [s, p, o] of mfgStore.match(null, null, null)) { // 遍历工艺数据三元组
|
|
257
|
+
store.add(s, p, o); // 合并到真实本体 store
|
|
258
|
+
}
|
|
259
|
+
const reasoner = new OWL2RLReasoner(store);
|
|
260
|
+
reasoner.materialize(); // 执行 RL 物化
|
|
261
|
+
|
|
262
|
+
// 4) 批记录 IAO 层级归因验证
|
|
263
|
+
const BR = 'http://factory.example.com/engineblock#BR-20240901-001'; // 批记录实例 IRI
|
|
264
|
+
const m = 'http://factory.example.com/engineblock#'; // 企业前缀
|
|
265
|
+
const isBatchRecord = store.has(BR, RDF + 'type', m + 'BatchRecord'); // 归为 BatchRecord
|
|
266
|
+
const isDoc = store.has(BR, RDF + 'type', IAO_DOC); // 归为 document(IAO_0000310)
|
|
267
|
+
const isICE = store.has(BR, RDF + 'type', IAO_ICE); // 归为 information content entity
|
|
268
|
+
const isGDC = store.has(BR, RDF + 'type', BFO_GDC); // 归为 BFO generically dependent continuant
|
|
269
|
+
const attributed = isBatchRecord && isDoc && isICE && isGDC; // 完整归因链(BatchRecord⊑document⊑ICE⊑GDC)
|
|
270
|
+
|
|
271
|
+
// 5) 工艺执行与质量追溯验证
|
|
272
|
+
const eb = 'http://factory.example.com/engineblock#EB-2024-001'; // 发动机缸体实例
|
|
273
|
+
const isEngineBlock = store.has(eb, RDF + 'type', m + 'EngineBlock'); // 归为 EngineBlock
|
|
274
|
+
const isProduct = store.has(eb, RDF + 'type', m + 'Product'); // 归为 Product
|
|
275
|
+
|
|
276
|
+
// 工艺顺序传递验证:铸造 precedes 精加工(经由粗加工)
|
|
277
|
+
const castingPrecedesFinish = store.has(
|
|
278
|
+
'http://factory.example.com/engineblock#Casting-EB001',
|
|
279
|
+
m + 'precedes',
|
|
280
|
+
'http://factory.example.com/engineblock#FinishMachining-EB001'
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
// 粗加工资源关联验证
|
|
284
|
+
const roughMachining = 'http://factory.example.com/engineblock#RoughMachining-EB001';
|
|
285
|
+
const requiresCNC = store.has(roughMachining, m + 'requiresResource', m + 'CNC-Machine-001'); // 需要数控加工中心
|
|
286
|
+
const requiresCutter = store.has(roughMachining, m + 'requiresResource', m + 'MillingCutter-D50'); // 需要 Φ50 铣刀
|
|
287
|
+
|
|
288
|
+
// 工艺参数关联验证
|
|
289
|
+
const hasParameter = store.has(roughMachining, m + 'hasParameter', m + 'RP-EB001'); // 粗加工关联参数
|
|
290
|
+
const paramSpeed = store.has(m + 'RP-EB001', m + 'spindleSpeed', '"800"^^<http://www.w3.org/2001/XMLSchema#integer>'); // 转速 800
|
|
291
|
+
|
|
292
|
+
// 质量检验关联验证
|
|
293
|
+
const dimInsp = 'http://factory.example.com/engineblock#DimInsp-EB001';
|
|
294
|
+
const hasInspectionResult = store.has(dimInsp, m + 'hasInspectionResult', m + 'IR-EB001'); // 检验关联结果
|
|
295
|
+
const inspectionPass = store.has(m + 'IR-EB001', m + 'inspectionPass', '"true"^^<http://www.w3.org/2001/XMLSchema#boolean>'); // 检验合格
|
|
296
|
+
|
|
297
|
+
// 批记录追溯验证
|
|
298
|
+
const recordsProduct = store.has(BR, m + 'recordsProduct', eb); // 批记录关联产品
|
|
299
|
+
const recordsRoughMachining = store.has(BR, m + 'recordsProcess', roughMachining); // 批记录关联粗加工
|
|
300
|
+
|
|
301
|
+
const consistent = reasoner.isConsistent(); // 本体一致性
|
|
302
|
+
|
|
303
|
+
// 6) 导出批记录本体为 RDF/XML
|
|
304
|
+
const mfgOnt = triplesToOntology(new TurtleParser().parse(buildEngineBlockProcessTurtle())); // 桥接为 OWLOntology
|
|
305
|
+
const xmlOut = writeRDFXML(mfgOnt); // 导出 RDF/XML
|
|
306
|
+
const exported = xmlOut.trim().startsWith('<?xml'); // 是合法 XML
|
|
307
|
+
|
|
308
|
+
return {
|
|
309
|
+
counts, edges, iaoStdClasses, hasStdClasses,
|
|
310
|
+
isBatchRecord, isDoc, isICE, isGDC, attributed,
|
|
311
|
+
isEngineBlock, isProduct,
|
|
312
|
+
castingPrecedesFinish,
|
|
313
|
+
requiresCNC, requiresCutter,
|
|
314
|
+
hasParameter, paramSpeed,
|
|
315
|
+
hasInspectionResult, inspectionPass,
|
|
316
|
+
recordsProduct, recordsRoughMachining,
|
|
317
|
+
consistent, exported
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// 导出供测试与复用
|
|
322
|
+
module.exports = { run };
|
|
323
|
+
|
|
324
|
+
// 直接运行时打印业务结论
|
|
325
|
+
if (require.main === module) {
|
|
326
|
+
const r = run();
|
|
327
|
+
console.log('================ 真实标准本体加载 ================');
|
|
328
|
+
console.log('BFO 公理数 :', r.counts.bfo); // > 0
|
|
329
|
+
console.log('IAO 公理数 :', r.counts.iao); // > 0
|
|
330
|
+
console.log('真实类层级边数 :', r.edges); // > 100
|
|
331
|
+
console.log('含全部 IAO 工艺标准类 :', r.hasStdClasses); // true
|
|
332
|
+
console.log('');
|
|
333
|
+
console.log('================ 批记录 IAO 层级归因 ================');
|
|
334
|
+
console.log('批记录归为 BatchRecord :', r.isBatchRecord); // true
|
|
335
|
+
console.log(' → document :', r.isDoc); // true
|
|
336
|
+
console.log(' → information content entity :', r.isICE); // true
|
|
337
|
+
console.log(' → BFO generically dependent cont:', r.isGDC); // true
|
|
338
|
+
console.log('沿真实 IAO 层级完整归因 :', r.attributed); // true
|
|
339
|
+
console.log('');
|
|
340
|
+
console.log('================ 产品与工艺执行 ================');
|
|
341
|
+
console.log('EB-2024-001 归为 EngineBlock :', r.isEngineBlock); // true
|
|
342
|
+
console.log('EB-2024-001 归为 Product :', r.isProduct); // true
|
|
343
|
+
console.log('铸造 precedes 精加工(传递) :', r.castingPrecedesFinish); // true
|
|
344
|
+
console.log('粗加工需要数控加工中心 :', r.requiresCNC); // true
|
|
345
|
+
console.log('粗加工需要Φ50铣刀 :', r.requiresCutter); // true
|
|
346
|
+
console.log('');
|
|
347
|
+
console.log('================ 工艺参数与质量追溯 ================');
|
|
348
|
+
console.log('粗加工关联工艺参数 :', r.hasParameter); // true
|
|
349
|
+
console.log('参数:主轴转速800rpm :', r.paramSpeed); // true
|
|
350
|
+
console.log('尺寸检验关联检验结果 :', r.hasInspectionResult); // true
|
|
351
|
+
console.log('检验结果:合格 :', r.inspectionPass); // true
|
|
352
|
+
console.log('');
|
|
353
|
+
console.log('================ 批记录追溯 ================');
|
|
354
|
+
console.log('批记录关联产品EB-2024-001 :', r.recordsProduct); // true
|
|
355
|
+
console.log('批记录关联粗加工工序 :', r.recordsRoughMachining); // true
|
|
356
|
+
console.log('');
|
|
357
|
+
console.log('================ 一致性与导出 ================');
|
|
358
|
+
console.log('本体一致性 :', r.consistent); // true
|
|
359
|
+
console.log('扩展本体可导出为 RDF/XML :', r.exported); // true
|
|
360
|
+
}
|