@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.
Files changed (92) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/LICENSE +48 -0
  3. package/README.md +287 -0
  4. package/docs/API.md +654 -0
  5. package/docs/design/OWL2-/347/274/272/345/217/243/345/210/206/346/236/220.md +140 -0
  6. package/docs/owl2-rl/OWL2-RL-/350/247/204/345/210/231/347/273/206/345/210/231.md +168 -0
  7. package/docs/owl2-rl/owl2-profiles-spec-zh.html +1914 -0
  8. package/docs/owl2-rl/owl2-profiles-spec.html +1916 -0
  9. package/docs/owl2-rl/rl_rules.json +392 -0
  10. package/main.js +46 -0
  11. package/package.json +76 -0
  12. package/sample/README.md +74 -0
  13. package/sample/case1-ecommerce-risk.js +170 -0
  14. package/sample/case10-ecommerce-customer-service.js +454 -0
  15. package/sample/case2-family-swrl.js +147 -0
  16. package/sample/case3-pharma-safety.js +132 -0
  17. package/sample/case4-knowledge-publishing.js +111 -0
  18. package/sample/case5-obda-profiles.js +153 -0
  19. package/sample/case6-medical-ontology.js +152 -0
  20. package/sample/case7-manufacturing-ppr.js +155 -0
  21. package/sample/case8-real-medical-bfo-ogms.js +353 -0
  22. package/sample/case9-real-manufacturing-iao.js +360 -0
  23. package/sample/ontologies/bfo.owl +1715 -0
  24. package/sample/ontologies/iao.owl +8532 -0
  25. package/sample/ontologies/ogms.owl +4320 -0
  26. package/sample/ontologies/ro-core.owl +1010 -0
  27. package/scripts/verify-api.js +53 -0
  28. package/src/index.js +176 -0
  29. package/src/inference/OWL2ProfileReasoners.js +67 -0
  30. package/src/inference/OWL2RLReasoner.js +65 -0
  31. package/src/inference/ReasonerQueries.js +111 -0
  32. package/src/inference/SWRLReasoner.js +409 -0
  33. package/src/inference/TripleStore.js +82 -0
  34. package/src/inference/rdf.js +83 -0
  35. package/src/inference/rules/owl2el.js +33 -0
  36. package/src/inference/rules/owl2ql.js +29 -0
  37. package/src/inference/rules/owl2rl.js +823 -0
  38. package/src/io/FunctionalSyntaxParser.js +399 -0
  39. package/src/io/FunctionalSyntaxWriter.js +180 -0
  40. package/src/io/ManchesterSyntaxParser.js +398 -0
  41. package/src/io/OWLXMLParser.js +356 -0
  42. package/src/io/OntologyLoader.js +125 -0
  43. package/src/io/RDFGraphToOntology.js +702 -0
  44. package/src/io/RDFXMLParser.js +319 -0
  45. package/src/io/RDFXMLWriter.js +196 -0
  46. package/src/io/SWRLParser.js +150 -0
  47. package/src/io/TurtleParser.js +363 -0
  48. package/src/io/TurtleWriter.js +393 -0
  49. package/src/model/IRI.js +62 -0
  50. package/src/model/OWLAxiom.js +507 -0
  51. package/src/model/OWLClassExpression.js +242 -0
  52. package/src/model/OWLEntity.js +142 -0
  53. package/src/model/OWLLiteral.js +30 -0
  54. package/src/model/OWLModelManager.js +106 -0
  55. package/src/model/OWLOntology.js +119 -0
  56. package/src/model/SWRL.js +152 -0
  57. package/src/model/event/OWLModelManagerEvent.js +33 -0
  58. package/src/model/hierarchy/HierarchyProvider.js +214 -0
  59. package/src/profiles/OWL2Profiles.js +185 -0
  60. package/src/server/public/app.js +97 -0
  61. package/src/server/public/index.html +49 -0
  62. package/src/server/webServer.js +138 -0
  63. package/src/validation/GlobalRestrictionsValidator.js +172 -0
  64. package/test/core.test.js +111 -0
  65. package/test/exports-map.test.js +165 -0
  66. package/test/owl2/axioms.test.js +160 -0
  67. package/test/owl2/classExpressions.test.js +99 -0
  68. package/test/owl2/functional-syntax-writer.test.js +65 -0
  69. package/test/owl2/functional.test.js +113 -0
  70. package/test/owl2/global-restrictions.test.js +76 -0
  71. package/test/owl2/longtail.test.js +74 -0
  72. package/test/owl2/manchester-syntax.test.js +100 -0
  73. package/test/owl2/ontology-loader-imports.test.js +62 -0
  74. package/test/owl2/owlxml-parser.test.js +112 -0
  75. package/test/owl2/profile-reasoners.test.js +108 -0
  76. package/test/owl2/profiles.test.js +66 -0
  77. package/test/owl2/rdf-graph-to-ontology.test.js +177 -0
  78. package/test/owl2/rdfxml-punning.test.js +25 -0
  79. package/test/owl2/rdfxml-writer.test.js +55 -0
  80. package/test/owl2/rdfxml.test.js +91 -0
  81. package/test/owl2/reasoner-queries.test.js +58 -0
  82. package/test/owl2/sample-e2e.test.js +195 -0
  83. package/test/owl2/swrl-parser.test.js +60 -0
  84. package/test/owl2/swrl.test.js +131 -0
  85. package/test/owl2/turtle-writer.test.js +84 -0
  86. package/test/owl2/turtle.test.js +124 -0
  87. package/test/owl2rl/cax.test.js +57 -0
  88. package/test/owl2rl/cls.test.js +210 -0
  89. package/test/owl2rl/dt.test.js +72 -0
  90. package/test/owl2rl/eq.test.js +95 -0
  91. package/test/owl2rl/prp.test.js +198 -0
  92. package/test/owl2rl/scm.test.js +203 -0
