UNPKG

data-pipeline-information-system-sparql

Version:

Sparql function to query/update RDF through SPARQL 1.1

46 lines (38 loc) 1.62 kB
import SparqlObject from './SparqlObject' import SparqlTask from '../Core/SparqlTask' import sparqljs from 'sparqljs' import {jsonBindings} from './_bindings' import {pathToBinding} from './common'; export function parseRepresentation(this:SparqlObject) { let out = ''; out += 'SELECT ' + jsonBindings.apply(this) + ' '; // out += 'WHERE { ' + this.definition + ' } '; // out += 'GROUP BY ' + this.groupBy; let parser = new sparqljs.Parser( this.prefixes ); return parser.parse(out) } export function representation(this:SparqlObject): string { let parsedQuery = parseRepresentation.apply(this); let generator = new sparqljs.Generator() generator.stringify(parsedQuery) return generator.stringify(parsedQuery); } // export function jsonRepresentation(reference:string, path: string[] = []) { // let model = SparqlTask.sparqlObjects[reference]; // let representation = `(CONCAT ('{', `; // representation += model.attributes.map((attribute) => { // let subRepresentation = '\'"' + attribute.name + '":'; // Remove the '?' // if (attribute.arrayable) { // subRepresentation += `[',GROUP_CONCAT(DISTINCT CONCAT(${pathToBinding([...path, attribute.name])});separator=','),']` // } else { // subRepresentation += `',${pathToBinding([...path, attribute.name])}` // } // return subRepresentation; // }) // .join(',') // representation += `,'}') AS ${pathToBinding([...path, model.reference])})`; // return representation; // } // export default jsonRepresentation;