Repository navigation
perf(infer): reason over the ontology at load, and skip sameAs rules that cannot fire - #417
Merged
Merged
Conversation
…that cannot fire Two changes to applyInference, each with an identical closure: - engine.load() gets only the ontology triples (RDFS/OWL axioms, class and property declarations, list cells), not the whole graph. load() closes the rules over its vocabulary, so passing every triple reasoned over the instance data twice. - When no asserted triple mentions a term that can introduce owl:sameAs (sameAs, NamedIndividual, Nothing, functional or inverse-functional properties, hasKey, max (qualified) cardinality), the nine rules whose premise reads owl:sameAs are dropped. Eyeling evaluates owl:sameAs as a builtin that scans every fact, and eq-rep-* call it once per triple, which made inference quadratic even when nothing was derived. Full `wiki check` on the bench:shacl fixture: 10^4 quads 45.1 s -> 1.6 s, 10^5 from over 20 minutes to 8.8 s, 10^6 in 92.7 s. Refs #414 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two changes to
applyInference(src/wiki/infer.ts). Each leaves the inferred closure identical.engine.load()gets only the ontology.load()is the engine's preprocessing pass: it closes the rules over the vocabulary it's given, theninfer()runs the data through. We passed the whole graph as the vocabulary, so the instance data was reasoned over twice. NowisOntologyTripleselects RDFS/OWL axioms, class and property declarations, and list cells. Annotations,sameAs, anddifferentFromstay in the data.owl:sameAsare dropped when nosameAscan arise. Eyeling evaluatesowl:sameAsas a builtin that scans every fact (evalOwlSameAsBuiltin), andeq-rep-s/p/ocall it once per triple, so inference was O(n²) even on graphs that derive nothing.mayDeriveSameAskeeps those rules whenever an asserted triple mentions a term that some rule needs in order to concludeowl:sameAs:sameAs,NamedIndividual(the ruleset declaressameAsreflexive viaprp-rp),Nothing(closed underNamedIndividual), functional or inverse-functional properties,hasKey, or max (qualified) cardinality. No rule concludes any of these terms, which I checked by scanning every rule conclusion in the baked ruleset. The rules are found by shape, and the count is checked at load, the same waydt-eqis, so a re-bake that changes them fails loudly.Parity
The closure matches
maintriple for triple (the harness is in the session record, not committed):mainhasKey, functional props,sameAson classes, a disjointness inconsistency)sameAstrigger removedtests/fixtures/microdocs/wiki.yml)wazootech/memorybench:shaclfixture, 10³bench:shaclfixture, 10⁴A scratch patch of Eyeling's builtin, using its existing predicate index, also made
infer()linear (8,005 quads: 6.9 s → 0.56 s) with identical output once the per-run inconsistency-report IRIs are normalized. That confirms the diagnosis. It isn't part of this PR; we don't own Eyeling (see wazootech/reasoner#1).Benchmark (
deno task bench:shacl, #416), fullwiki checkmainAt 10⁶,
loadGraphtakes 61 s and SHACL validation 28 s. SHACL result counts match the validator-only cases at every size (4 / 24 / 194 / 2,078). Measured on Windows with 1.4–3.5 GB of RAM free.Not fixed
Graphs that do mention one of those terms still go through Eyeling's quadratic
sameAsbuiltin. The fix for that is our own reasoner (wazootech/reasoner#1).Checks
deno task check,lint,fmt:check,test(581 passed, 1 ignored), and the docs wiki'sfmt --check,lint --strict,check --strict, andrender --checkall pass. The docs' embedded SPARQL results are unchanged. New:tests/infer_test.tscovers ontology classification, thesameAstrigger terms,sameAssubstitution with an assertedsameAs,sameAsderived from a functional property, and axioms applying with the equality rules dropped.Refs #414
🤖 Generated with Claude Code