pldn / LDWizard

🧙 LDWizard: A generic framework for simplifying the creation of linked data. Supported by the PLDN community.
European Union Public License 1.2
13 stars 7 forks source link

Create function for SPARQL refinement in columnRefinement transformations #152

Closed philipperenzen closed 11 months ago

philipperenzen commented 11 months ago

Currently in LDWizard, it is not yet supported to use SPARQL queries to conduct refinement transformations. This issue proposes a feature to support retrieving values from a given input query and endpoint. The query could have the CSV row/column value injected, if the correct argument is present in the query.

For example:

const sparqlQuery = `
prefix dct: <http://purl.org/dc/terms/>
select ?refinement where
 {
   ?refinement dct:title ?title; a <https://triplydb.com/Triply/linkedmdb/vocab/Film> .
   filter(lcase(?title) = lcase(?search))
 }
`
const columnrefinement: ColumnRefinement = {
  bulk: true,
  transformation: sparqlTransform(sparqlQuery, 'https://api.nightly.triplydb.com/datasets/Triply/linkedmdb/sparql')
}

A description of the sparqlTransform implementation:

type Options = {
 refinementBinding?: string ;
 queryVariable?: string ;
}

function sparqlTransform(query: string, endpoint: string, options: Options = {}): (value: string) => Map<number, string> {
  const optionsWithDefault: Options = {...{refinementBinding: 'refinement', queryVariable: 'query'}, ...options}
  // 1. parse query and make it into a union of `batchSize` queries and bind the `?search` variable to the value of the column in the source data 
  // 2. perform fetch request on endpoint
  // 3. inject variable `options.queryVariable` into the `union` query 
  // 4. get binding `options.refinementBinding`
  // 5. match the binding to the correct row
  // 5. return the Map with the row number and string values of the bindings 
}
philipperenzen commented 11 months ago

Feature is now available in version 3.0.4, see CONFIGURING.md for examples.