@@ -0,0 +1,392 @@
1
+ [
2
+ {
3
+ "id": "eq-ref",
4
+ "if": "T(?s, ?p, ?o)",
5
+ "then": "T(?s, owl:sameAs, ?s)\nT(?p, owl:sameAs, ?p)\nT(?o, owl:sameAs, ?o)"
6
+ },
7
+ {
8
+ "id": "eq-sym",
9
+ "if": "T(?x, owl:sameAs, ?y)",
10
+ "then": "T(?y, owl:sameAs, ?x)"
11
+ },
12
+ {
13
+ "id": "eq-trans",
14
+ "if": "T(?x, owl:sameAs, ?y)\nT(?y, owl:sameAs, ?z)",
15
+ "then": "T(?x, owl:sameAs, ?z)"
16
+ },
17
+ {
18
+ "id": "eq-rep-s",
19
+ "if": "T(?s, owl:sameAs, ?s')\nT(?s, ?p, ?o)",
20
+ "then": "T(?s', ?p, ?o)"
21
+ },
22
+ {
23
+ "id": "eq-rep-p",
24
+ "if": "T(?p, owl:sameAs, ?p')\nT(?s, ?p, ?o)",
25
+ "then": "T(?s, ?p', ?o)"
26
+ },
27
+ {
28
+ "id": "eq-rep-o",
29
+ "if": "T(?o, owl:sameAs, ?o')\nT(?s, ?p, ?o)",
30
+ "then": "T(?s, ?p, ?o')"
31
+ },
32
+ {
33
+ "id": "eq-diff1",
34
+ "if": "T(?x, owl:sameAs, ?y)\nT(?x, owl:differentFrom, ?y)",
35
+ "then": "false"
36
+ },
37
+ {
38
+ "id": "eq-diff2",
39
+ "if": "T(?x, rdf:type, owl:AllDifferent)\nT(?x, owl:members, ?y)\nLIST[?y, ?z1, ..., ?zn]\nT(?zi, owl:sameAs, ?zj)",
40
+ "then": "false"
41
+ },
42
+ {
43
+ "id": "eq-diff3",
44
+ "if": "T(?x, rdf:type, owl:AllDifferent)\nT(?x, owl:distinctMembers, ?y)\nLIST[?y, ?z1, ..., ?zn]\nT(?zi, owl:sameAs, ?zj)",
45
+ "then": "false"
46
+ },
47
+ {
48
+ "id": "prp-ap",
49
+ "if": "",
50
+ "then": "T(ap, rdf:type, owl:AnnotationProperty)"
51
+ },
52
+ {
53
+ "id": "prp-dom",
54
+ "if": "T(?p, rdfs:domain, ?c)\nT(?x, ?p, ?y)",
55
+ "then": "T(?x, rdf:type, ?c)"
56
+ },
57
+ {
58
+ "id": "prp-rng",
59
+ "if": "T(?p, rdfs:range, ?c)\nT(?x, ?p, ?y)",
60
+ "then": "T(?y, rdf:type, ?c)"
61
+ },
62
+ {
63
+ "id": "prp-fp",
64
+ "if": "T(?p, rdf:type, owl:FunctionalProperty)\nT(?x, ?p, ?y1)\nT(?x, ?p, ?y2)",
65
+ "then": "T(?y1, owl:sameAs, ?y2)"
66
+ },
67
+ {
68
+ "id": "prp-ifp",
69
+ "if": "T(?p, rdf:type, owl:InverseFunctionalProperty)\nT(?x1, ?p, ?y)\nT(?x2, ?p, ?y)",
70
+ "then": "T(?x1, owl:sameAs, ?x2)"
71
+ },
72
+ {
73
+ "id": "prp-irp",
74
+ "if": "T(?p, rdf:type, owl:IrreflexiveProperty)\nT(?x, ?p, ?x)",
75
+ "then": "false"
76
+ },
77
+ {
78
+ "id": "prp-symp",
79
+ "if": "T(?p, rdf:type, owl:SymmetricProperty)\nT(?x, ?p, ?y)",
80
+ "then": "T(?y, ?p, ?x)"
81
+ },
82
+ {
83
+ "id": "prp-asyp",
84
+ "if": "T(?p, rdf:type, owl:AsymmetricProperty)\nT(?x, ?p, ?y)\nT(?y, ?p, ?x)",
85
+ "then": "false"
86
+ },
87
+ {
88
+ "id": "prp-trp",
89
+ "if": "T(?p, rdf:type, owl:TransitiveProperty)\nT(?x, ?p, ?y)\nT(?y, ?p, ?z)",
90
+ "then": "T(?x, ?p, ?z)"
91
+ },
92
+ {
93
+ "id": "prp-spo1",
94
+ "if": "T(?p1, rdfs:subPropertyOf, ?p2)\nT(?x, ?p1, ?y)",
95
+ "then": "T(?x, ?p2, ?y)"
96
+ },
97
+ {
98
+ "id": "prp-spo2",
99
+ "if": "T(?p, owl:propertyChainAxiom, ?x)\nLIST[?x, ?p1, ..., ?pn]\nT(?u1, ?p1, ?u2)\nT(?u2, ?p2, ?u3)\n...\nT(?un, ?pn, ?un+1)",
100
+ "then": "T(?u1, ?p, ?un+1)"
101
+ },
102
+ {
103
+ "id": "prp-eqp1",
104
+ "if": "T(?p1, owl:equivalentProperty, ?p2)\nT(?x, ?p1, ?y)",
105
+ "then": "T(?x, ?p2, ?y)"
106
+ },
107
+ {
108
+ "id": "prp-eqp2",
109
+ "if": "T(?p1, owl:equivalentProperty, ?p2)\nT(?x, ?p2, ?y)",
110
+ "then": "T(?x, ?p1, ?y)"
111
+ },
112
+ {
113
+ "id": "prp-pdw",
114
+ "if": "T(?p1, owl:propertyDisjointWith, ?p2)\nT(?x, ?p1, ?y)\nT(?x, ?p2, ?y)",
115
+ "then": "false"
116
+ },
117
+ {
118
+ "id": "prp-adp",
119
+ "if": "T(?x, rdf:type, owl:AllDisjointProperties)\nT(?x, owl:members, ?y)\nLIST[?y, ?p1, ..., ?pn]\nT(?u, ?pi, ?v)\nT(?u, ?pj, ?v)",
120
+ "then": "false"
121
+ },
122
+ {
123
+ "id": "prp-inv1",
124
+ "if": "T(?p1, owl:inverseOf, ?p2)\nT(?x, ?p1, ?y)",
125
+ "then": "T(?y, ?p2, ?x)"
126
+ },
127
+ {
128
+ "id": "prp-inv2",
129
+ "if": "T(?p1, owl:inverseOf, ?p2)\nT(?x, ?p2, ?y)",
130
+ "then": "T(?y, ?p1, ?x)"
131
+ },
132
+ {
133
+ "id": "prp-key",
134
+ "if": "T(?c, owl:hasKey, ?u)\nLIST[?u, ?p1, ..., ?pn]\nT(?x, rdf:type, ?c)\nT(?x, ?p1, ?z1)\n...\nT(?x, ?pn, ?zn)\nT(?y, rdf:type, ?c)\nT(?y, ?p1, ?z1)\n...\nT(?y, ?pn, ?zn)",
135
+ "then": "T(?x, owl:sameAs, ?y)"
136
+ },
137
+ {
138
+ "id": "prp-npa1",
139
+ "if": "T(?x, owl:sourceIndividual, ?i1)\nT(?x, owl:assertionProperty, ?p)\nT(?x, owl:targetIndividual, ?i2)\nT(?i1, ?p, ?i2)",
140
+ "then": "false"
141
+ },
142
+ {
143
+ "id": "prp-npa2",
144
+ "if": "T(?x, owl:sourceIndividual, ?i)\nT(?x, owl:assertionProperty, ?p)\nT(?x, owl:targetValue, ?lt)\nT(?i, ?p, ?lt)",
145
+ "then": "false"
146
+ },
147
+ {
148
+ "id": "cls-thing",
149
+ "if": "",
150
+ "then": "T(owl:Thing, rdf:type, owl:Class)"
151
+ },
152
+ {
153
+ "id": "cls-nothing1",
154
+ "if": "",
155
+ "then": "T(owl:Nothing, rdf:type, owl:Class)"
156
+ },
157
+ {
158
+ "id": "cls-nothing2",
159
+ "if": "T(?x, rdf:type, owl:Nothing)",
160
+ "then": "false"
161
+ },
162
+ {
163
+ "id": "cls-int1",
164
+ "if": "T(?c, owl:intersectionOf, ?x)\nLIST[?x, ?c1, ..., ?cn]\nT(?y, rdf:type, ?c1)\nT(?y, rdf:type, ?c2)\n...\nT(?y, rdf:type, ?cn)",
165
+ "then": "T(?y, rdf:type, ?c)"
166
+ },
167
+ {
168
+ "id": "cls-int2",
169
+ "if": "T(?c, owl:intersectionOf, ?x)\nLIST[?x, ?c1, ..., ?cn]\nT(?y, rdf:type, ?c)",
170
+ "then": "T(?y, rdf:type, ?c1)\nT(?y, rdf:type, ?c2)\n...\nT(?y, rdf:type, ?cn)"
171
+ },
172
+ {
173
+ "id": "cls-uni",
174
+ "if": "T(?c, owl:unionOf, ?x)\nLIST[?x, ?c1, ..., ?cn]\nT(?y, rdf:type, ?ci)",
175
+ "then": "T(?y, rdf:type, ?c)"
176
+ },
177
+ {
178
+ "id": "cls-com",
179
+ "if": "T(?c1, owl:complementOf, ?c2)\nT(?x, rdf:type, ?c1)\nT(?x, rdf:type, ?c2)",
180
+ "then": "false"
181
+ },
182
+ {
183
+ "id": "cls-svf1",
184
+ "if": "T(?x, owl:someValuesFrom, ?y)\nT(?x, owl:onProperty, ?p)\nT(?u, ?p, ?v)\nT(?v, rdf:type, ?y)",
185
+ "then": "T(?u, rdf:type, ?x)"
186
+ },
187
+ {
188
+ "id": "cls-svf2",
189
+ "if": "T(?x, owl:someValuesFrom, owl:Thing)\nT(?x, owl:onProperty, ?p)\nT(?u, ?p, ?v)",
190
+ "then": "T(?u, rdf:type, ?x)"
191
+ },
192
+ {
193
+ "id": "cls-avf",
194
+ "if": "T(?x, owl:allValuesFrom, ?y)\nT(?x, owl:onProperty, ?p)\nT(?u, rdf:type, ?x)\nT(?u, ?p, ?v)",
195
+ "then": "T(?v, rdf:type, ?y)"
196
+ },
197
+ {
198
+ "id": "cls-hv1",
199
+ "if": "T(?x, owl:hasValue, ?y)\nT(?x, owl:onProperty, ?p)\nT(?u, rdf:type, ?x)",
200
+ "then": "T(?u, ?p, ?y)"
201
+ },
202
+ {
203
+ "id": "cls-hv2",
204
+ "if": "T(?x, owl:hasValue, ?y)\nT(?x, owl:onProperty, ?p)\nT(?u, ?p, ?y)",
205
+ "then": "T(?u, rdf:type, ?x)"
206
+ },
207
+ {
208
+ "id": "cls-maxc1",
209
+ "if": "T(?x, owl:maxCardinality, \"0\"^^xsd:nonNegativeInteger)\nT(?x, owl:onProperty, ?p)\nT(?u, rdf:type, ?x)\nT(?u, ?p, ?y)",
210
+ "then": "false"
211
+ },
212
+ {
213
+ "id": "cls-maxc2",
214
+ "if": "T(?x, owl:maxCardinality, \"1\"^^xsd:nonNegativeInteger)\nT(?x, owl:onProperty, ?p)\nT(?u, rdf:type, ?x)\nT(?u, ?p, ?y1)\nT(?u, ?p, ?y2)",
215
+ "then": "T(?y1, owl:sameAs, ?y2)"
216
+ },
217
+ {
218
+ "id": "cls-maxqc1",
219
+ "if": "T(?x, owl:maxQualifiedCardinality, \"0\"^^xsd:nonNegativeInteger)\nT(?x, owl:onProperty, ?p)\nT(?x, owl:onClass, ?c)\nT(?u, rdf:type, ?x)\nT(?u, ?p, ?y)\nT(?y, rdf:type, ?c)",
220
+ "then": "false"
221
+ },
222
+ {
223
+ "id": "cls-maxqc2",
224
+ "if": "T(?x, owl:maxQualifiedCardinality, \"0\"^^xsd:nonNegativeInteger)\nT(?x, owl:onProperty, ?p)\nT(?x, owl:onClass, owl:Thing)\nT(?u, rdf:type, ?x)\nT(?u, ?p, ?y)",
225
+ "then": "false"
226
+ },
227
+ {
228
+ "id": "cls-maxqc3",
229
+ "if": "T(?x, owl:maxQualifiedCardinality, \"1\"^^xsd:nonNegativeInteger)\nT(?x, owl:onProperty, ?p)\nT(?x, owl:onClass, ?c)\nT(?u, rdf:type, ?x)\nT(?u, ?p, ?y1)\nT(?y1, rdf:type, ?c)\nT(?u, ?p, ?y2)\nT(?y2, rdf:type, ?c)",
230
+ "then": "T(?y1, owl:sameAs, ?y2)"
231
+ },
232
+ {
233
+ "id": "cls-maxqc4",
234
+ "if": "T(?x, owl:maxQualifiedCardinality, \"1\"^^xsd:nonNegativeInteger)\nT(?x, owl:onProperty, ?p)\nT(?x, owl:onClass, owl:Thing)\nT(?u, rdf:type, ?x)\nT(?u, ?p, ?y1)\nT(?u, ?p, ?y2)",
235
+ "then": "T(?y1, owl:sameAs, ?y2)"
236
+ },
237
+ {
238
+ "id": "cls-oo",
239
+ "if": "T(?c, owl:oneOf, ?x)\nLIST[?x, ?y1, ..., ?yn]",
240
+ "then": "T(?y1, rdf:type, ?c)\n...\nT(?yn, rdf:type, ?c)"
241
+ },
242
+ {
243
+ "id": "cax-sco",
244
+ "if": "T(?c1, rdfs:subClassOf, ?c2)\nT(?x, rdf:type, ?c1)",
245
+ "then": "T(?x, rdf:type, ?c2)"
246
+ },
247
+ {
248
+ "id": "cax-eqc1",
249
+ "if": "T(?c1, owl:equivalentClass, ?c2)\nT(?x, rdf:type, ?c1)",
250
+ "then": "T(?x, rdf:type, ?c2)"
251
+ },
252
+ {
253
+ "id": "cax-eqc2",
254
+ "if": "T(?c1, owl:equivalentClass, ?c2)\nT(?x, rdf:type, ?c2)",
255
+ "then": "T(?x, rdf:type, ?c1)"
256
+ },
257
+ {
258
+ "id": "cax-dw",
259
+ "if": "T(?c1, owl:disjointWith, ?c2)\nT(?x, rdf:type, ?c1)\nT(?x, rdf:type, ?c2)",
260
+ "then": "false"
261
+ },
262
+ {
263
+ "id": "cax-adc",
264
+ "if": "T(?x, rdf:type, owl:AllDisjointClasses)\nT(?x, owl:members, ?y)\nLIST[?y, ?c1, ..., ?cn]\nT(?z, rdf:type, ?ci)\nT(?z, rdf:type, ?cj)",
265
+ "then": "false"
266
+ },
267
+ {
268
+ "id": "dt-type1",
269
+ "if": "",
270
+ "then": "T(dt, rdf:type, rdfs:Datatype)"
271
+ },
272
+ {
273
+ "id": "dt-type2",
274
+ "if": "",
275
+ "then": "T(lt, rdf:type, dt)"
276
+ },
277
+ {
278
+ "id": "dt-eq",
279
+ "if": "",
280
+ "then": "T(lt1, owl:sameAs, lt2)"
281
+ },
282
+ {
283
+ "id": "dt-diff",
284
+ "if": "",
285
+ "then": "T(lt1, owl:differentFrom, lt2)"
286
+ },
287
+ {
288
+ "id": "dt-not-type",
289
+ "if": "T(lt, rdf:type, dt)",
290
+ "then": "false"
291
+ },
292
+ {
293
+ "id": "scm-cls",
294
+ "if": "T(?c, rdf:type, owl:Class)",
295
+ "then": "T(?c, rdfs:subClassOf, ?c)\nT(?c, owl:equivalentClass, ?c)\nT(?c, rdfs:subClassOf, owl:Thing)\nT(owl:Nothing, rdfs:subClassOf, ?c)"
296
+ },
297
+ {
298
+ "id": "scm-sco",
299
+ "if": "T(?c1, rdfs:subClassOf, ?c2)\nT(?c2, rdfs:subClassOf, ?c3)",
300
+ "then": "T(?c1, rdfs:subClassOf, ?c3)"
301
+ },
302
+ {
303
+ "id": "scm-eqc1",
304
+ "if": "T(?c1, owl:equivalentClass, ?c2)",
305
+ "then": "T(?c1, rdfs:subClassOf, ?c2)\nT(?c2, rdfs:subClassOf, ?c1)"
306
+ },
307
+ {
308
+ "id": "scm-eqc2",
309
+ "if": "T(?c1, rdfs:subClassOf, ?c2)\nT(?c2, rdfs:subClassOf, ?c1)",
310
+ "then": "T(?c1, owl:equivalentClass, ?c2)"
311
+ },
312
+ {
313
+ "id": "scm-op",
314
+ "if": "T(?p, rdf:type, owl:ObjectProperty)",
315
+ "then": "T(?p, rdfs:subPropertyOf, ?p)\nT(?p, owl:equivalentProperty, ?p)"
316
+ },
317
+ {
318
+ "id": "scm-dp",
319
+ "if": "T(?p, rdf:type, owl:DatatypeProperty)",
320
+ "then": "T(?p, rdfs:subPropertyOf, ?p)\nT(?p, owl:equivalentProperty, ?p)"
321
+ },
322
+ {
323
+ "id": "scm-spo",
324
+ "if": "T(?p1, rdfs:subPropertyOf, ?p2)\nT(?p2, rdfs:subPropertyOf, ?p3)",
325
+ "then": "T(?p1, rdfs:subPropertyOf, ?p3)"
326
+ },
327
+ {
328
+ "id": "scm-eqp1",
329
+ "if": "T(?p1, owl:equivalentProperty, ?p2)",
330
+ "then": "T(?p1, rdfs:subPropertyOf, ?p2)\nT(?p2, rdfs:subPropertyOf, ?p1)"
331
+ },
332
+ {
333
+ "id": "scm-eqp2",
334
+ "if": "T(?p1, rdfs:subPropertyOf, ?p2)\nT(?p2, rdfs:subPropertyOf, ?p1)",
335
+ "then": "T(?p1, owl:equivalentProperty, ?p2)"
336
+ },
337
+ {
338
+ "id": "scm-dom1",
339
+ "if": "T(?p, rdfs:domain, ?c1)\nT(?c1, rdfs:subClassOf, ?c2)",
340
+ "then": "T(?p, rdfs:domain, ?c2)"
341
+ },
342
+ {
343
+ "id": "scm-dom2",
344
+ "if": "T(?p2, rdfs:domain, ?c)\nT(?p1, rdfs:subPropertyOf, ?p2)",
345
+ "then": "T(?p1, rdfs:domain, ?c)"
346
+ },
347
+ {
348
+ "id": "scm-rng1",
349
+ "if": "T(?p, rdfs:range, ?c1)\nT(?c1, rdfs:subClassOf, ?c2)",
350
+ "then": "T(?p, rdfs:range, ?c2)"
351
+ },
352
+ {
353
+ "id": "scm-rng2",
354
+ "if": "T(?p2, rdfs:range, ?c)\nT(?p1, rdfs:subPropertyOf, ?p2)",
355
+ "then": "T(?p1, rdfs:range, ?c)"
356
+ },
357
+ {
358
+ "id": "scm-hv",
359
+ "if": "T(?c1, owl:hasValue, ?i)\nT(?c1, owl:onProperty, ?p1)\nT(?c2, owl:hasValue, ?i)\nT(?c2, owl:onProperty, ?p2)\nT(?p1, rdfs:subPropertyOf, ?p2)",
360
+ "then": "T(?c1, rdfs:subClassOf, ?c2)"
361
+ },
362
+ {
363
+ "id": "scm-svf1",
364
+ "if": "T(?c1, owl:someValuesFrom, ?y1)\nT(?c1, owl:onProperty, ?p)\nT(?c2, owl:someValuesFrom, ?y2)\nT(?c2, owl:onProperty, ?p)\nT(?y1, rdfs:subClassOf, ?y2)",
365
+ "then": "T(?c1, rdfs:subClassOf, ?c2)"
366
+ },
367
+ {
368
+ "id": "scm-svf2",
369
+ "if": "T(?c1, owl:someValuesFrom, ?y)\nT(?c1, owl:onProperty, ?p1)\nT(?c2, owl:someValuesFrom, ?y)\nT(?c2, owl:onProperty, ?p2)\nT(?p1, rdfs:subPropertyOf, ?p2)",
370
+ "then": "T(?c1, rdfs:subClassOf, ?c2)"
371
+ },
372
+ {
373
+ "id": "scm-avf1",
374
+ "if": "T(?c1, owl:allValuesFrom, ?y1)\nT(?c1, owl:onProperty, ?p)\nT(?c2, owl:allValuesFrom, ?y2)\nT(?c2, owl:onProperty, ?p)\nT(?y1, rdfs:subClassOf, ?y2)",
375
+ "then": "T(?c1, rdfs:subClassOf, ?c2)"
376
+ },
377
+ {
378
+ "id": "scm-avf2",
379
+ "if": "T(?c1, owl:allValuesFrom, ?y)\nT(?c1, owl:onProperty, ?p1)\nT(?c2, owl:allValuesFrom, ?y)\nT(?c2, owl:onProperty, ?p2)\nT(?p1, rdfs:subPropertyOf, ?p2)",
380
+ "then": "T(?c2, rdfs:subClassOf, ?c1)"
381
+ },
382
+ {
383
+ "id": "scm-int",
384
+ "if": "T(?c, owl:intersectionOf, ?x)\nLIST[?x, ?c1, ..., ?cn]",
385
+ "then": "T(?c, rdfs:subClassOf, ?c1)\nT(?c, rdfs:subClassOf, ?c2)\n...\nT(?c, rdfs:subClassOf, ?cn)"
386
+ },
387
+ {
388
+ "id": "scm-uni",
389
+ "if": "T(?c, owl:unionOf, ?x)\nLIST[?x, ?c1, ..., ?cn]",
390
+ "then": "T(?c1, rdfs:subClassOf, ?c)\nT(?c2, rdfs:subClassOf, ?c)\n...\nT(?cn, rdfs:subClassOf, ?c)"
391
+ }
392
+ ]
package/main.js ADDED
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ // ---------------------------------------------------------------------------
4
+ // Electron desktop shell for protege-js.
5
+ // Starts the local web server, then opens a BrowserWindow pointing at it.
6
+ // Run: node main.js (or: npx electron . )
7
+ // ---------------------------------------------------------------------------
8
+
9
+ const path = require('path');
10
+ const { start, PORT } = require('./src/server/webServer');
11
+
12
+ function startElectron() {
13
+ const { app, BrowserWindow } = require('electron');
14
+
15
+ app.whenReady().then(() => {
16
+ const server = start(PORT);
17
+ const win = new BrowserWindow({
18
+ width: 1280,
19
+ height: 840,
20
+ title: 'Protégé JS',
21
+ backgroundColor: '#1e1e1e',
22
+ webPreferences: {
23
+ contextIsolation: true
24
+ }
25
+ });
26
+ win.loadURL(`http://localhost:${PORT}/`);
27
+ app.on('window-all-closed', () => {
28
+ server.close();
29
+ if (process.platform !== 'darwin') app.quit();
30
+ else app.quit();
31
+ });
32
+ });
33
+ }
34
+
35
+ function startHeadless() {
36
+ // No Electron available (e.g. running with plain node) — just run the server.
37
+ start(PORT);
38
+ console.log('Open http://localhost:' + PORT + '/ in a browser.');
39
+ }
40
+
41
+ try {
42
+ require.resolve('electron');
43
+ startElectron();
44
+ } catch {
45
+ startHeadless();
46
+ }
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@skaterqiang/protege-js",
3
+ "version": "0.1.0",
4
+ "description": "Zero-dependency OWL 2 / RDF / SWRL library for Node.js: 6 parsers, 3 serializers, and a forward-chaining reasoner covering all 78 W3C OWL 2 RL rules plus QL/EL profiles. A Node.js port of Protégé's non-UI core.",
5
+ "main": "src/index.js",
6
+ "exports": {
7
+ ".": "./src/index.js",
8
+ "./src/*.js": "./src/*.js",
9
+ "./src/*": "./src/*.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "files": [
16
+ "src/",
17
+ "docs/",
18
+ "sample/",
19
+ "test/",
20
+ "scripts/",
21
+ "main.js",
22
+ "README.md",
23
+ "CHANGELOG.md",
24
+ "LICENSE"
25
+ ],
26
+ "scripts": {
27
+ "start": "node main.js",
28
+ "start:web": "node src/server/webServer.js",
29
+ "test": "node --test test/*.test.js test/owl2rl/*.test.js test/owl2/*.test.js",
30
+ "test:rl": "node --test test/owl2rl/*.test.js",
31
+ "test:spec": "node --test test/owl2/*.test.js",
32
+ "verify:api": "node scripts/verify-api.js",
33
+ "sample": "node sample/case1-ecommerce-risk.js",
34
+ "prepublishOnly": "npm test && npm run verify:api"
35
+ },
36
+ "keywords": [
37
+ "owl",
38
+ "owl2",
39
+ "owl2-rl",
40
+ "rdf",
41
+ "rdfs",
42
+ "swrl",
43
+ "ontology",
44
+ "semantic-web",
45
+ "reasoner",
46
+ "reasoning",
47
+ "knowledge-graph",
48
+ "turtle",
49
+ "rdfxml",
50
+ "manchester-syntax",
51
+ "functional-syntax",
52
+ "protege",
53
+ "bfo",
54
+ "description-logic",
55
+ "parser",
56
+ "serializer"
57
+ ],
58
+ "author": "skaterqiang",
59
+ "license": "BSD-2-Clause",
60
+ "repository": {
61
+ "type": "git",
62
+ "url": "git+https://github.com/skaterqiang/protege-js.git"
63
+ },
64
+ "homepage": "https://github.com/skaterqiang/protege-js#readme",
65
+ "bugs": {
66
+ "url": "https://github.com/skaterqiang/protege-js/issues"
67
+ },
68
+ "engines": {
69
+ "node": ">=18.0.0"
70
+ },
71
+ "sideEffects": false,
72
+ "dependencies": {},
73
+ "devDependencies": {
74
+ "electron": "^33.0.0"
75
+ }
76
+ }
@@ -0,0 +1,74 @@
1
+ # 业务案例(sample/)—— OWL 2 端到端实战
2
+
3
+ 本目录收录 **10 个真实业务场景** 的端到端示例,演示 protege-js 如何用 OWL 2 解决具体业务问题。每个案例独立成文件、可直接运行,并由 [../test/owl2/sample-e2e.test.js](../test/owl2/sample-e2e.test.js) 做自动化断言。
4
+
5
+ 其中 [ontologies/](ontologies/) 目录存放**真实下载的行业公开标准本体** OWL 文件(BFO / OGMS / RO-core / IAO,均来自 OBO Foundry 官方 PURL),案例 8、9 直接加载这些真实文件。
6
+
7
+ ## 运行
8
+
9
+ ```bash
10
+ # 单独运行某个案例(打印中文业务结论)
11
+ node sample/case1-ecommerce-risk.js
12
+
13
+ # 运行全部 10 个案例
14
+ for f in sample/case*.js; do echo "=== $f ==="; node "$f"; done
15
+
16
+ # 作为端到端测试运行(纳入 npm test)
17
+ node --test test/owl2/sample-e2e.test.js
18
+ ```
19
+
20
+ ## 案例一览
21
+
22
+ | # | 文件 | 业务场景 | 用到的 OWL 2 能力 |
23
+ |---|------|---------|------------------|
24
+ | 1 | [case1-ecommerce-risk.js](case1-ecommerce-risk.js) | **电商订单风控**:黑名单买家下单自动标记为高风险订单;误标可信订单时触发一致性告警 | `rdfs:subClassOf` 分类、`rdf:type` 实例归类、`owl:disjointWith` 冲突检测 |
25
+ | 2 | [case2-family-swrl.js](case2-family-swrl.js) | **家庭关系推理**:由「父亲+其兄弟」推出叔叔;按年龄自动判定成年 | SWRL 规则(类/对象属性/数据属性/内置函数原子)、`swrlb:greaterThanOrEqual`、`owl:inverseOf` |
26
+ | 3 | [case3-pharma-safety.js](case3-pharma-safety.js) | **医疗用药安全**:防止给同一病人开具相互禁忌的药物;相同身份证号的病人记录自动合并 | `owl:disjointWith` 一致性、`owl:hasKey` 唯一识别(prp-key)、`owl:sameAs` |
27
+ | 4 | [case4-knowledge-publishing.js](case4-knowledge-publishing.js) | **知识库内容发布**:Turtle 手写本体 → 解析 → 结构化 → 导出为 Turtle/Functional/RDF-XML,往返不丢公理 | TurtleParser、triplesToOntology 桥接、三种 Writer、前缀保真 |
28
+ | 5 | [case5-obda-profiles.js](case5-obda-profiles.js) | **企业数据集成(OBDA)**:分散员工数据按本体统一查询召回;组织架构传递分类;profile 合规校验 | OWL2QLReasoner、OWL2ELReasoner、`prp-trp` 传递性、checkQL/checkEL |
29
+ | 6 | [case6-medical-ontology.js](case6-medical-ontology.js) | **医疗本体层**(BFO/OGMS/DOID 风格):疾病-症状-药物-检查核心骨架 + **OWL 文件导入导出**(Turtle→RDF/XML→再导入 round-trip) | TurtleParser、`writeRDFXML`、`parseRDFXML`、OWL 2 RL 类层级推理(cax-sco) |
30
+ | 7 | [case7-manufacturing-ppr.js](case7-manufacturing-ppr.js) | **制造业本体层**(ISA-95/BFO+CCO 风格):产品-工艺-资源(PPR)三角 + BOM 结构 + **OWL 文件导入导出** round-trip | TurtleParser、`writeRDFXML`、`parseRDFXML`、`prp-trp` 传递(hasPart)、`prp-inv` 逆关系(partOf) |
31
+ | 8 | [case8-real-medical-bfo-ogms.js](case8-real-medical-bfo-ogms.js) | **真实医疗标准本体层**:直接加载下载的 **BFO + OGMS + RO-core** 公开 OWL 文件,提取真实类层级(230 条 subclass 边 / 187 个 OGMS 类 / 38 个临床核心类),沿真实层级对临床实例做 RL 归因 | 真实公开 OWL 文件加载、`parseRDFXML`、OWL 2 RL 类层级推理、RDF/XML 再导出 |
32
+ | 9 | [case9-real-manufacturing-iao.js](case9-real-manufacturing-iao.js) | **真实制造业标准本体层**:加载真实 **BFO + IAO**,把「工艺文件/批生产记录/作业指导书」挂到 IAO 标准类 | 真实公开 OWL 文件加载、IAO 信息制品标准类复用、`cax-sco` 类层级归因、RDF/XML 导出 |
33
+ | 10 | [case10-ecommerce-customer-service.js](case10-ecommerce-customer-service.js) | **电商客服智能工单分派**:SWRL 技能路由 + 根因分析 + 升级预测 + 跨渠道关联 | SWRL 路由规则、BFO/IAO 归因、`cax-dw` disjoint、`prp-trp` 传递、RDF/XML 导出 |
34
+
35
+ ## 真实公开本体(ontologies/)
36
+
37
+ 以下文件为 OBO Foundry 官方发布的**真实行业标准本体**,供案例 8、9 直接使用:
38
+
39
+ | 文件 | 本体 | 来源 | 公理数 | 用途 |
40
+ |------|------|------|-------|------|
41
+ | [ontologies/bfo.owl](ontologies/bfo.owl) | Basic Formal Ontology (BFO) | https://purl.obolibrary.org/obo/bfo.owl | 178 | ISO/IEC 21838-2 顶层本体,医疗/制造共用基础 |
42
+ | [ontologies/ogms.owl](ontologies/ogms.owl) | Ontology for General Medical Science (OGMS) | https://purl.obolibrary.org/obo/ogms.owl | 845 | 医疗通用科学本体(disease/diagnosis 等临床核心类) |
43
+ | [ontologies/ro-core.owl](ontologies/ro-core.owl) | OBO Relation Ontology core | https://purl.obolibrary.org/obo/ro/core.owl | 245 | 标准关系(part_of/has_part 等),制造业 BOM 谓词来源 |
44
+ | [ontologies/iao.owl](ontologies/iao.owl) | Information Artifact Ontology (IAO) | https://purl.obolibrary.org/obo/iao.owl | 2361 | 信息制品本体(工艺文档/批记录/计划规范等标准类) |
45
+ ### 许可证与归属(License & Attribution)
46
+
47
+ 上述 4 个文件为第三方作品,**不属于本项目的 BSD-2-Clause 许可范围**,按各自原始许可证随包再分发。许可证信息取自各文件内嵌的 `dcterms:license` / `dc:license` 注解(已逐个核实):
48
+
49
+ | 文件 | 许可证 | 文件内声明位置 | 版权/来源 |
50
+ |------|--------|---------------|----------|
51
+ | `bfo.owl` | [CC-BY 4.0](https://creativecommons.org/licenses/by/4.0/) | `<terms:license rdf:resource="http://creativecommons.org/licenses/by/4.0/"/>` | Barry Smith 等,[Basic Formal Ontology](https://basic-formal-ontology.org/) |
52
+ | `ogms.owl` | [CC-BY 4.0](https://creativecommons.org/licenses/by/4.0/) | `<terms:license>http://creativecommons.org/licenses/by/4.0/</terms:license>` | OGMS 项目组,[OBO Foundry](http://obofoundry.org/ontology/ogms.html) |
53
+ | `iao.owl` | [CC-BY 4.0](https://creativecommons.org/licenses/by/4.0/) | `<terms:license rdf:resource="http://creativecommons.org/licenses/by/4.0/"/>` | IAO 项目组,[OBO Foundry](http://obofoundry.org/ontology/iao.html) |
54
+ | `ro-core.owl` | [CC0 1.0](https://creativecommons.org/publicdomain/zero/1.0/) | `<terms:license rdf:resource="https://creativecommons.org/publicdomain/zero/1.0/"/>` | OBO Relation Ontology 项目组 |
55
+
56
+ CC-BY 4.0 要求署名(attribution):本表即为署名声明;如需再分发,请保留本表与各文件内的原始许可证注解。
57
+
58
+ > 这 4 个文件共约 **1.07 MB**,占 npm 包体积的主要部分。若你只需要库本身,可在安装后删除 `sample/ontologies/`——但 `test/owl2/sample-e2e.test.js` 中 case8 / case9 / case10 依赖它们,删除后这 3 个用例会失败。
59
+ ## 每个案例的结构
60
+
61
+ - 文件顶部块注释:**业务背景 / 业务规则 / 用到的 OWL 2 能力 / 预期结果**。
62
+ - `buildStore()`:构造业务数据(TBox 类层级 + ABox 实例)。
63
+ - `run()`:执行推理/解析/序列化,返回关键结论。
64
+ - `if (require.main === module)`:直接运行时打印中文业务结论,便于人工核对。
65
+
66
+ ## 覆盖的 OWL 2 规范面
67
+
68
+ - **OWL 2 RL**:分类(cax-sco/eqc)、一致性(cax-dw)、hasKey(prp-key)、等价合并(eq-*)
69
+ - **OWL 2 QL / EL**:最小推理机 + 查询召回 + 传递闭包
70
+ - **SWRL**:规则模型 + 求值器(含 builtin)
71
+ - **解析/序列化**:Turtle、Functional Syntax、RDF/XML、round-trip
72
+ - **OWL 文件导入导出**:Turtle 导入 → RDF/XML 导出 → RDF/XML 再导入(医疗/制造本体层交换格式)
73
+ - **真实公开本体加载**:直接解析 OBO Foundry 官方 BFO/OGMS/RO/IAO OWL 文件并复用其标准类层级与关系
74
+ - **Profile 校验**:OWL2Profiles(checkQL / checkEL)