@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,242 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { OWLClass } = require('./OWLEntity');
|
|
4
|
+
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// OWLClassExpression — mirrors org.semanticweb.owlapi.model.OWLClassExpression
|
|
7
|
+
// Named classes are OWLClass instances; anonymous expressions are objects
|
|
8
|
+
// created here: ObjectIntersectionOf / ObjectUnionOf / ObjectComplementOf /
|
|
9
|
+
// ObjectSomeValuesFrom / ObjectAllValuesFrom / ObjectHasValue /
|
|
10
|
+
// ObjectOneOf / ObjectExactCardinality / etc.
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
const ClassExpressionType = Object.freeze({
|
|
14
|
+
OWL_CLASS: 'OWLClass',
|
|
15
|
+
// Object-side
|
|
16
|
+
OBJECT_INTERSECTION_OF: 'ObjectIntersectionOf',
|
|
17
|
+
OBJECT_UNION_OF: 'ObjectUnionOf',
|
|
18
|
+
OBJECT_COMPLEMENT_OF: 'ObjectComplementOf',
|
|
19
|
+
OBJECT_SOME_VALUES_FROM: 'ObjectSomeValuesFrom',
|
|
20
|
+
OBJECT_ALL_VALUES_FROM: 'ObjectAllValuesFrom',
|
|
21
|
+
OBJECT_HAS_VALUE: 'ObjectHasValue',
|
|
22
|
+
OBJECT_ONE_OF: 'ObjectOneOf',
|
|
23
|
+
OBJECT_HAS_SELF: 'ObjectHasSelf',
|
|
24
|
+
OBJECT_MIN_CARDINALITY: 'ObjectMinCardinality',
|
|
25
|
+
OBJECT_MAX_CARDINALITY: 'ObjectMaxCardinality',
|
|
26
|
+
OBJECT_EXACT_CARDINALITY: 'ObjectExactCardinality',
|
|
27
|
+
OBJECT_MIN_QUALIFIED_CARDINALITY: 'ObjectMinQualifiedCardinality',
|
|
28
|
+
OBJECT_MAX_QUALIFIED_CARDINALITY: 'ObjectMaxQualifiedCardinality',
|
|
29
|
+
OBJECT_EXACT_QUALIFIED_CARDINALITY: 'ObjectExactQualifiedCardinality',
|
|
30
|
+
// Data-side
|
|
31
|
+
DATA_SOME_VALUES_FROM: 'DataSomeValuesFrom',
|
|
32
|
+
DATA_ALL_VALUES_FROM: 'DataAllValuesFrom',
|
|
33
|
+
DATA_HAS_VALUE: 'DataHasValue',
|
|
34
|
+
DATA_MIN_CARDINALITY: 'DataMinCardinality',
|
|
35
|
+
DATA_MAX_CARDINALITY: 'DataMaxCardinality',
|
|
36
|
+
DATA_EXACT_CARDINALITY: 'DataExactCardinality',
|
|
37
|
+
// Data ranges (not strictly class expressions but part of OWL2 syntax)
|
|
38
|
+
DATA_INTERSECTION_OF: 'DataIntersectionOf',
|
|
39
|
+
DATA_UNION_OF: 'DataUnionOf',
|
|
40
|
+
DATA_COMPLEMENT_OF: 'DataComplementOf',
|
|
41
|
+
DATA_ONE_OF: 'DataOneOf',
|
|
42
|
+
DATATYPE_RESTRICTION: 'DatatypeRestriction'
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
class OWLObjectIntersectionOf {
|
|
46
|
+
constructor(operands) {
|
|
47
|
+
this.type = ClassExpressionType.OBJECT_INTERSECTION_OF;
|
|
48
|
+
this.operands = operands.slice();
|
|
49
|
+
}
|
|
50
|
+
toString() { return `(${this.operands.map(String).join(' and ')})`; }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
class OWLObjectUnionOf {
|
|
54
|
+
constructor(operands) {
|
|
55
|
+
this.type = ClassExpressionType.OBJECT_UNION_OF;
|
|
56
|
+
this.operands = operands.slice();
|
|
57
|
+
}
|
|
58
|
+
toString() { return `(${this.operands.map(String).join(' or ')})`; }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
class OWLObjectComplementOf {
|
|
62
|
+
constructor(operand) {
|
|
63
|
+
this.type = ClassExpressionType.OBJECT_COMPLEMENT_OF;
|
|
64
|
+
this.operand = operand;
|
|
65
|
+
}
|
|
66
|
+
toString() { return `(not ${this.operand})`; }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
class OWLObjectSomeValuesFrom {
|
|
70
|
+
constructor(property, filler) {
|
|
71
|
+
this.type = ClassExpressionType.OBJECT_SOME_VALUES_FROM;
|
|
72
|
+
this.property = property;
|
|
73
|
+
this.filler = filler;
|
|
74
|
+
}
|
|
75
|
+
toString() { return `(${this.property.getShortForm()} some ${this.filler})`; }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
class OWLObjectAllValuesFrom {
|
|
79
|
+
constructor(property, filler) {
|
|
80
|
+
this.type = ClassExpressionType.OBJECT_ALL_VALUES_FROM;
|
|
81
|
+
this.property = property;
|
|
82
|
+
this.filler = filler;
|
|
83
|
+
}
|
|
84
|
+
toString() { return `(${this.property.getShortForm()} only ${this.filler})`; }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
class OWLObjectHasValue {
|
|
88
|
+
constructor(property, value) {
|
|
89
|
+
this.type = ClassExpressionType.OBJECT_HAS_VALUE;
|
|
90
|
+
this.property = property;
|
|
91
|
+
this.value = value; // OWLNamedIndividual
|
|
92
|
+
}
|
|
93
|
+
toString() { return `(${this.property.getShortForm()} value ${this.value.getShortForm()})`; }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
class OWLObjectOneOf {
|
|
97
|
+
constructor(individuals) {
|
|
98
|
+
this.type = ClassExpressionType.OBJECT_ONE_OF;
|
|
99
|
+
this.operands = individuals.slice();
|
|
100
|
+
}
|
|
101
|
+
toString() { return `{${this.operands.map(i => i.getShortForm()).join(', ')}}`; }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
class OWLObjectCardinalityRestriction {
|
|
105
|
+
constructor(type, cardinality, property, filler) {
|
|
106
|
+
this.type = type;
|
|
107
|
+
this.cardinality = cardinality;
|
|
108
|
+
this.property = property;
|
|
109
|
+
this.filler = filler;
|
|
110
|
+
}
|
|
111
|
+
toString() {
|
|
112
|
+
const op = this.type === ClassExpressionType.OBJECT_MIN_CARDINALITY
|
|
113
|
+
|| this.type === ClassExpressionType.OBJECT_MIN_QUALIFIED_CARDINALITY ? 'min'
|
|
114
|
+
: this.type === ClassExpressionType.OBJECT_MAX_CARDINALITY
|
|
115
|
+
|| this.type === ClassExpressionType.OBJECT_MAX_QUALIFIED_CARDINALITY ? 'max' : 'exactly';
|
|
116
|
+
return `(${this.property.getShortForm()} ${op} ${this.cardinality} ${this.filler || ''})`;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
class OWLObjectHasSelf {
|
|
121
|
+
constructor(property) {
|
|
122
|
+
this.type = ClassExpressionType.OBJECT_HAS_SELF;
|
|
123
|
+
this.property = property;
|
|
124
|
+
}
|
|
125
|
+
toString() { return `(${this.property.getShortForm()} Self)`; }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ---- Data-side class expressions -------------------------------------------
|
|
129
|
+
|
|
130
|
+
class OWLDataSomeValuesFrom {
|
|
131
|
+
constructor(property, dataRange) {
|
|
132
|
+
this.type = ClassExpressionType.DATA_SOME_VALUES_FROM;
|
|
133
|
+
this.property = property;
|
|
134
|
+
this.filler = dataRange;
|
|
135
|
+
}
|
|
136
|
+
toString() { return `(${this.property.getShortForm()} some ${this.filler})`; }
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
class OWLDataAllValuesFrom {
|
|
140
|
+
constructor(property, dataRange) {
|
|
141
|
+
this.type = ClassExpressionType.DATA_ALL_VALUES_FROM;
|
|
142
|
+
this.property = property;
|
|
143
|
+
this.filler = dataRange;
|
|
144
|
+
}
|
|
145
|
+
toString() { return `(${this.property.getShortForm()} only ${this.filler})`; }
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
class OWLDataHasValue {
|
|
149
|
+
constructor(property, literal) {
|
|
150
|
+
this.type = ClassExpressionType.DATA_HAS_VALUE;
|
|
151
|
+
this.property = property;
|
|
152
|
+
this.value = literal; // OWLLiteral
|
|
153
|
+
}
|
|
154
|
+
toString() { return `(${this.property.getShortForm()} value ${this.value})`; }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
class OWLDataCardinalityRestriction {
|
|
158
|
+
constructor(type, cardinality, property, dataRange) {
|
|
159
|
+
this.type = type;
|
|
160
|
+
this.cardinality = cardinality;
|
|
161
|
+
this.property = property;
|
|
162
|
+
this.filler = dataRange;
|
|
163
|
+
}
|
|
164
|
+
toString() {
|
|
165
|
+
const op = this.type === ClassExpressionType.DATA_MIN_CARDINALITY ? 'min'
|
|
166
|
+
: this.type === ClassExpressionType.DATA_MAX_CARDINALITY ? 'max' : 'exactly';
|
|
167
|
+
return `(${this.property.getShortForm()} ${op} ${this.cardinality} ${this.filler || ''})`;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ---- Data ranges ------------------------------------------------------------
|
|
172
|
+
|
|
173
|
+
class OWLDataIntersectionOf {
|
|
174
|
+
constructor(operands) {
|
|
175
|
+
this.type = ClassExpressionType.DATA_INTERSECTION_OF;
|
|
176
|
+
this.operands = operands.slice();
|
|
177
|
+
}
|
|
178
|
+
toString() { return `(${this.operands.map(String).join(' and ')})`; }
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
class OWLDataUnionOf {
|
|
182
|
+
constructor(operands) {
|
|
183
|
+
this.type = ClassExpressionType.DATA_UNION_OF;
|
|
184
|
+
this.operands = operands.slice();
|
|
185
|
+
}
|
|
186
|
+
toString() { return `(${this.operands.map(String).join(' or ')})`; }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
class OWLDataComplementOf {
|
|
190
|
+
constructor(operand) {
|
|
191
|
+
this.type = ClassExpressionType.DATA_COMPLEMENT_OF;
|
|
192
|
+
this.operand = operand;
|
|
193
|
+
}
|
|
194
|
+
toString() { return `(not ${this.operand})`; }
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
class OWLDataOneOf {
|
|
198
|
+
constructor(literals) {
|
|
199
|
+
this.type = ClassExpressionType.DATA_ONE_OF;
|
|
200
|
+
this.operands = literals.slice();
|
|
201
|
+
}
|
|
202
|
+
toString() { return `{${this.operands.join(', ')}}`; }
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
class OWLDatatypeRestriction {
|
|
206
|
+
constructor(datatype, facetRestrictions) {
|
|
207
|
+
this.type = ClassExpressionType.DATATYPE_RESTRICTION;
|
|
208
|
+
this.datatype = datatype; // OWLDatatype
|
|
209
|
+
this.facetRestrictions = facetRestrictions.slice(); // [{facet: IRI, value: OWLLiteral}]
|
|
210
|
+
}
|
|
211
|
+
toString() {
|
|
212
|
+
const fr = this.facetRestrictions.map(f => `${f.facet.getShortForm()} ${f.value}`).join(' ');
|
|
213
|
+
return `${this.datatype.getShortForm()}[${fr}]`;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function isNamedClass(expr) {
|
|
218
|
+
return expr instanceof OWLClass;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
module.exports = {
|
|
222
|
+
ClassExpressionType,
|
|
223
|
+
OWLObjectIntersectionOf,
|
|
224
|
+
OWLObjectUnionOf,
|
|
225
|
+
OWLObjectComplementOf,
|
|
226
|
+
OWLObjectSomeValuesFrom,
|
|
227
|
+
OWLObjectAllValuesFrom,
|
|
228
|
+
OWLObjectHasValue,
|
|
229
|
+
OWLObjectOneOf,
|
|
230
|
+
OWLObjectHasSelf,
|
|
231
|
+
OWLObjectCardinalityRestriction,
|
|
232
|
+
OWLDataSomeValuesFrom,
|
|
233
|
+
OWLDataAllValuesFrom,
|
|
234
|
+
OWLDataHasValue,
|
|
235
|
+
OWLDataCardinalityRestriction,
|
|
236
|
+
OWLDataIntersectionOf,
|
|
237
|
+
OWLDataUnionOf,
|
|
238
|
+
OWLDataComplementOf,
|
|
239
|
+
OWLDataOneOf,
|
|
240
|
+
OWLDatatypeRestriction,
|
|
241
|
+
isNamedClass
|
|
242
|
+
};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { IRI } = require('./IRI');
|
|
4
|
+
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// OWLEntity — mirrors org.semanticweb.owlapi.model.OWLEntity hierarchy
|
|
7
|
+
// OWLClass, OWLObjectProperty, OWLDataProperty, OWLNamedIndividual,
|
|
8
|
+
// OWLDatatype, OWLAnnotationProperty
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
const EntityType = Object.freeze({
|
|
12
|
+
CLASS: 'Class',
|
|
13
|
+
OBJECT_PROPERTY: 'ObjectProperty',
|
|
14
|
+
DATA_PROPERTY: 'DataProperty',
|
|
15
|
+
NAMED_INDIVIDUAL: 'NamedIndividual',
|
|
16
|
+
DATATYPE: 'Datatype',
|
|
17
|
+
ANNOTATION_PROPERTY: 'AnnotationProperty'
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
class OWLEntity {
|
|
21
|
+
constructor(iri, entityType) {
|
|
22
|
+
this.iri = iri instanceof IRI ? iri : IRI.create(iri);
|
|
23
|
+
this.entityType = entityType;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getIRI() {
|
|
27
|
+
return this.iri;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getEntityType() {
|
|
31
|
+
return this.entityType;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getShortForm() {
|
|
35
|
+
return this.iri.getShortForm();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
isOWLClass() { return this.entityType === EntityType.CLASS; }
|
|
39
|
+
isOWLObjectProperty() { return this.entityType === EntityType.OBJECT_PROPERTY; }
|
|
40
|
+
isOWLDataProperty() { return this.entityType === EntityType.DATA_PROPERTY; }
|
|
41
|
+
isOWLNamedIndividual() { return this.entityType === EntityType.NAMED_INDIVIDUAL; }
|
|
42
|
+
isOWLDatatype() { return this.entityType === EntityType.DATATYPE; }
|
|
43
|
+
isOWLAnnotationProperty() { return this.entityType === EntityType.ANNOTATION_PROPERTY; }
|
|
44
|
+
|
|
45
|
+
equals(other) {
|
|
46
|
+
return other instanceof OWLEntity
|
|
47
|
+
&& other.entityType === this.entityType
|
|
48
|
+
&& other.iri.equals(this.iri);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
toString() {
|
|
52
|
+
return `${this.entityType}(<${this.iri}>)`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
class OWLClass extends OWLEntity {
|
|
57
|
+
constructor(iri) { super(iri, EntityType.CLASS); }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
class OWLObjectProperty extends OWLEntity {
|
|
61
|
+
constructor(iri) { super(iri, EntityType.OBJECT_PROPERTY); }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
class OWLDataProperty extends OWLEntity {
|
|
65
|
+
constructor(iri) { super(iri, EntityType.DATA_PROPERTY); }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
class OWLNamedIndividual extends OWLEntity {
|
|
69
|
+
constructor(iri) { super(iri, EntityType.NAMED_INDIVIDUAL); }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
class OWLDatatype extends OWLEntity {
|
|
73
|
+
constructor(iri) { super(iri, EntityType.DATATYPE); }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
class OWLAnnotationProperty extends OWLEntity {
|
|
77
|
+
constructor(iri) { super(iri, EntityType.ANNOTATION_PROPERTY); }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ---------------------------------------------------------------------------
|
|
81
|
+
// OWLAnonymousIndividual — mirrors org.semanticweb.owlapi.model.OWLAnonymousIndividual
|
|
82
|
+
// An individual identified only by a blank node id (Turtle _:b0), not by an IRI.
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
|
|
85
|
+
class OWLAnonymousIndividual {
|
|
86
|
+
constructor(nodeId) {
|
|
87
|
+
if (!nodeId) throw new Error('OWLAnonymousIndividual requires a nodeId');
|
|
88
|
+
this.nodeId = String(nodeId);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
getNodeId() { return this.nodeId; }
|
|
92
|
+
|
|
93
|
+
isAnonymous() { return true; }
|
|
94
|
+
isNamed() { return false; }
|
|
95
|
+
isOWLNamedIndividual() { return false; }
|
|
96
|
+
isOWLAnonymousIndividual() { return true; }
|
|
97
|
+
|
|
98
|
+
getEntityType() { return EntityType.NAMED_INDIVIDUAL; } // treated as individual in indexes
|
|
99
|
+
|
|
100
|
+
equals(other) {
|
|
101
|
+
return other instanceof OWLAnonymousIndividual && other.nodeId === this.nodeId;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
getShortForm() { return this.nodeId; }
|
|
105
|
+
|
|
106
|
+
toString() { return `_:${this.nodeId.replace(/^_:/, '')}`; }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Well-known entities. */
|
|
110
|
+
const OWL = Object.freeze({
|
|
111
|
+
THING: new OWLClass('http://www.w3.org/2002/07/owl#Thing'),
|
|
112
|
+
NOTHING: new OWLClass('http://www.w3.org/2002/07/owl#Nothing'),
|
|
113
|
+
TOP_OBJECT_PROPERTY: new OWLObjectProperty('http://www.w3.org/2002/07/owl#topObjectProperty'),
|
|
114
|
+
BOTTOM_OBJECT_PROPERTY: new OWLObjectProperty('http://www.w3.org/2002/07/owl#bottomObjectProperty'),
|
|
115
|
+
TOP_DATA_PROPERTY: new OWLDataProperty('http://www.w3.org/2002/07/owl#topDataProperty'),
|
|
116
|
+
BOTTOM_DATA_PROPERTY: new OWLDataProperty('http://www.w3.org/2002/07/owl#bottomDataProperty')
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
/** Entity factory — mirrors OWLDataFactory entity getters. */
|
|
120
|
+
class OWLEntityFactory {
|
|
121
|
+
getOWLClass(iri) { return new OWLClass(iri); }
|
|
122
|
+
getOWLObjectProperty(iri) { return new OWLObjectProperty(iri); }
|
|
123
|
+
getOWLDataProperty(iri) { return new OWLDataProperty(iri); }
|
|
124
|
+
getOWLNamedIndividual(iri) { return new OWLNamedIndividual(iri); }
|
|
125
|
+
getOWLDatatype(iri) { return new OWLDatatype(iri); }
|
|
126
|
+
getOWLAnnotationProperty(iri) { return new OWLAnnotationProperty(iri); }
|
|
127
|
+
getOWLAnonymousIndividual(nodeId) { return new OWLAnonymousIndividual(nodeId); }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
module.exports = {
|
|
131
|
+
EntityType,
|
|
132
|
+
OWLEntity,
|
|
133
|
+
OWLClass,
|
|
134
|
+
OWLObjectProperty,
|
|
135
|
+
OWLDataProperty,
|
|
136
|
+
OWLNamedIndividual,
|
|
137
|
+
OWLAnonymousIndividual,
|
|
138
|
+
OWLDatatype,
|
|
139
|
+
OWLAnnotationProperty,
|
|
140
|
+
OWL,
|
|
141
|
+
OWLEntityFactory
|
|
142
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// OWLLiteral — mirrors org.semanticweb.owlapi.model.OWLLiteral
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
class OWLLiteral {
|
|
8
|
+
constructor(lexicalValue, datatype = null, lang = null) {
|
|
9
|
+
this.lexicalValue = String(lexicalValue);
|
|
10
|
+
this.datatype = datatype; // OWLDatatype | null
|
|
11
|
+
this.lang = lang; // language tag | null
|
|
12
|
+
}
|
|
13
|
+
getLiteral() { return this.lexicalValue; }
|
|
14
|
+
getLang() { return this.lang; }
|
|
15
|
+
getDatatype() { return this.datatype; }
|
|
16
|
+
toString() {
|
|
17
|
+
let s = `"${this.lexicalValue}"`;
|
|
18
|
+
if (this.lang) s += `@${this.lang}`;
|
|
19
|
+
else if (this.datatype) s += `^^<${this.datatype.getIRI()}>`;
|
|
20
|
+
return s;
|
|
21
|
+
}
|
|
22
|
+
equals(other) {
|
|
23
|
+
return other instanceof OWLLiteral
|
|
24
|
+
&& other.lexicalValue === this.lexicalValue
|
|
25
|
+
&& other.lang === this.lang
|
|
26
|
+
&& String(other.datatype) === String(this.datatype);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = { OWLLiteral };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { OWLOntology, OWLOntologyID } = require('./OWLOntology');
|
|
4
|
+
const { EventType, OWLModelManagerChangeEvent } = require('./event/OWLModelManagerEvent');
|
|
5
|
+
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
// OWLModelManager — mirrors org.protege.editor.owl.model.OWLModelManager /
|
|
8
|
+
// OWLModelManagerImpl. Holds a set of ontologies, the active ontology,
|
|
9
|
+
// fires change events, and exposes hierarchy providers.
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
class OWLModelManager {
|
|
13
|
+
constructor() {
|
|
14
|
+
this._ontologies = new Map(); // key: ontology id string
|
|
15
|
+
this._activeOntology = null;
|
|
16
|
+
this._listeners = new Set();
|
|
17
|
+
this._hierarchyProviders = new Map(); // EntityType -> provider
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// --- ontology registry -----------------------------------------------------
|
|
21
|
+
|
|
22
|
+
addOntology(ontology) {
|
|
23
|
+
const key = ontology.getOntologyID().toString();
|
|
24
|
+
this._ontologies.set(key, ontology);
|
|
25
|
+
this._fire(EventType.ONTOLOGY_CREATED, ontology);
|
|
26
|
+
if (!this._activeOntology) {
|
|
27
|
+
this.setActiveOntology(ontology);
|
|
28
|
+
}
|
|
29
|
+
return ontology;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
createOntology(ontologyIRI = null) {
|
|
33
|
+
const ont = new OWLOntology(new OWLOntologyID(ontologyIRI));
|
|
34
|
+
return this.addOntology(ont);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
removeOntology(ontology) {
|
|
38
|
+
const key = ontology.getOntologyID().toString();
|
|
39
|
+
const removed = this._ontologies.delete(key);
|
|
40
|
+
if (removed && this._activeOntology === ontology) {
|
|
41
|
+
this._activeOntology = this.getOntologies()[0] || null;
|
|
42
|
+
this._fire(EventType.ACTIVE_ONTOLOGY_CHANGED, this._activeOntology);
|
|
43
|
+
}
|
|
44
|
+
return removed;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
getOntologies() { return [...this._ontologies.values()]; }
|
|
48
|
+
|
|
49
|
+
setActiveOntology(ontology) {
|
|
50
|
+
if (this._activeOntology !== ontology) {
|
|
51
|
+
this._activeOntology = ontology;
|
|
52
|
+
this._fire(EventType.ACTIVE_ONTOLOGY_CHANGED, ontology);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getActiveOntology() { return this._activeOntology; }
|
|
57
|
+
|
|
58
|
+
// --- change events ---------------------------------------------------------
|
|
59
|
+
|
|
60
|
+
addListener(listener) {
|
|
61
|
+
this._listeners.add(listener);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
removeListener(listener) {
|
|
65
|
+
this._listeners.delete(listener);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
_fire(type, payload) {
|
|
69
|
+
const event = new OWLModelManagerChangeEvent(type, payload);
|
|
70
|
+
for (const l of this._listeners) {
|
|
71
|
+
try { l(event); } catch (e) { console.error('OWLModelManager listener error:', e); }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
fireEvent(type, payload) {
|
|
76
|
+
this._fire(type, payload);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// --- hierarchy providers ---------------------------------------------------
|
|
80
|
+
|
|
81
|
+
setOWLClassHierarchyProvider(provider) {
|
|
82
|
+
this._hierarchyProviders.set('CLASS', provider);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
getOWLClassHierarchyProvider() {
|
|
86
|
+
return this._hierarchyProviders.get('CLASS') || null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
setOWLObjectPropertyHierarchyProvider(provider) {
|
|
90
|
+
this._hierarchyProviders.set('OBJECT_PROPERTY', provider);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getOWLObjectPropertyHierarchyProvider() {
|
|
94
|
+
return this._hierarchyProviders.get('OBJECT_PROPERTY') || null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
setOWLDataPropertyHierarchyProvider(provider) {
|
|
98
|
+
this._hierarchyProviders.set('DATA_PROPERTY', provider);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
getOWLDataPropertyHierarchyProvider() {
|
|
102
|
+
return this._hierarchyProviders.get('DATA_PROPERTY') || null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
module.exports = { OWLModelManager };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { AxiomType } = require('./OWLAxiom');
|
|
4
|
+
const { EntityType } = require('./OWLEntity');
|
|
5
|
+
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
// OWLOntology — mirrors org.semanticweb.owlapi.model.OWLOntology
|
|
8
|
+
// An in-memory set of axioms plus an ontology IRI / version IRI.
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
class OWLOntologyID {
|
|
12
|
+
constructor(ontologyIRI = null, versionIRI = null) {
|
|
13
|
+
this.ontologyIRI = ontologyIRI;
|
|
14
|
+
this.versionIRI = versionIRI;
|
|
15
|
+
}
|
|
16
|
+
isAnonymous() { return !this.ontologyIRI; }
|
|
17
|
+
toString() {
|
|
18
|
+
if (this.isAnonymous()) return 'OntologyID(Anonymous)';
|
|
19
|
+
return `OntologyID(<${this.ontologyIRI}>${this.versionIRI ? ' version <' + this.versionIRI + '>' : ''})`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class OWLOntology {
|
|
24
|
+
constructor(id = new OWLOntologyID()) {
|
|
25
|
+
this.id = id;
|
|
26
|
+
this._axioms = new Set();
|
|
27
|
+
this._ontologyAnnotations = []; // OWLAnnotationAssertion on the ontology itself
|
|
28
|
+
this.format = null; // e.g. 'RDF/XML', 'Turtle'
|
|
29
|
+
// Ontology header (W3C OWL 2 §3.1): imports closure + version compatibility
|
|
30
|
+
this.imports = [];
|
|
31
|
+
this.priorVersion = [];
|
|
32
|
+
this.backwardCompatibleWith = [];
|
|
33
|
+
this.incompatibleWith = [];
|
|
34
|
+
// Prefix fidelity: prefix -> namespace map captured at parse time so
|
|
35
|
+
// writers can re-emit the original abbreviations.
|
|
36
|
+
this.prefixes = {};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Record a prefix mapping (e.g. 'ex' -> 'http://ex.org/'). */
|
|
40
|
+
addPrefix(prefix, namespace) { this.prefixes[prefix] = namespace; }
|
|
41
|
+
|
|
42
|
+
/** Get the recorded prefix map. */
|
|
43
|
+
getPrefixes() { return Object.assign({}, this.prefixes); }
|
|
44
|
+
|
|
45
|
+
getOntologyID() { return this.id; }
|
|
46
|
+
|
|
47
|
+
isAnonymous() { return this.id.isAnonymous(); }
|
|
48
|
+
|
|
49
|
+
getAxiomCount() { return this._axioms.size; }
|
|
50
|
+
|
|
51
|
+
getAxioms() { return [...this._axioms]; }
|
|
52
|
+
|
|
53
|
+
addAxiom(axiom) {
|
|
54
|
+
this._axioms.add(axiom);
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
removeAxiom(axiom) {
|
|
59
|
+
return this._axioms.delete(axiom);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getAxiomsOfType(type) {
|
|
63
|
+
return this.getAxioms().filter(a => a.getAxiomType() === type);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// --- entity indexes --------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
getClassesInSignature() { return this._entitiesOf(EntityType.CLASS); }
|
|
69
|
+
getObjectPropertiesInSignature() { return this._entitiesOf(EntityType.OBJECT_PROPERTY); }
|
|
70
|
+
getDataPropertiesInSignature() { return this._entitiesOf(EntityType.DATA_PROPERTY); }
|
|
71
|
+
getIndividualsInSignature() { return this._entitiesOf(EntityType.NAMED_INDIVIDUAL); }
|
|
72
|
+
getAnnotationPropertiesInSignature() { return this._entitiesOf(EntityType.ANNOTATION_PROPERTY); }
|
|
73
|
+
|
|
74
|
+
_entitiesOf(entityType) {
|
|
75
|
+
const byIri = new Map();
|
|
76
|
+
for (const ax of this._axioms) {
|
|
77
|
+
for (const e of ax.entities()) {
|
|
78
|
+
if (e.getEntityType && e.getEntityType() === entityType) {
|
|
79
|
+
byIri.set(e.getIRI().toString(), e);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return [...byIri.values()];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// --- subclass indexes (asserted) ------------------------------------------
|
|
87
|
+
|
|
88
|
+
getSubClassAxiomsForSubClass(cls) {
|
|
89
|
+
return this.getAxiomsOfType(AxiomType.SUBCLASS_OF)
|
|
90
|
+
.filter(a => a.subClass && a.subClass.equals && a.subClass.equals(cls));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getSubClassAxiomsForSuperClass(cls) {
|
|
94
|
+
return this.getAxiomsOfType(AxiomType.SUBCLASS_OF)
|
|
95
|
+
.filter(a => a.superClass && a.superClass.equals && a.superClass.equals(cls));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// --- annotations -----------------------------------------------------------
|
|
99
|
+
|
|
100
|
+
addOntologyAnnotation(annotationAssertion) {
|
|
101
|
+
this._ontologyAnnotations.push(annotationAssertion);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
getOntologyAnnotations() { return this._ontologyAnnotations.slice(); }
|
|
105
|
+
|
|
106
|
+
getAnnotationsForSubject(iriString) {
|
|
107
|
+
return this.getAxiomsOfType(AxiomType.ANNOTATION_ASSERTION)
|
|
108
|
+
.filter(a => a.subject && a.subject.toString() === iriString);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** rdfs:label (or other annotation property) literal values for an entity. */
|
|
112
|
+
getAnnotationValues(entity, propertyIRI) {
|
|
113
|
+
return this.getAnnotationsForSubject(entity.getIRI().toString())
|
|
114
|
+
.filter(a => a.property.getIRI().toString() === propertyIRI)
|
|
115
|
+
.map(a => a.value);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
module.exports = { OWLOntology, OWLOntologyID };
|