Skip to content

Commit

Permalink
Fix countQuads not being selective enough for quoted triples
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Jun 26, 2023
1 parent 9a0c01f commit 060f27b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/RdfStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,13 @@ export class RdfStore<E = any, Q extends RDF.BaseQuad = RDF.Quad> implements RDF
object?: RDF.Term | null,
graph?: RDF.Term | null,
): number {
// Check if our dictionary and our indexes have quoted pattern support
const indexesSupportQuotedPatterns = Boolean(this.dictionary.features.quotedTriples) &&
Object.values(this.indexesWrapped).every(wrapped => wrapped.index.features.quotedTripleFiltering);

// Construct a quad pattern array
const quadComponents: QuadPatternTerms = <QuadPatternTerms>
[ subject || undefined, predicate || undefined, object || undefined, graph || undefined ]
.map(term => {
if (term && (term.termType === 'Variable' || term.termType === 'Quad')) {
return;
}
return term;
});
const [ quadComponents ] =
quadToPattern(subject, predicate, object, graph, indexesSupportQuotedPatterns);

// Optimize all-variables pattern
if (quadComponents.every(quadComponent => quadComponent === undefined)) {
Expand Down
12 changes: 12 additions & 0 deletions test/RdfStore-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,18 @@ describe('RdfStore', () => {
]);
});

it('should count results for a quoted object variable', () => {
expect(store.countQuads(
undefined,
DF.namedNode('ex:says'),
DF.quad(
DF.namedNode('ex:bob'),
DF.namedNode('ex:name'),
DF.variable('name'),
),
)).toEqual(2);
});

it('should produce results for a quoted predicate variable', () => {
expect(store.getQuads(
undefined,
Expand Down

0 comments on commit 060f27b

Please sign in to comment.