From 43d2b316db4629401d9105592deffc5b637d82e9 Mon Sep 17 00:00:00 2001 From: David de Boer Date: Tue, 11 Jun 2024 13:59:09 +0200 Subject: [PATCH] fix: Use $this consistently * Replace `?this` with `$this` in generators. * They seem to be equivalent, so this should be no BC break. --- src/lib/Generator.class.ts | 11 +++++------ static/example/generator-stage-1-1.rq | 4 ++-- static/example/generator-stage-1-2.rq | 4 ++-- static/example/generator-stage-2.rq | 6 +++--- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/lib/Generator.class.ts b/src/lib/Generator.class.ts index 27b2927..6624dd5 100644 --- a/src/lib/Generator.class.ts +++ b/src/lib/Generator.class.ts @@ -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'; @@ -83,11 +83,10 @@ export default class Generator extends EventEmitter { '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 { diff --git a/static/example/generator-stage-1-1.rq b/static/example/generator-stage-1-1.rq index 03da34b..3ad0689 100644 --- a/static/example/generator-stage-1-1.rq +++ b/static/example/generator-stage-1-1.rq @@ -3,10 +3,10 @@ prefix dbo: prefix rdf: prefix rdfs: construct { - ?this a sdo:Thing ; + $this a sdo:Thing ; sdo:additionalType ; sdo:name ?name -} +} where { $this rdfs:label ?name . filter(lang(?name) = 'en') diff --git a/static/example/generator-stage-1-2.rq b/static/example/generator-stage-1-2.rq index 8095e02..9097494 100644 --- a/static/example/generator-stage-1-2.rq +++ b/static/example/generator-stage-1-2.rq @@ -3,8 +3,8 @@ prefix dbo: prefix rdf: prefix rdfs: construct { - ?this rdfs:comment "This was generated using LDWorkbench"; -} + $this rdfs:comment "This was generated using LDWorkbench"; +} where { $this a/rdfs:subClassOf* dbo:Plant } diff --git a/static/example/generator-stage-2.rq b/static/example/generator-stage-2.rq index 69b758b..8bb36f5 100644 --- a/static/example/generator-stage-2.rq +++ b/static/example/generator-stage-2.rq @@ -2,8 +2,8 @@ prefix skos: prefix rdfs: prefix wdtn: 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 -} +}