Skip to content

Commit

Permalink
fix: Correctly use sparql string tag
Browse files Browse the repository at this point in the history
- Arrays in sparql string are supported directly, no need to join
- filters.map should return sparql tagged strings
  • Loading branch information
ptbrowne committed Jan 26, 2022
1 parent a8cc140 commit af52a0d
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions app/rdf/query-dimension-values.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SELECT } from "@tpluscode/sparql-builder";
import { SELECT, sparql } from "@tpluscode/sparql-builder";
import { Literal, NamedNode, Term } from "rdf-js";
import { Filters } from "../configurator";
import { cube as cubeNs } from "./namespace";
Expand Down Expand Up @@ -96,35 +96,33 @@ export async function loadDimensionValues(
?observation ${dimensionIri} ?value .
${
filters
? filterList
.map(([iri, value], idx) => {
const filterDimension = cube.dimensions.find(
(d) => d.path?.value === iri
);
if (
!filterDimension ||
value.type === "range" ||
dimensionIri?.value === iri
) {
return "";
}
const versioned = filterDimension
? dimensionIsVersioned(filterDimension)
: false;
return `${
versioned
? `?dimension${idx} <http://schema.org/sameAs> ?dimension_unversioned${idx}.`
: ""
}
? filterList.map(([iri, value], idx) => {
const filterDimension = cube.dimensions.find(
(d) => d.path?.value === iri
);
if (
!filterDimension ||
value.type === "range" ||
dimensionIri?.value === iri
) {
return "";
}
const versioned = filterDimension
? dimensionIsVersioned(filterDimension)
: false;
return sparql`${
versioned
? sparql`?dimension${idx} ${ns.schema.sameAs} ?dimension_unversioned${idx}.`
: ""
}
?observation <${iri}> ?dimension${idx}.
${formatFilterIntoSparqlFilter(
value,
filterDimension,
versioned,
idx
)}`;
})
.join("\n")
})
: ""
}
`;
Expand Down

0 comments on commit af52a0d

Please sign in to comment.