Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | 8x 1550x 446x 446x 446x 25407x 25407x 25407x 25407x 25407x 11210x 4x 25407x 8x 8x 8x 2x 25407x 124x 124x 124x 1x 25407x 11210x 2x 2x 2x 25407x 3x 6x 5x 25407x 39x 4x 5x 25407x 4x 4x 1x 25407x 2x 2x 1x 436x 80x 80x 80x 78x 78x 13x 6x 11x 15x 436x 20x 20x 18x 18x 18x 2x 2x 436x 20x 22x 22x 22x 4x 4x 2x 436x 8x 8x 4x 4x 4x 4x 4x 2x 2x 436x 8x 8x 4x 4x 4x 4x 4x 8x 4x 436x 14x 14x 14x 14x 14x 14x 14x 6x 6x 6x 4x 14x 8x 8x 16x 8x 16x 8x 108x 108x 104x 104x 104x 99x 99x 17x | /**
* OWL 2 RL — Table 6: Class expression rules (cls-*)
*
* @see https://www.w3.org/TR/owl2-profiles/#Reasoning_in_OWL_2_RL_and_RDF_Graphs_using_Rules
* @see Table 6 — https://www.w3.org/TR/owl2-profiles/#tab-rules-classes
*/
import * as rdfjs from '@rdfjs/types';
import DataFactory from '@rdfjs/data-model';
import { TripleIndex } from '../../triple-index.js';
import { InferenceResult, infer } from '../../reasoner.js';
import { RDF, RDFS, OWL, ZERO, ONE, rdf, rdfs, owl } from '../vocabulary.js';
const { namedNode } = DataFactory;
function makeTriple(subject: rdfjs.Quad_Subject, predicate: rdfjs.Quad_Predicate, object: rdfjs.Quad_Object): rdfjs.Quad {
return DataFactory.quad(subject, predicate, object);
}
/**
* Axiomatic class triples (cls-thing, cls-nothing1).
*
* @see https://www.w3.org/TR/owl2-profiles/#tab-rules-classes
*/
export function* classAxioms(): Iterable<rdfjs.Quad> {
yield makeTriple(owl.Thing, rdf.type, owl.Class);
yield makeTriple(owl.Nothing, rdf.type, owl.Class);
// owl:NamedIndividual is a subclass of owl:Thing (OWL 2 meta-ontology).
// This lets cax-sco propagate rdf:type owl:Thing to all named individuals,
// which is required for prp-rflx (reflexive property assertions).
yield makeTriple(owl.NamedIndividual, rdfs.subClassOf, owl.Thing);
}
/**
* Single-quad class expression rules that fire once per incoming quad.
*
* Rules applied:
* - cls-nothing2: x type owl:Nothing → inconsistency
* - cls-hv1: x type c, c hasValue v on p → x p v
* - cls-hv2: c hasValue v on p, x p v → x type c
* - cls-svf2: c someValuesFrom owl:Thing on p, x p y → x type c
* - cls-oo: c oneOf list, u in list → u type c
* - cls-int2: c intersectionOf list, x type c → x type each component
* - cls-uni: c unionOf list, x type component → x type c
* - cls-com: c complementOf d, x type c AND x type d → inconsistency
*
* @see https://www.w3.org/TR/owl2-profiles/#tab-rules-classes
*/
export function* classSingleQuad(quad: rdfjs.Quad, index: TripleIndex): Iterable<InferenceResult> {
const { subject, predicate, object } = quad;
const predicateIri = predicate.value;
const subjectIri = subject.value;
const objectIri = object.value;
if (predicateIri === RDF.type) {
// cls-nothing2: x type owl:Nothing → inconsistency
if (objectIri === OWL.Nothing) {
yield infer(makeTriple(owl.Thing, rdfs.subClassOf, owl.Nothing), 'cls-nothing2', quad);
}
}
// cls-hv2: c hasValue v on p, x p v → x type c
// Fires for any quad x p v (not just rdf:type).
for (const restriction of index.getSubjects(OWL.hasValue, objectIri)) {
const propertiesOnRestriction = index.getObjects(OWL.onProperty, restriction.value);
for (const propertyTerm of propertiesOnRestriction) {
if (propertyTerm.value === predicateIri) {
yield infer(
makeTriple(subject, rdf.type, restriction as rdfjs.Quad_Object),
'cls-hv2',
quad,
makeTriple(restriction as rdfjs.Quad_Subject, namedNode(OWL.hasValue), object),
makeTriple(restriction as rdfjs.Quad_Subject, namedNode(OWL.onProperty), predicate),
);
}
}
}
// cls-svf2: c someValuesFrom owl:Thing on p, x p y → x type c
// Fires for any quad x p y (not just rdf:type).
for (const restriction of index.getSubjects(OWL.someValuesFrom, OWL.Thing)) {
const propertiesOnRestriction = index.getObjects(OWL.onProperty, restriction.value);
for (const propertyTerm of propertiesOnRestriction) {
if (propertyTerm.value === predicateIri) {
yield infer(
makeTriple(subject, rdf.type, restriction as rdfjs.Quad_Object),
'cls-svf2',
quad,
makeTriple(restriction as rdfjs.Quad_Subject, namedNode(OWL.someValuesFrom), owl.Thing),
makeTriple(restriction as rdfjs.Quad_Subject, namedNode(OWL.onProperty), predicate),
);
}
}
}
// cls-hv1: x type c, c hasValue v on p → x p v
if (predicateIri === RDF.type) {
for (const value of index.getObjects(OWL.hasValue, objectIri)) {
const propertiesOnRestriction = index.getObjects(OWL.onProperty, objectIri);
for (const propertyTerm of propertiesOnRestriction) {
yield infer(
makeTriple(subject, namedNode(propertyTerm.value), value),
'cls-hv1',
quad,
makeTriple(object as rdfjs.Quad_Subject, namedNode(OWL.hasValue), value),
makeTriple(object as rdfjs.Quad_Subject, namedNode(OWL.onProperty), propertyTerm),
);
}
}
}
// cls-oo: c oneOf list, u in list → u type c
if (predicateIri === OWL.oneOf) {
for (const member of walkRdfList(objectIri, index)) {
if (member.termType === 'NamedNode' || member.termType === 'BlankNode') {
yield infer(
makeTriple(member as rdfjs.Quad_Subject, rdf.type, subject as rdfjs.Quad_Object),
'cls-oo',
quad,
);
}
}
}
// cls-int2: c intersectionOf list, x type c → x type each component
if (predicateIri === OWL.intersectionOf) {
for (const instance of index.getSubjects(RDF.type, subjectIri)) {
for (const component of walkRdfList(objectIri, index)) {
yield infer(
makeTriple(instance as rdfjs.Quad_Subject, rdf.type, component),
'cls-int2',
quad,
makeTriple(instance as rdfjs.Quad_Subject, rdf.type, subject as rdfjs.Quad_Object),
);
}
}
}
// cls-uni: c unionOf list, x type component → x type c
if (predicateIri === OWL.unionOf) {
for (const component of walkRdfList(objectIri, index)) {
for (const instance of index.getSubjects(RDF.type, component.value)) {
yield infer(
makeTriple(instance as rdfjs.Quad_Subject, rdf.type, subject as rdfjs.Quad_Object),
'cls-uni',
quad,
makeTriple(instance as rdfjs.Quad_Subject, rdf.type, component),
);
}
}
}
// cls-com: c complementOf d, x type c AND x type d → inconsistency
if (predicateIri === OWL.complementOf) {
for (const instance of index.getSubjects(RDF.type, subjectIri)) {
if (index.has(RDF.type, instance.value, objectIri)) {
yield infer(
makeTriple(owl.Thing, rdfs.subClassOf, owl.Nothing),
'cls-com',
quad,
makeTriple(instance as rdfjs.Quad_Subject, rdf.type, subject as rdfjs.Quad_Object),
makeTriple(instance as rdfjs.Quad_Subject, rdf.type, object),
);
}
}
}
}
/**
* Join-based class expression rules that require scanning the full index.
*
* Rules applied:
* - cls-int1: c intersectionOf list, x type each component → x type c
* - cls-svf1: c someValuesFrom d on p (d ≠ owl:Thing), x p y, y type d → x type c
* - cls-avf: c allValuesFrom d on p, x type c, x p y → y type d
* - cls-maxc1: c maxCardinality "0" on p, x type c, x p y → inconsistency
* - cls-maxc2: c maxCardinality "1" on p, x type c, x p y1, x p y2 → y1 sameAs y2
* - cls-maxqc1: c maxQualifiedCardinality "0" on p scoped to d, x type c, x p y, y type d → inconsistency
* - cls-maxqc2: c maxQualifiedCardinality "0" on p scoped to owl:Thing, x type c, x p y → inconsistency
* - cls-maxqc3: c maxQualifiedCardinality "1" on p scoped to d, x p y1 y2 both typed d → y1 sameAs y2
* - cls-maxqc4: c maxQualifiedCardinality "1" on p scoped to owl:Thing, x p y1 y2 → y1 sameAs y2
*
* @see https://www.w3.org/TR/owl2-profiles/#tab-rules-classes
*/
export function* classJoin(index: TripleIndex): Iterable<InferenceResult> {
// cls-int1: c intersectionOf list, x type each component → x type c
for (const [classIri, listHeadNodes] of index.byPredSubj.get(OWL.intersectionOf) ?? []) {
for (const listHeadNode of listHeadNodes) {
const components = walkRdfList(listHeadNode.value, index);
if (components.length === 0) continue;
// Find candidates: typed as first component.
const candidates = index.getSubjects(RDF.type, components[0].value);
outer: for (const instance of candidates) {
for (let i = 1; i < components.length; i++) {
if (!index.has(RDF.type, instance.value, components[i].value)) continue outer;
}
yield infer(
makeTriple(instance as rdfjs.Quad_Subject, rdf.type, namedNode(classIri)),
'cls-int1',
makeTriple(namedNode(classIri), namedNode(OWL.intersectionOf), listHeadNode),
...components.map(component => makeTriple(instance as rdfjs.Quad_Subject, rdf.type, component)),
);
}
}
}
// cls-svf1: c someValuesFrom d on p (d != owl:Thing), x p y, y type d → x type c
for (const [classIri, fillerNodes] of index.byPredSubj.get(OWL.someValuesFrom) ?? []) {
for (const filler of fillerNodes) {
if (filler.value === OWL.Thing) continue;
const propertiesOnRestriction = index.getObjects(OWL.onProperty, classIri);
for (const propertyTerm of propertiesOnRestriction) {
for (const fillerInstance of index.getSubjects(RDF.type, filler.value)) {
for (const instance of index.getSubjects(propertyTerm.value, fillerInstance.value)) {
yield infer(
makeTriple(instance as rdfjs.Quad_Subject, rdf.type, namedNode(classIri)),
'cls-svf1',
makeTriple(namedNode(classIri), namedNode(OWL.someValuesFrom), filler),
makeTriple(namedNode(classIri), namedNode(OWL.onProperty), propertyTerm),
makeTriple(instance as rdfjs.Quad_Subject, propertyTerm as rdfjs.Quad_Predicate, fillerInstance),
makeTriple(fillerInstance as rdfjs.Quad_Subject, rdf.type, filler),
);
}
}
}
}
}
// cls-avf: c allValuesFrom d on p, x type c, x p y → y type d
for (const [classIri, fillerNodes] of index.byPredSubj.get(OWL.allValuesFrom) ?? []) {
for (const filler of fillerNodes) {
const propertiesOnRestriction = index.getObjects(OWL.onProperty, classIri);
for (const propertyTerm of propertiesOnRestriction) {
for (const instance of index.getSubjects(RDF.type, classIri)) {
for (const value of index.getObjects(propertyTerm.value, instance.value)) {
if (value.termType === 'NamedNode' || value.termType === 'BlankNode') {
yield infer(
makeTriple(value as rdfjs.Quad_Subject, rdf.type, filler),
'cls-avf',
makeTriple(namedNode(classIri), namedNode(OWL.allValuesFrom), filler),
makeTriple(namedNode(classIri), namedNode(OWL.onProperty), propertyTerm),
makeTriple(instance as rdfjs.Quad_Subject, rdf.type, namedNode(classIri)),
makeTriple(instance as rdfjs.Quad_Subject, propertyTerm as rdfjs.Quad_Predicate, value),
);
}
}
}
}
}
}
// cls-maxc1: c maxCardinality "0" on p, x type c, x p y → inconsistency
for (const [classIri, cardinalityNodes] of index.byPredSubj.get(OWL.maxCardinality) ?? []) {
for (const cardinality of cardinalityNodes) {
if (cardinality.value !== ZERO) continue;
const propertiesOnRestriction = index.getObjects(OWL.onProperty, classIri);
for (const propertyTerm of propertiesOnRestriction) {
for (const instance of index.getSubjects(RDF.type, classIri)) {
const values = index.getObjects(propertyTerm.value, instance.value);
if (values.size > 0) {
yield infer(
makeTriple(owl.Thing, rdfs.subClassOf, owl.Nothing),
'cls-maxc1',
makeTriple(namedNode(classIri), namedNode(OWL.maxCardinality), cardinality),
makeTriple(namedNode(classIri), namedNode(OWL.onProperty), propertyTerm),
makeTriple(instance as rdfjs.Quad_Subject, rdf.type, namedNode(classIri)),
...[...values].map(value => makeTriple(instance as rdfjs.Quad_Subject, propertyTerm as rdfjs.Quad_Predicate, value)),
);
}
}
}
}
}
// cls-maxc2: c maxCardinality "1" on p, x type c, x p y1, x p y2 → y1 sameAs y2
for (const [classIri, cardinalityNodes] of index.byPredSubj.get(OWL.maxCardinality) ?? []) {
for (const cardinality of cardinalityNodes) {
if (cardinality.value !== ONE) continue;
const propertiesOnRestriction = index.getObjects(OWL.onProperty, classIri);
for (const propertyTerm of propertiesOnRestriction) {
for (const instance of index.getSubjects(RDF.type, classIri)) {
const values = [...index.getObjects(propertyTerm.value, instance.value)];
for (let i = 0; i < values.length; i++) {
for (let j = i + 1; j < values.length; j++) {
yield infer(
makeTriple(values[i] as rdfjs.Quad_Subject, owl.sameAs, values[j]),
'cls-maxc2',
makeTriple(namedNode(classIri), namedNode(OWL.maxCardinality), cardinality),
makeTriple(namedNode(classIri), namedNode(OWL.onProperty), propertyTerm),
makeTriple(instance as rdfjs.Quad_Subject, rdf.type, namedNode(classIri)),
makeTriple(instance as rdfjs.Quad_Subject, propertyTerm as rdfjs.Quad_Predicate, values[i]),
makeTriple(instance as rdfjs.Quad_Subject, propertyTerm as rdfjs.Quad_Predicate, values[j]),
);
}
}
}
}
}
}
// cls-maxqc1/2/3/4: qualified max cardinality constraints
for (const [classIri, cardinalityNodes] of index.byPredSubj.get(OWL.maxQualifiedCardinality) ?? []) {
for (const cardinality of cardinalityNodes) {
const propertiesOnRestriction = index.getObjects(OWL.onProperty, classIri);
const scopedClasses = index.getObjects(OWL.onClass, classIri);
for (const propertyTerm of propertiesOnRestriction) {
for (const scopedClass of scopedClasses) {
const isScopedToOwlThing = scopedClass.value === OWL.Thing;
if (cardinality.value === ZERO) {
// cls-maxqc1: qualifiedCardinality "0" on d, x type c, x p y, y type d → inconsistency
// cls-maxqc2: qualifiedCardinality "0" on owl:Thing, x type c, x p y → inconsistency
for (const instance of index.getSubjects(RDF.type, classIri)) {
for (const value of index.getObjects(propertyTerm.value, instance.value)) {
if (isScopedToOwlThing || index.has(RDF.type, value.value, scopedClass.value)) {
yield infer(
makeTriple(owl.Thing, rdfs.subClassOf, owl.Nothing),
isScopedToOwlThing ? 'cls-maxqc2' : 'cls-maxqc1',
makeTriple(namedNode(classIri), namedNode(OWL.maxQualifiedCardinality), cardinality),
makeTriple(namedNode(classIri), namedNode(OWL.onProperty), propertyTerm),
makeTriple(namedNode(classIri), namedNode(OWL.onClass), scopedClass),
makeTriple(instance as rdfjs.Quad_Subject, rdf.type, namedNode(classIri)),
makeTriple(instance as rdfjs.Quad_Subject, propertyTerm as rdfjs.Quad_Predicate, value),
...(isScopedToOwlThing ? [] : [makeTriple(value as rdfjs.Quad_Subject, rdf.type, scopedClass)]),
);
}
}
}
}
if (cardinality.value === ONE) {
// cls-maxqc3/4: two qualified values → sameAs
for (const instance of index.getSubjects(RDF.type, classIri)) {
const qualifiedValues = [...index.getObjects(propertyTerm.value, instance.value)]
.filter(value => isScopedToOwlThing || index.has(RDF.type, value.value, scopedClass.value));
for (let i = 0; i < qualifiedValues.length; i++) {
for (let j = i + 1; j < qualifiedValues.length; j++) {
yield infer(
makeTriple(qualifiedValues[i] as rdfjs.Quad_Subject, owl.sameAs, qualifiedValues[j]),
isScopedToOwlThing ? 'cls-maxqc4' : 'cls-maxqc3',
makeTriple(namedNode(classIri), namedNode(OWL.maxQualifiedCardinality), cardinality),
makeTriple(namedNode(classIri), namedNode(OWL.onProperty), propertyTerm),
makeTriple(namedNode(classIri), namedNode(OWL.onClass), scopedClass),
makeTriple(instance as rdfjs.Quad_Subject, rdf.type, namedNode(classIri)),
makeTriple(instance as rdfjs.Quad_Subject, propertyTerm as rdfjs.Quad_Predicate, qualifiedValues[i]),
makeTriple(instance as rdfjs.Quad_Subject, propertyTerm as rdfjs.Quad_Predicate, qualifiedValues[j]),
);
}
}
}
}
}
}
}
}
}
function walkRdfList(listHeadIri: string, index: TripleIndex): rdfjs.Quad_Object[] {
const firstNodes = index.getObjects(RDF.first, listHeadIri);
if (firstNodes.size === 0) return [];
const [first] = firstNodes;
const restNodes = index.getObjects(RDF.rest, listHeadIri);
if (restNodes.size === 0) return [first];
const [rest] = restNodes;
if (rest.value === RDF.nil) return [first];
return [first, ...walkRdfList(rest.value, index)];
}
|