How to use the sparqljs.Parser function in sparqljs

To help you get started, we’ve selected a few sparqljs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Callidon / sparql-engine / src / engine / plan-builder.ts View on Github external
constructor (dataset: Dataset, prefixes: any = {}, customFunctions?: CustomFunctions) {
    this._dataset = dataset
    this._parser = new Parser(prefixes)
    this._optimizer = Optimizer.getDefault()
    this._customFunctions = customFunctions
    this._stageBuilders = new Map()

    // add default stage builders
    this.use(SPARQL_OPERATION.AGGREGATE, new AggregateStageBuilder(this._dataset))
    this.use(SPARQL_OPERATION.BGP, new BGPStageBuilder(this._dataset))
    this.use(SPARQL_OPERATION.BIND, new BindStageBuilder(this._dataset))
    this.use(SPARQL_OPERATION.DISTINCT, new DistinctStageBuilder(this._dataset))
    this.use(SPARQL_OPERATION.FILTER, new FilterStageBuilder(this._dataset))
    this.use(SPARQL_OPERATION.GRAPH, new GraphStageBuilder(this._dataset))
    this.use(SPARQL_OPERATION.MINUS, new MinusStageBuilder(this._dataset))
    this.use(SPARQL_OPERATION.SERVICE, new ServiceStageBuilder(this._dataset))
    this.use(SPARQL_OPERATION.OPTIONAL, new OptionalStageBuilder(this._dataset))
    this.use(SPARQL_OPERATION.ORDER_BY, new OrderByStageBuilder(this._dataset))
    this.use(SPARQL_OPERATION.PROPERTY_PATH, new GlushkovStageBuilder(this._dataset))
github SynBioHub / synbiohub / lib / views / sparql.js View on Github external
function post (req, res) {
  req.setTimeout(0) // no timeout

  var graphUri

  if (req.body.graph === 'user') {
    graphUri = req.user.graphUri
  } else {
    graphUri = null
  }

  const parser = new SparqlParser()
  const generator = new SparqlGenerator()

  var query

  try {
    query = parser.parse(req.body.query)
  } catch (e) {
    form(req, res, {
      query: req.body.query,
      graph: req.body.graph,
      errors: [
        e.stack
      ]
    })

    return
github LinkedDataFragments / Client.js / lib / sparql / SparqlIterator.js View on Github external
function SparqlIterator(source, query, options) {
  // Set argument defaults
  if (typeof source.read !== 'function')
    options = query, query = source, source = null;
  options = options || {};
  source = source || AsyncIterator.single({});

  // Transform the query into a cascade of iterators
  try {
    // Parse the query if needed
    if (typeof query === 'string')
      query = new SparqlParser(options.prefixes).parse(query);

    // Create an iterator that projects the bindings according to the query type
    var queryIterator, QueryConstructor = queryConstructors[query.queryType];
    if (!QueryConstructor)
      throw new Error('No iterator available for query type: ' + query.queryType);
    queryIterator = new QueryConstructor(null, query, options);
    // Create an iterator for bindings of the query's graph pattern
    var graphIterator = new SparqlGroupsIterator(source,
                              queryIterator.patterns || query.where, options);

    // Create iterators for each order
    for (var i = query.order && (query.order.length - 1); i >= 0; i--) {
      var order = new SparqlExpressionEvaluator(query.order[i].expression),
          ascending = !query.order[i].descending;
      graphIterator = new SortIterator(graphIterator, function (a, b) {
        var orderA = '', orderB = '';
github epimorphics / qonsole / src / stores / qonsole.query.js View on Github external
import RemoteSparqlService from '../remote-sparql-service'
import {getPrefixesFromQuery} from '../query'
import _ from 'lodash'
import {Parser, Generator} from 'sparqljs'

const parser = new Parser()
const generator = new Generator()
const sparqlService = new RemoteSparqlService()

export default {
  state: {
    'query': '',
    'isLoading': false,
    outstandingQuery: undefined // Used to store query for aborting
  },
  getters: {
    query: state => {
      return state.query
    },
    isLoading: state => {
      return state.isLoading
    }
github researchstudio-sat / webofneeds / webofneeds / won-owner-webapp / src / main / webapp / app / sparql-builder-utils.js View on Github external
let limitStr = "";
  if (limit) {
    limitStr = `LIMIT ${parseInt(limit)}`;
  }

  const queryTemplate = `
${prefixesString(prefixes)}
SELECT ${distinctStr} ${variables.join(" ")}
WHERE {
  ${where ? where.join(" \n") : ""}
} ${orderByStr} ${groupByStr} ${limitStr}`;

  // ---------- parse root-query ----------

  const queryAST = new SparqlParser().parse(queryTemplate);

  // ---------- if there are sub-queries, add their ASTs and prefixes ----------
  addSubQueries(queryAST, subQueries);

  // ---------- return AST ----------

  return queryAST;
}
github Callidon / sparql-engine / src / engine / plan-builder.js View on Github external
build (query, options = { format: 'raw' }) {
    // If needed, parse the string query into a logical query execution plan
    if (typeof query === 'string') {
      query = new Parser(options.prefixes).parse(query)
    }
    switch (query.type) {
      case 'query':
        const iterator = this._buildQueryPlan(query, options)
        // only use results formatters for select & ask queries
        if (query.queryType === 'CONSTRUCT' || query.queryType === 'DESCRIBE') {
          return iterator
        }
        switch (options.format) {
          case 'xml':
          case 'application/xml':
          case 'application/sparql-results+xml':
            return new XMLFormatter(iterator, query.variables)
          default:
            return iterator
        }
github researchspace / researchspace / researchspace / web / src / main / components / annotations / AnnotationTextEditorComponent.ts View on Github external
const findTemplatesForUri = (
  dropTemplateConfig: DropTemplateConfigItem[], uri: string
): Kefir.Property => {
  const query = new SparqlJs.Parser().parse(`
    PREFIX rdfs: 
    SELECT ?type ?label ?lang WHERE {
      <${uri}> a ?type .
      OPTIONAL {
        ?type rdfs:label ?label .
        BIND(LANG(?label) AS ?lang)
      }
    }
  `);
  return SparqlClient.select(query).map((result: SparqlClient.SparqlSelectResult) => {
    const types = result.results.bindings;
    let possibleTemplates = [];
    dropTemplateConfig.map(configItem => {
      const {type} = configItem;
      if (type === 'any' || _.find(types, value => value['type'].value === type)) {
        possibleTemplates.push(configItem);
github stanford-oval / thingengine-core / lib / graphdb / sparql_runner.js View on Github external
constructor(stores) {
        this._stores = stores;
        this._parser = new SparqlParser();
    }
github researchspace / researchspace / metaphacts-platform / web / src / main / api / sparql / SparqlUtil.ts View on Github external
export function parsePatterns(
  patterns: string, prefixes?: { [prefix: string]: string }
): SparqlJs.Pattern[] {
  const wrappedPattern = `SELECT * WHERE { ${patterns} }`;
  const parser = prefixes
    ? new SparqlJs.Parser(prefixes)
    : Parser;
  const query = parser.parse(
    encodeLegacyVars(replaceQueryParams(wrappedPattern))
  ) as SparqlJs.SelectQuery;
  return query.where;
}

sparqljs

A parser for the SPARQL query language

MIT
Latest version published 3 months ago

Package Health Score

79 / 100
Full package analysis

Popular sparqljs functions