Skip to content

Commit

Permalink
fix: Use $this consistently
Browse files Browse the repository at this point in the history
* Replace `?this` with `$this` in generators.
* They seem to be equivalent, so this should be no BC break.
  • Loading branch information
ddeboer committed Jun 11, 2024
1 parent d08b26e commit 305a565
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
11 changes: 5 additions & 6 deletions src/lib/Generator.class.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {ConstructQuery, ValuePatternRow} from 'sparqljs';
import type {ConstructQuery} from 'sparqljs';
import type Stage from './Stage.class.js';
import getSPARQLQuery from '../utils/getSPARQLQuery.js';
import type {Quad, NamedNode} from '@rdfjs/types';
Expand Down Expand Up @@ -83,11 +83,10 @@ export default class Generator extends EventEmitter<Events> {
'construct'
);
const patterns = unionQuery.where ?? [];
const valuePatterns: ValuePatternRow[] = [];
for (const $this of batch) {
valuePatterns.push({'?this': $this});
}
patterns.push({type: 'values', values: valuePatterns});
patterns.push({
type: 'values',
values: batch.map($this => ({'?this': $this})),
});
unionQuery.where = [{type: 'group', patterns}];

try {
Expand Down
4 changes: 2 additions & 2 deletions static/example/generator-stage-1-1.rq
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ prefix dbo: <http://dbpedia.org/ontology/>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
construct {
?this a sdo:Thing ;
$this a sdo:Thing ;
sdo:additionalType <http://vocab.getty.edu/aat/300343602>;
sdo:name ?name
}
}
where {
$this rdfs:label ?name .
filter(lang(?name) = 'en')
Expand Down
4 changes: 2 additions & 2 deletions static/example/generator-stage-1-2.rq
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ prefix dbo: <http://dbpedia.org/ontology/>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
construct {
?this rdfs:comment "This was generated using LDWorkbench";
}
$this rdfs:comment "This was generated using LDWorkbench";
}
where {
$this a/rdfs:subClassOf* dbo:Plant
}
6 changes: 3 additions & 3 deletions static/example/generator-stage-2.rq
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix wdtn: <http://www.wikidata.org/prop/direct-normalized/>
construct {
?this a skos:Concept; skos:prefLabel ?labels
$this a skos:Concept; skos:prefLabel ?labels
} where {
?s wdtn:P1014 ?this .
?s wdtn:P1014 $this .
?s rdfs:label ?labels
}
}

0 comments on commit 305a565

Please sign in to comment.