You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a matchBGP method for basic graph pattern matching #71
Opened by Claude on behalf of Jesse. It is waiting for Jesse's review and is open for discussion. We're looking for input and consensus so that we can update the types.
Context
Matching a basic graph pattern (a set of quad patterns whose terms may be variables) is a common need for code that sits on top of an RDF/JS dataset: rule engines, shape validators, small query helpers. Today every library writes its own join over repeated DatasetCore.match calls, and a store that could join more efficiently on its own indexes has no shared interface to expose that through.
N3.js explored a Store.matchBGP(patterns) method (formerly rdfjs/N3.js#809). It now lives in a standalone package, n3-match-bgp (npm install n3-match-bgp), which joins on the N3.js Store's internal indexes and falls back to match for any other DatasetCore. It will only land in N3.js itself if a shared interface is agreed here.
The change is purely additive. It adds one new interface and changes nothing that exists, so every current implementation and caller of DatasetCore, Dataset, Source and Store keeps compiling unchanged. A dataset opts in by implementing the interface as well, for example class MyStore implements DatasetCore, BgpMatchable, and consumers can feature-detect it with typeof dataset.matchBGP === 'function'. That makes it a minor release.
Open questions
Method or function. A method lets a store use its own indexes. n3-match-bgp is a function matchBGP(dataset, patterns, options), which works over any DatasetCore. Should the types describe the method, the function, or both?
Synchronous or streaming. The proposal is synchronous (Iterable), matching DatasetCore. Should there be a Source-style variant that returns a ResultStream<Bindings>?
Creating bindings. n3-match-bgp takes an optional BindingsFactory so callers such as Comunica get their own Bindings class. Should that be an options argument here?
Wildcards. n3-match-bgp also accepts null in a pattern as an unbound wildcard. Should that be part of the contract?
Triple terms. With RDF 1.2, a pattern may hold a triple term that contains variables, such as quad(r, rdf.reifies, quad(s, p, o)). Should matchBGP bind variables inside triple terms (as SPARQL 1.2 does)? This connects to Matching patterns inside quads: Variable components in Quad pattern terms of match() #68 and the draft PR for matching inside triple terms.
Which spec. Does this belong in the dataset spec or the query spec?
Context
Matching a basic graph pattern (a set of quad patterns whose terms may be variables) is a common need for code that sits on top of an RDF/JS dataset: rule engines, shape validators, small query helpers. Today every library writes its own join over repeated
DatasetCore.matchcalls, and a store that could join more efficiently on its own indexes has no shared interface to expose that through.N3.js explored a
Store.matchBGP(patterns)method (formerly rdfjs/N3.js#809). It now lives in a standalone package, n3-match-bgp (npm install n3-match-bgp), which joins on the N3.jsStore's internal indexes and falls back tomatchfor any otherDatasetCore. It will only land in N3.js itself if a shared interface is agreed here.Proposal
An optional interface, added next to
DatasetCore:Variables.Bindingsobject (from the query spec types) mapping every variable in the patterns to a term.Draft PR: #72
Compatibility
The change is purely additive. It adds one new interface and changes nothing that exists, so every current implementation and caller of
DatasetCore,Dataset,SourceandStorekeeps compiling unchanged. A dataset opts in by implementing the interface as well, for exampleclass MyStore implements DatasetCore, BgpMatchable, and consumers can feature-detect it withtypeof dataset.matchBGP === 'function'. That makes it a minor release.Open questions
matchBGP(dataset, patterns, options), which works over anyDatasetCore. Should the types describe the method, the function, or both?Iterable), matchingDatasetCore. Should there be aSource-style variant that returns aResultStream<Bindings>?BindingsFactoryso callers such as Comunica get their ownBindingsclass. Should that be an options argument here?nullin a pattern as an unbound wildcard. Should that be part of the contract?quad(r, rdf.reifies, quad(s, p, o)). ShouldmatchBGPbind variables inside triple terms (as SPARQL 1.2 does)? This connects to Matching patterns inside quads: Variable components in Quad pattern terms of match() #68 and the draft PR for matching inside triple terms.Related