Could it be possible to expose utils to parse portions of SPARQL? This would help working with sparqljs where I need to generate some JS representation programmatically but the code becomes quite verbose.
For example, I want to create a BindExpression for this snippet
BIND(IF(REGEX(str(?res), ?resourcePattern), ?pagePattern, 1/0) as ?page)
is create like
const expression = {
type: 'bind',
variable: { termType: 'Variable', value: 'page' },
expression: {
type: 'operation',
operator: 'if',
args: [
{
type: 'operation',
operator: 'regex',
args: [
{
type: 'operation',
operator: 'str',
args: [
{ termType: 'Variable', value: 'res' }
]
},
this.factory.variable('resourcePattern'),
]
},
this.factory.variable('pagePattern'),
{
type: 'operation',
operator: '/',
args: [
toRdf(1),
toRdf(0),
]
}
]
}
}
It would be much more efficient to write something like
let parser
parser.parseBindExpression('BIND(IF(REGEX(str(?res), ?resourcePattern), ?pagePattern, 1/0) as ?page)')
Combined with @tpluscode/sparql-builder, I could also interpolate RDF/JS terms
import { sparql } from '@tpluscode/sparql-builder'
import rdf from '@rdfjs/data-model'
let parser
let pageVar = rdf.variable('page')
parser.parseBindExpression(sparql`BIND(IF(REGEX(str(?res), ?resourcePattern), ?pagePattern, 1/0) as ${pageVar})`)
Could it be possible to expose utils to parse portions of SPARQL? This would help working with sparqljs where I need to generate some JS representation programmatically but the code becomes quite verbose.
For example, I want to create a
BindExpressionfor this snippetis create like
It would be much more efficient to write something like
Combined with @tpluscode/sparql-builder, I could also interpolate RDF/JS terms