@faubulous/mentor-rdf 2.2.0 → 2.2.1
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/dist/index.js +93 -1
- package/dist/index.js.map +2 -2
- package/dist/rdf/reasoners/rdfs-reasoner.d.ts +38 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4842,6 +4842,18 @@ var RdfsReasoner = class extends SkosReasoner {
|
|
|
4842
4842
|
this.classes = /* @__PURE__ */ new Set();
|
|
4843
4843
|
this.properties = /* @__PURE__ */ new Set();
|
|
4844
4844
|
this.individuals = /* @__PURE__ */ new Set();
|
|
4845
|
+
/**
|
|
4846
|
+
* The super properties of each property, as asserted with `rdfs:subPropertyOf`.
|
|
4847
|
+
*/
|
|
4848
|
+
this._superProperties = /* @__PURE__ */ new Map();
|
|
4849
|
+
/**
|
|
4850
|
+
* The ranges asserted for each property.
|
|
4851
|
+
*/
|
|
4852
|
+
this._ranges = /* @__PURE__ */ new Map();
|
|
4853
|
+
/**
|
|
4854
|
+
* The domains asserted for each property.
|
|
4855
|
+
*/
|
|
4856
|
+
this._domains = /* @__PURE__ */ new Map();
|
|
4845
4857
|
}
|
|
4846
4858
|
isIgnoredNode(term) {
|
|
4847
4859
|
switch (term.value) {
|
|
@@ -4866,6 +4878,47 @@ var RdfsReasoner = class extends SkosReasoner {
|
|
|
4866
4878
|
for (let individual of individuals) {
|
|
4867
4879
|
this.store.add(quad2(individual, rdf.type, owl.NamedIndividual, this.targetGraph));
|
|
4868
4880
|
}
|
|
4881
|
+
this._inferInheritedRangesAndDomains();
|
|
4882
|
+
}
|
|
4883
|
+
/**
|
|
4884
|
+
* Infers the ranges and domains that properties inherit from their super properties
|
|
4885
|
+
* (OWL 2 RL rules scm-rng2 and scm-dom2), following `rdfs:subPropertyOf` chains.
|
|
4886
|
+
*/
|
|
4887
|
+
_inferInheritedRangesAndDomains() {
|
|
4888
|
+
for (const { property, superProperties } of this._superProperties.values()) {
|
|
4889
|
+
for (const superProperty of this._getAncestorProperties(property.value, superProperties)) {
|
|
4890
|
+
for (const range of this._ranges.get(superProperty) ?? []) {
|
|
4891
|
+
this.store.add(quad2(property, rdfs.range, range, this.targetGraph));
|
|
4892
|
+
}
|
|
4893
|
+
for (const domain of this._domains.get(superProperty) ?? []) {
|
|
4894
|
+
this.store.add(quad2(property, rdfs.domain, domain, this.targetGraph));
|
|
4895
|
+
}
|
|
4896
|
+
}
|
|
4897
|
+
}
|
|
4898
|
+
}
|
|
4899
|
+
/**
|
|
4900
|
+
* Gets the transitive super properties of a property, nearest first. Cycles in the
|
|
4901
|
+
* property hierarchy are followed only once.
|
|
4902
|
+
* @param property The IRI or blank node id of a property.
|
|
4903
|
+
* @param superProperties The direct super properties of the property.
|
|
4904
|
+
* @returns The IRIs of all super properties, excluding the property itself.
|
|
4905
|
+
*/
|
|
4906
|
+
_getAncestorProperties(property, superProperties) {
|
|
4907
|
+
const result = [];
|
|
4908
|
+
const visited = /* @__PURE__ */ new Set([property]);
|
|
4909
|
+
const queue = [...superProperties];
|
|
4910
|
+
while (queue.length > 0) {
|
|
4911
|
+
const current = queue.shift();
|
|
4912
|
+
if (visited.has(current)) {
|
|
4913
|
+
continue;
|
|
4914
|
+
}
|
|
4915
|
+
visited.add(current);
|
|
4916
|
+
result.push(current);
|
|
4917
|
+
for (const next of this._superProperties.get(current)?.superProperties ?? []) {
|
|
4918
|
+
queue.push(next);
|
|
4919
|
+
}
|
|
4920
|
+
}
|
|
4921
|
+
return result;
|
|
4869
4922
|
}
|
|
4870
4923
|
resetState() {
|
|
4871
4924
|
super.resetState();
|
|
@@ -4873,6 +4926,9 @@ var RdfsReasoner = class extends SkosReasoner {
|
|
|
4873
4926
|
this.classes.clear();
|
|
4874
4927
|
this.properties.clear();
|
|
4875
4928
|
this.individuals.clear();
|
|
4929
|
+
this._superProperties.clear();
|
|
4930
|
+
this._ranges.clear();
|
|
4931
|
+
this._domains.clear();
|
|
4876
4932
|
}
|
|
4877
4933
|
applyInference(quad5) {
|
|
4878
4934
|
super.applyInference(quad5);
|
|
@@ -4966,13 +5022,49 @@ var RdfsReasoner = class extends SkosReasoner {
|
|
|
4966
5022
|
}
|
|
4967
5023
|
return;
|
|
4968
5024
|
}
|
|
4969
|
-
case rdfs.
|
|
5025
|
+
case rdfs.subPropertyOf.value: {
|
|
5026
|
+
this._addSuperProperty(s, o);
|
|
5027
|
+
return;
|
|
5028
|
+
}
|
|
5029
|
+
case rdfs.range.value: {
|
|
5030
|
+
this.assertProperty(s);
|
|
5031
|
+
this._addToList(this._ranges, s.value, o);
|
|
5032
|
+
return;
|
|
5033
|
+
}
|
|
4970
5034
|
case rdfs.domain.value: {
|
|
4971
5035
|
this.assertProperty(s);
|
|
5036
|
+
this._addToList(this._domains, s.value, o);
|
|
4972
5037
|
return;
|
|
4973
5038
|
}
|
|
4974
5039
|
}
|
|
4975
5040
|
}
|
|
5041
|
+
/**
|
|
5042
|
+
* Records that a property is a sub property of another property.
|
|
5043
|
+
* @param property The sub property.
|
|
5044
|
+
* @param superProperty The super property.
|
|
5045
|
+
*/
|
|
5046
|
+
_addSuperProperty(property, superProperty) {
|
|
5047
|
+
let entry = this._superProperties.get(property.value);
|
|
5048
|
+
if (!entry) {
|
|
5049
|
+
entry = { property, superProperties: /* @__PURE__ */ new Set() };
|
|
5050
|
+
this._superProperties.set(property.value, entry);
|
|
5051
|
+
}
|
|
5052
|
+
entry.superProperties.add(superProperty.value);
|
|
5053
|
+
}
|
|
5054
|
+
/**
|
|
5055
|
+
* Adds a value to the list stored under a key.
|
|
5056
|
+
* @param map The map of lists.
|
|
5057
|
+
* @param key The key of the list.
|
|
5058
|
+
* @param value The value to add.
|
|
5059
|
+
*/
|
|
5060
|
+
_addToList(map, key, value) {
|
|
5061
|
+
const list = map.get(key);
|
|
5062
|
+
if (list) {
|
|
5063
|
+
list.push(value);
|
|
5064
|
+
} else {
|
|
5065
|
+
map.set(key, [value]);
|
|
5066
|
+
}
|
|
5067
|
+
}
|
|
4976
5068
|
};
|
|
4977
5069
|
|
|
4978
5070
|
// src/rdf/reasoners/shacl-reasoner.ts
|