feat: match Variables inside Quad pattern terms - #637
Conversation
|
As a separate PR it would make sense to introduce something like |
|
This PR appears to introduce cross graph logic - I assume because it builds upon a PR that has now been stood down. Can all of this logic please be removed. |
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…f script Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
4bf84e1 to
5f98fdf
Compare
|
Addressed. I rebuilt this branch directly on current |
Adds structural matching for
Quadpattern terms containingVariablecomponents, on top of the component-id triple-term index of #635:match/getQuads/countQuads/hasand friends can now answer?r rdf:reifies <<( :s ?p ?o )>>-style queries from the index instead of a full scan, in any pattern slot that can hold a triple term (subject, object, graph) and at any nesting depth.Semantics (aligned with rdf-stores, so existing Comunica consumers understand them): concrete components must be term-equal; a
Variablematches anything in its position; nestedQuadcomponents recurse; the same variable twice acts as independent wildcards (no join — that stays with #281); variable-freeQuadpatterns keep the exact single-id path; top-levelVariablearguments stay non-matching; a pattern built withDataFactory.quad(s, p, o)matches default-graph triple terms, and aVariablegraph component also matches API-only graph-component terms.Implementation: wildcard-bearing slots expand into candidate term ids enumerated from the
_quadIdsindex and loop the existing_findInIndex/_countInIndex/indexMatchmachinery with the numeric ids as fixed keys; variable-free patterns and non-Quadslots take the previous code paths unchanged. Advertisingfeatures.quotedTripleFilteringto Comunica is deferred to a follow-up (it belongs with an integration test).Stacked on #635, rebased directly onto current
mainwithout #601's cross-entity-index set-operation changes. The branch now contains the focused triple-term component-id index plus #637's structural matching, documentation, and array-pattern refactor.Performance (M1, Node 25, interleaved A/B fresh-process runs vs the #635 tip 72c8ffd; workload per the #633 analysis, 100 k / 1 M quads): the wildcard query
<<( :s0 ?p ?o )>>with 100 hits answers in 183 µs / 184 µs — O(matches), size-independent — vs a 69 ms / 850 ms full-scan workaround (~375× / ~4 600×); the low-selectivity<<( ?s :p3 ?o )>>(N/16 hits) is materialization-bound at 15.6 ms / 168 ms (~5× vs scan, ~3.5–4× faster than the design memo's prototype). Ingest, heap (byte-identical) and the variable-free exact-match paths are unchanged within noise (the variable-free paths are unchanged code). Fullnpm test(6 573 tests, 100 % coverage) and the RDF 1.2 syntax suites pass.Open questions (from the design memo, for sign-off):
Variablearguments: kept non-matching (0 results, as today, pinned in a test). Aligning with rdf-stores (wildcards) would be more consistent but changes observable behavior of existing calls — separate decision.forSubjects/forPredicates/forObjects: scope-cut to exact-only forQuadpatterns in this PR (documented); the candidate loop can be extended there too if wanted.Closes #633
Refs rdfjs/types#68
cc @jeswr