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 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 | 8x 8x 590x 25408x 25408x 25408x 25408x 25408x 2x 25408x 2x 1x 25408x 37x 36x 25408x 21x 25408x 19x 25408x 19x 25408x 3x 2x 25408x 3x 2x 25408x 2x 25408x 11211x 28x 3x 2x 11211x 2x 1x 444x 24696x 30x 30x 28x 36x 36x 51x 18x 16x 16x 16x 12x 4x 441x 24693x 27x 27x 25x 25x 33x 33x 8x 8x 8x 8x 8x 7x 441x 24693x 16x 16x 14x 22x 22x 22x 22x 26x 4x 441x 24693x 7x 7x 4x 4x 8x 8x 10x 6x 2x 441x 24693x 8x 8x 6x 10x 10x 8x 441x 16x 16x 16x 16x 14x 14x 14x 12x 12x 12x 4x 8x 6x 441x 30x 11x 11x 11x 22x 11x 11x 11x 11x 9x 9x 9x 7x 7x 7x 2x 5x 3x 441x 24693x 16x 16x 14x 14x 22x 22x 8x 8x 8x 8x 8x 7x 441x 16x 16x 16x 16x 12x 6x 12x 6x 6x 441x 16x 16x 16x 2x 441x 26x 26x 26x 26x 46x 20x 20x 20x 16x 441x 24693x 12x 12x 12x 6x 4x 12x 6x 4x 446x 4014x 446x 104x 104x 100x 100x 100x 92x 92x 35x 14x 8x 6x 8x 6x 8x 20x 16x 16x 16x 14x 14x 14x 14x 12x 12x 14x 14x 16x | /**
* OWL 2 RL — Table 5: Property semantics rules (prp-*)
*
* @see https://www.w3.org/TR/owl2-profiles/#Reasoning_in_OWL_2_RL_and_RDF_Graphs_using_Rules
* @see Table 5 — https://www.w3.org/TR/owl2-profiles/#tab-rules-properties
*/
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, rdf, rdfs, owl } from '../vocabulary.js';
const { namedNode } = DataFactory;
// Built-in annotation properties (prp-ap)
// @see https://www.w3.org/TR/owl2-profiles/#tab-rules-properties
const BUILTIN_ANNOTATION_PROPERTIES = [
RDFS.label, RDFS.comment, RDFS.seeAlso, RDFS.isDefinedBy,
OWL.deprecated, OWL.versionInfo, OWL.priorVersion,
OWL.backwardCompatibleWith, OWL.incompatibleWith,
];
function makeTriple(subject: rdfjs.Quad_Subject, predicate: rdfjs.Quad_Predicate, object: rdfjs.Quad_Object): rdfjs.Quad {
return DataFactory.quad(subject, predicate, object);
}
/**
* Single-quad property rules that fire once per incoming quad.
*
* Rules applied:
* - prp-dom: p domain c, x p y → x type c
* - prp-rng: p range c, x p y → y type c
* - prp-symp: p type SymmetricProperty, x p y → y p x
* - prp-spo1: p1 subPropertyOf p2, x p1 y → x p2 y
* - prp-eqp1: p1 equivalentProperty p2, x p1 y → x p2 y
* - prp-eqp2: p1 equivalentProperty p2, x p2 y → x p1 y
* - prp-inv1: p1 inverseOf p2, x p1 y → y p2 x
* - prp-inv2: p1 inverseOf p2, x p2 y → y p1 x
* - prp-irp: p type IrreflexiveProperty, x p x → inconsistency
*
* Rules prp-npa1 and prp-npa2 are handled as join rules in {@link propertyJoin}.
*
* @see https://www.w3.org/TR/owl2-profiles/#tab-rules-properties
*/
export function* propertySingleQuad(quad: rdfjs.Quad, index: TripleIndex): Iterable<InferenceResult> {
const { subject, predicate, object } = quad;
const predicateIri = predicate.value;
const subjectIri = subject.value;
const objectIri = object.value;
// prp-dom: p domain c, x p y → x type c
for (const domainClass of index.getObjects(RDFS.domain, predicateIri)) {
yield infer(
makeTriple(subject, rdf.type, domainClass),
'prp-dom',
quad,
makeTriple(predicate, namedNode(RDFS.domain), domainClass),
);
}
// prp-rng: p range c, x p y → y type c
for (const rangeClass of index.getObjects(RDFS.range, predicateIri)) {
if (object.termType === 'NamedNode' || object.termType === 'BlankNode') {
yield infer(
makeTriple(object as rdfjs.Quad_Subject, rdf.type, rangeClass),
'prp-rng',
quad,
makeTriple(predicate, namedNode(RDFS.range), rangeClass),
);
}
}
// prp-symp: p type SymmetricProperty, x p y → y p x
if (index.has(RDF.type, predicateIri, OWL.SymmetricProperty)) {
if (object.termType === 'NamedNode' || object.termType === 'BlankNode') {
yield infer(
makeTriple(object as rdfjs.Quad_Subject, predicate, subject as rdfjs.Quad_Object),
'prp-symp',
quad,
makeTriple(predicate, rdf.type, namedNode(OWL.SymmetricProperty)),
);
}
}
// prp-spo1: p1 subPropertyOf p2, x p1 y → x p2 y
for (const superProperty of index.getObjects(RDFS.subPropertyOf, predicateIri)) {
yield infer(
makeTriple(subject, namedNode(superProperty.value), object),
'prp-spo1',
quad,
makeTriple(predicate, namedNode(RDFS.subPropertyOf), superProperty),
);
}
// prp-eqp1/2: p1 equivalentProperty p2, x p1 y → x p2 y (and vice versa)
for (const equivalentProperty of index.getObjects(OWL.equivalentProperty, predicateIri)) {
yield infer(
makeTriple(subject, namedNode(equivalentProperty.value), object),
'prp-eqp1',
quad,
makeTriple(predicate, namedNode(OWL.equivalentProperty), equivalentProperty),
);
}
for (const equivalentProperty of index.getSubjects(OWL.equivalentProperty, predicateIri)) {
yield infer(
makeTriple(subject, equivalentProperty as rdfjs.Quad_Predicate, object),
'prp-eqp2',
quad,
makeTriple(equivalentProperty as rdfjs.Quad_Subject, namedNode(OWL.equivalentProperty), predicate),
);
}
// prp-inv1: p1 inverseOf p2, x p1 y → y p2 x
for (const inverseProperty of index.getObjects(OWL.inverseOf, predicateIri)) {
if (object.termType === 'NamedNode' || object.termType === 'BlankNode') {
yield infer(
makeTriple(object as rdfjs.Quad_Subject, namedNode(inverseProperty.value), subject as rdfjs.Quad_Object),
'prp-inv1',
quad,
makeTriple(predicate, namedNode(OWL.inverseOf), inverseProperty),
);
}
}
// prp-inv2: p1 inverseOf p2, x p2 y → y p1 x
for (const inverseProperty of index.getSubjects(OWL.inverseOf, predicateIri)) {
if (object.termType === 'NamedNode' || object.termType === 'BlankNode') {
yield infer(
makeTriple(object as rdfjs.Quad_Subject, inverseProperty as rdfjs.Quad_Predicate, subject as rdfjs.Quad_Object),
'prp-inv2',
quad,
makeTriple(inverseProperty as rdfjs.Quad_Subject, namedNode(OWL.inverseOf), predicate),
);
}
}
// prp-irp: p type IrreflexiveProperty, x p x → inconsistency
if (subjectIri === objectIri && index.has(RDF.type, predicateIri, OWL.IrreflexiveProperty)) {
yield infer(
makeTriple(owl.Thing, rdfs.subClassOf, owl.Nothing),
'prp-irp',
quad,
makeTriple(predicate, rdf.type, namedNode(OWL.IrreflexiveProperty)),
);
}
// prp-rflx: p type ReflexiveProperty, x type owl:Thing → x p x
if (predicateIri === RDF.type) {
if (objectIri === OWL.Thing) {
for (const reflexiveProp of index.getSubjects(RDF.type, OWL.ReflexiveProperty)) {
if (subject.termType === 'NamedNode' || subject.termType === 'BlankNode') {
yield infer(
makeTriple(subject, reflexiveProp as rdfjs.Quad_Predicate, subject as rdfjs.Quad_Object),
'prp-rflx',
quad,
makeTriple(reflexiveProp as rdfjs.Quad_Subject, rdf.type, namedNode(OWL.ReflexiveProperty)),
);
}
}
}
if (objectIri === OWL.ReflexiveProperty) {
for (const thing of index.getSubjects(RDF.type, OWL.Thing)) {
yield infer(
makeTriple(thing as rdfjs.Quad_Subject, subject as rdfjs.Quad_Predicate, thing as rdfjs.Quad_Object),
'prp-rflx',
quad,
makeTriple(thing as rdfjs.Quad_Subject, rdf.type, namedNode(OWL.Thing)),
);
}
}
}
// prp-npa1: _x assertionProperty p, _x sourceIndividual s, _x targetIndividual o, s p o → inconsistency
// prp-npa2: _x assertionProperty p, _x sourceIndividual s, _x targetValue v, s p v → inconsistency
// These are handled more efficiently as join rules.
}
/**
* Join-based property rules that require scanning the full index.
*
* Rules applied:
* - prp-fp: p FunctionalProperty, x p y1, x p y2 → y1 sameAs y2
* - prp-fp-dif: p FunctionalProperty, Y1 p X1, Y2 p X2, X1 differentFrom X2 → Y1 differentFrom Y2
* - prp-ifp: p InverseFunctionalProperty, y1 p x, y2 p x → y1 sameAs y2
* - prp-ifp-dif: p InverseFunctionalProperty, Y1 p X1, Y2 p X2, Y1 differentFrom Y2 → X1 differentFrom X2
* - prp-trp: p TransitiveProperty, x p y, y p z → x p z
* - prp-asyp: p AsymmetricProperty, x p y, y p x → inconsistency
* - prp-pdw: p1 propertyDisjointWith p2, x p1 y, x p2 y → inconsistency
* - prp-adp: AllDisjointProperties members list, x p1 y, x p2 y → inconsistency
* - prp-spo2: p propertyChainAxiom list, chain steps → direct triple
* - scm-chain-trans: p propertyChainAxiom [p, p] → p type TransitiveProperty
* - prp-key: c hasKey list, x type c, y type c, all key values equal → x sameAs y
* - prp-npa1: NegativePropertyAssertion + matching triple → inconsistency
* - prp-npa2: NegativePropertyAssertion + matching data value → inconsistency
*
* @see https://www.w3.org/TR/owl2-profiles/#tab-rules-properties
*/
export function* propertyJoin(index: TripleIndex): Iterable<InferenceResult> {
// prp-fp: p FunctionalProperty, x p y1, x p y2 → y1 sameAs y2
for (const [propertyIri] of index.byPredSubj.get(RDF.type) ?? []) {
if (!index.has(RDF.type, propertyIri, OWL.FunctionalProperty)) continue;
const bySubject = index.byPredSubj.get(propertyIri);
if (!bySubject) continue;
for (const [subjectIri, objects] of bySubject) {
const objectArray = [...objects];
for (let i = 0; i < objectArray.length; i++) {
for (let j = i + 1; j < objectArray.length; j++) {
if (objectArray[i].value !== objectArray[j].value) {
// dt-diff: if both are literals they denote distinct values → inconsistency
const firstAssertion = makeTriple(namedNode(subjectIri), namedNode(propertyIri), objectArray[i]);
const secondAssertion = makeTriple(namedNode(subjectIri), namedNode(propertyIri), objectArray[j]);
if (objectArray[i].termType === 'Literal' && objectArray[j].termType === 'Literal') {
yield infer(
makeTriple(owl.Thing, rdfs.subClassOf, owl.Nothing),
'dt-diff',
makeTriple(namedNode(propertyIri), rdf.type, namedNode(OWL.FunctionalProperty)),
firstAssertion,
secondAssertion,
);
} else {
yield infer(
makeTriple(objectArray[i] as rdfjs.Quad_Subject, owl.sameAs, objectArray[j]),
'prp-fp',
makeTriple(namedNode(propertyIri), rdf.type, namedNode(OWL.FunctionalProperty)),
firstAssertion,
secondAssertion,
);
}
}
}
}
}
}
// prp-fp contrapositive: p FunctionalProperty, Y1 p X1, Y2 p X2, X1 differentFrom X2 → Y1 differentFrom Y2
for (const [propertyIri] of index.byPredSubj.get(RDF.type) ?? []) {
if (!index.has(RDF.type, propertyIri, OWL.FunctionalProperty)) continue;
const bySubject = index.byPredSubj.get(propertyIri);
if (!bySubject) continue;
const entries = [...bySubject.entries()];
for (let i = 0; i < entries.length; i++) {
const [y1Iri, x1Set] = entries[i];
for (let j = i + 1; j < entries.length; j++) {
const [y2Iri, x2Set] = entries[j];
for (const x1 of x1Set) {
for (const x2 of x2Set) {
const diffTriple = index.has(OWL.differentFrom, x1.value, x2.value)
? makeTriple(x1 as rdfjs.Quad_Subject, owl.differentFrom, x2)
: index.has(OWL.differentFrom, x2.value, x1.value)
? makeTriple(x2 as rdfjs.Quad_Subject, owl.differentFrom, x1)
: null;
if (diffTriple) {
yield infer(
makeTriple(namedNode(y1Iri), owl.differentFrom, namedNode(y2Iri)),
'prp-fp-dif',
makeTriple(namedNode(propertyIri), rdf.type, namedNode(OWL.FunctionalProperty)),
makeTriple(namedNode(y1Iri), namedNode(propertyIri), x1),
makeTriple(namedNode(y2Iri), namedNode(propertyIri), x2),
diffTriple,
);
}
}
}
}
}
}
// prp-ifp: p InverseFunctionalProperty, y1 p x, y2 p x → y1 sameAs y2
for (const [propertyIri] of index.byPredSubj.get(RDF.type) ?? []) {
if (!index.has(RDF.type, propertyIri, OWL.InverseFunctionalProperty)) continue;
const byObject = index.byPredObj.get(propertyIri);
if (!byObject) continue;
for (const [objectIri, subjects] of byObject) {
const subjectArray = [...subjects];
const firstSubject = subjectArray[0] as rdfjs.Quad_Subject;
const objectTerm = [...index.getObjects(propertyIri, firstSubject.value)].find(obj => obj.value === objectIri) as rdfjs.Quad_Object;
for (let i = 0; i < subjectArray.length; i++) {
for (let j = i + 1; j < subjectArray.length; j++) {
yield infer(
makeTriple(subjectArray[i] as rdfjs.Quad_Subject, owl.sameAs, subjectArray[j] as rdfjs.Quad_Object),
'prp-ifp',
makeTriple(subjectArray[i] as rdfjs.Quad_Subject, namedNode(propertyIri), objectTerm),
makeTriple(subjectArray[j] as rdfjs.Quad_Subject, namedNode(propertyIri), objectTerm),
);
}
}
}
}
// prp-trp: p TransitiveProperty, x p y, y p z → x p z
for (const [propertyIri] of index.byPredSubj.get(RDF.type) ?? []) {
if (!index.has(RDF.type, propertyIri, OWL.TransitiveProperty)) continue;
const bySubject = index.byPredSubj.get(propertyIri);
if (!bySubject) continue;
const propertyTerm = namedNode(propertyIri);
for (const [subjectIri, intermediates] of bySubject) {
const subjectTerm = namedNode(subjectIri);
for (const intermediate of intermediates) {
for (const transitiveTarget of index.getObjects(propertyIri, intermediate.value)) {
if (transitiveTarget.value !== subjectIri) {
yield infer(
makeTriple(subjectTerm, propertyTerm, transitiveTarget),
'prp-trp',
makeTriple(subjectTerm, propertyTerm, intermediate),
makeTriple(intermediate as rdfjs.Quad_Subject, propertyTerm, transitiveTarget),
);
}
}
}
}
}
// prp-asyp: p AsymmetricProperty, x p y, y p x → inconsistency
for (const [propertyIri] of index.byPredSubj.get(RDF.type) ?? []) {
if (!index.has(RDF.type, propertyIri, OWL.AsymmetricProperty)) continue;
const bySubject = index.byPredSubj.get(propertyIri);
if (!bySubject) continue;
for (const [subjectIri, objects] of bySubject) {
for (const object of objects) {
if (index.has(propertyIri, object.value, subjectIri)) {
yield infer(
makeTriple(owl.Thing, rdfs.subClassOf, owl.Nothing),
'prp-asyp',
makeTriple(namedNode(subjectIri), namedNode(propertyIri), object),
makeTriple(object as rdfjs.Quad_Subject, namedNode(propertyIri), namedNode(subjectIri)),
);
}
}
}
}
// prp-pdw: p1 propertyDisjointWith p2, x p1 y, x p2 z
// → inconsistency if y = z (same object in both relations)
// → y differentFrom z if y ≠ z (objects in disjoint relations must be distinct)
for (const [firstPropertyIri, disjointProperties] of index.byPredSubj.get(OWL.propertyDisjointWith) ?? []) {
for (const disjointProperty of disjointProperties) {
const secondPropertyIri = disjointProperty.value;
const bySubjectForFirst = index.byPredSubj.get(firstPropertyIri);
if (!bySubjectForFirst) continue;
for (const [subjectIri, firstObjects] of bySubjectForFirst) {
const secondObjects = index.byPredSubj.get(secondPropertyIri)?.get(subjectIri);
if (!secondObjects) continue;
for (const firstObject of firstObjects) {
for (const secondObject of secondObjects) {
if (firstObject.value === secondObject.value) {
yield infer(
makeTriple(owl.Thing, rdfs.subClassOf, owl.Nothing),
'prp-pdw',
makeTriple(namedNode(firstPropertyIri), namedNode(OWL.propertyDisjointWith), namedNode(secondPropertyIri)),
makeTriple(namedNode(subjectIri), namedNode(firstPropertyIri), firstObject),
makeTriple(namedNode(subjectIri), namedNode(secondPropertyIri), secondObject),
);
} else if (
(firstObject.termType === 'NamedNode' || firstObject.termType === 'BlankNode') &&
(secondObject.termType === 'NamedNode' || secondObject.termType === 'BlankNode')
) {
yield infer(
makeTriple(firstObject as rdfjs.Quad_Subject, owl.differentFrom, secondObject),
'prp-pdw',
makeTriple(namedNode(firstPropertyIri), namedNode(OWL.propertyDisjointWith), namedNode(secondPropertyIri)),
makeTriple(namedNode(subjectIri), namedNode(firstPropertyIri), firstObject),
makeTriple(namedNode(subjectIri), namedNode(secondPropertyIri), secondObject),
);
}
}
}
}
}
}
// prp-adp: AllDisjointProperties members list
for (const [allDisjointIri, listHeadNodes] of index.byPredSubj.get(OWL.members) ?? []) {
if (!index.has(RDF.type, allDisjointIri, OWL.AllDisjointProperties)) continue;
for (const listHeadNode of listHeadNodes) {
const memberProperties = walkRdfList(listHeadNode.value, index);
for (let i = 0; i < memberProperties.length; i++) {
for (let j = i + 1; j < memberProperties.length; j++) {
const firstPropertyIri = memberProperties[i].value;
const secondPropertyIri = memberProperties[j].value;
const bySubjectForFirst = index.byPredSubj.get(firstPropertyIri);
if (!bySubjectForFirst) continue;
for (const [subjectIri, firstObjects] of bySubjectForFirst) {
const secondObjects = index.byPredSubj.get(secondPropertyIri)?.get(subjectIri);
if (!secondObjects) continue;
for (const firstObject of firstObjects) {
for (const secondObject of secondObjects) {
if (firstObject.value === secondObject.value) {
yield infer(
makeTriple(owl.Thing, rdfs.subClassOf, owl.Nothing),
'prp-adp',
makeTriple(namedNode(allDisjointIri), rdf.type, namedNode(OWL.AllDisjointProperties)),
makeTriple(namedNode(allDisjointIri), namedNode(OWL.members), listHeadNode),
makeTriple(namedNode(subjectIri), namedNode(firstPropertyIri), firstObject),
makeTriple(namedNode(subjectIri), namedNode(secondPropertyIri), secondObject),
);
} else if (
(firstObject.termType === 'NamedNode' || firstObject.termType === 'BlankNode') &&
(secondObject.termType === 'NamedNode' || secondObject.termType === 'BlankNode')
) {
yield infer(
makeTriple(firstObject as rdfjs.Quad_Subject, owl.differentFrom, secondObject),
'prp-adp',
makeTriple(namedNode(allDisjointIri), rdf.type, namedNode(OWL.AllDisjointProperties)),
makeTriple(namedNode(allDisjointIri), namedNode(OWL.members), listHeadNode),
makeTriple(namedNode(subjectIri), namedNode(firstPropertyIri), firstObject),
makeTriple(namedNode(subjectIri), namedNode(secondPropertyIri), secondObject),
);
}
}
}
}
}
}
}
}
// prp-ifp contrapositive: p InverseFunctionalProperty, Y1 p X1, Y2 p X2, Y1 differentFrom Y2 → X1 differentFrom X2
for (const [propertyIri] of index.byPredSubj.get(RDF.type) ?? []) {
if (!index.has(RDF.type, propertyIri, OWL.InverseFunctionalProperty)) continue;
const byObject = index.byPredObj.get(propertyIri);
if (!byObject) continue;
const entries = [...byObject.entries()];
for (let i = 0; i < entries.length; i++) {
const [x1Iri, y1Set] = entries[i];
for (let j = i + 1; j < entries.length; j++) {
const [x2Iri, y2Set] = entries[j];
for (const y1 of y1Set) {
for (const y2 of y2Set) {
const diffTriple = index.has(OWL.differentFrom, y1.value, y2.value)
? makeTriple(y1 as rdfjs.Quad_Subject, owl.differentFrom, y2)
: index.has(OWL.differentFrom, y2.value, y1.value)
? makeTriple(y2 as rdfjs.Quad_Subject, owl.differentFrom, y1)
: null;
if (diffTriple) {
yield infer(
makeTriple(namedNode(x1Iri), owl.differentFrom, namedNode(x2Iri)),
'prp-ifp-dif',
makeTriple(y1 as rdfjs.Quad_Subject, namedNode(propertyIri), namedNode(x1Iri)),
makeTriple(y2 as rdfjs.Quad_Subject, namedNode(propertyIri), namedNode(x2Iri)),
diffTriple,
);
}
}
}
}
}
}
// prp-spo2: p propertyChainAxiom list, chain steps → direct triple
for (const [propertyIri, listHeadNodes] of index.byPredSubj.get(OWL.propertyChainAxiom) ?? []) {
const propertyTerm = namedNode(propertyIri);
for (const listHeadNode of listHeadNodes) {
const chainProperties = walkRdfList(listHeadNode.value, index);
if (chainProperties.length < 2) continue;
for (const start of (index.byPredSubj.get(chainProperties[0].value) ?? new Map())) {
const [startSubjectIri] = start as [string, Set<rdfjs.Quad_Object>];
const reachableEnds = followPropertyChainWithPath(startSubjectIri, chainProperties.map(chainProperty => chainProperty.value), 0, index);
for (const { endIri, path } of reachableEnds) {
yield infer(
makeTriple(namedNode(startSubjectIri), propertyTerm, namedNode(endIri)),
'prp-spo2',
makeTriple(namedNode(propertyIri), namedNode(OWL.propertyChainAxiom), listHeadNode),
...path,
);
}
}
}
}
// scm-chain-trans: p propertyChainAxiom [p, p] → p rdf:type owl:TransitiveProperty
for (const [propertyIri, listHeadNodes] of index.byPredSubj.get(OWL.propertyChainAxiom) ?? []) {
for (const listHeadNode of listHeadNodes) {
const chain = walkRdfList(listHeadNode.value, index);
if (chain.length === 2 && chain[0].value === propertyIri && chain[1].value === propertyIri) {
yield infer(
makeTriple(namedNode(propertyIri), rdf.type, owl.TransitiveProperty),
'scm-chain-trans',
makeTriple(namedNode(propertyIri), namedNode(OWL.propertyChainAxiom), listHeadNode),
);
}
}
}
// prp-key: c hasKey list, x type c, y type c, all key values equal → x sameAs y
for (const [classIri, listHeadNodes] of index.byPredSubj.get(OWL.hasKey) ?? []) {
for (const listHeadNode of listHeadNodes) {
const keyProperties = walkRdfList(listHeadNode.value, index).map(keyProperty => keyProperty.value);
const instances = [...(index.getSubjects(RDF.type, classIri))];
for (let i = 0; i < instances.length; i++) {
for (let j = i + 1; j < instances.length; j++) {
const firstInstanceIri = instances[i].value;
const secondInstanceIri = instances[j].value;
if (allKeyValuesMatch(firstInstanceIri, secondInstanceIri, keyProperties, index)) {
yield infer(
makeTriple(namedNode(firstInstanceIri), owl.sameAs, namedNode(secondInstanceIri)),
'prp-key',
makeTriple(namedNode(classIri), namedNode(OWL.hasKey), listHeadNode),
makeTriple(namedNode(firstInstanceIri), rdf.type, namedNode(classIri)),
makeTriple(namedNode(secondInstanceIri), rdf.type, namedNode(classIri)),
);
}
}
}
}
}
// prp-npa1: NegativePropertyAssertion + actual triple → inconsistency
for (const [assertionIri] of index.byPredSubj.get(RDF.type) ?? []) {
if (!index.has(RDF.type, assertionIri, OWL.NegativePropertyAssertion)) continue;
for (const sourceIndividual of index.getObjects(OWL.sourceIndividual, assertionIri)) {
for (const assertionProperty of index.getObjects(OWL.assertionProperty, assertionIri)) {
for (const targetIndividual of index.getObjects(OWL.targetIndividual, assertionIri)) {
if (index.has(assertionProperty.value, sourceIndividual.value, targetIndividual.value)) {
yield infer(
makeTriple(owl.Thing, rdfs.subClassOf, owl.Nothing),
'prp-npa1',
makeTriple(namedNode(assertionIri), rdf.type, namedNode(OWL.NegativePropertyAssertion)),
makeTriple(namedNode(assertionIri), namedNode(OWL.sourceIndividual), sourceIndividual),
makeTriple(namedNode(assertionIri), namedNode(OWL.assertionProperty), assertionProperty),
makeTriple(namedNode(assertionIri), namedNode(OWL.targetIndividual), targetIndividual),
makeTriple(sourceIndividual as rdfjs.Quad_Subject, assertionProperty as rdfjs.Quad_Predicate, targetIndividual),
);
}
}
for (const targetValue of index.getObjects(OWL.targetValue, assertionIri)) {
if (index.has(assertionProperty.value, sourceIndividual.value, targetValue.value)) {
yield infer(
makeTriple(owl.Thing, rdfs.subClassOf, owl.Nothing),
'prp-npa2',
makeTriple(namedNode(assertionIri), rdf.type, namedNode(OWL.NegativePropertyAssertion)),
makeTriple(namedNode(assertionIri), namedNode(OWL.sourceIndividual), sourceIndividual),
makeTriple(namedNode(assertionIri), namedNode(OWL.assertionProperty), assertionProperty),
makeTriple(namedNode(assertionIri), namedNode(OWL.targetValue), targetValue),
makeTriple(sourceIndividual as rdfjs.Quad_Subject, assertionProperty as rdfjs.Quad_Predicate, targetValue),
);
}
}
}
}
}
}
/**
* Yield axiomatic type triples for OWL 2 RL built-in annotation properties (prp-ap).
*
* @see https://www.w3.org/TR/owl2-profiles/#tab-rules-properties
*/
export function* propertyAxioms(): Iterable<rdfjs.Quad> {
for (const uri of BUILTIN_ANNOTATION_PROPERTIES) {
yield DataFactory.quad(namedNode(uri), rdf.type, owl.AnnotationProperty);
}
// owl:differentFrom is declared symmetric in the OWL 2 meta-ontology.
// This lets prp-symp automatically derive symmetry of differentFrom.
yield DataFactory.quad(owl.differentFrom, rdf.type, owl.SymmetricProperty);
}
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)];
}
function* followPropertyChainWithPath(
currentIri: string,
chainPropertyIris: string[],
step: number,
index: TripleIndex,
path: rdfjs.Quad[] = [],
): Iterable<{ endIri: string; path: rdfjs.Quad[] }> {
if (step === chainPropertyIris.length - 1) {
// Last step: yield each reachable end node with full chain evidence.
for (const end of index.getObjects(chainPropertyIris[step], currentIri)) {
yield {
endIri: end.value,
path: [...path, makeTriple(namedNode(currentIri), namedNode(chainPropertyIris[step]), end)],
};
}
return;
}
for (const next of index.getObjects(chainPropertyIris[step], currentIri)) {
yield* followPropertyChainWithPath(
next.value,
chainPropertyIris,
step + 1,
index,
[...path, makeTriple(namedNode(currentIri), namedNode(chainPropertyIris[step]), next)],
);
}
}
function allKeyValuesMatch(firstInstanceIri: string, secondInstanceIri: string, keyPropertyIris: string[], index: TripleIndex): boolean {
for (const keyPropertyIri of keyPropertyIris) {
const firstValues = index.getObjects(keyPropertyIri, firstInstanceIri);
const secondValues = index.getObjects(keyPropertyIri, secondInstanceIri);
if (firstValues.size === 0 || secondValues.size === 0) return false;
let matched = false;
for (const firstValue of firstValues) {
for (const secondValue of secondValues) {
if (firstValue.value === secondValue.value) {
matched = true;
break;
}
}
if (matched) break;
}
if (!matched) return false;
}
return true;
}
|