How to use the sparqljs.Generator 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.

github researchspace / researchspace / metaphacts-platform / web / src / main / api / sparql / SparqlUtil.ts View on Github external
import { getCurrentResource } from 'platform/api/navigation';
import { ConfigHolder } from 'platform/api/services/config-holder';

import { isQuery, isTerm, isIri } from './TypeGuards';

// by default we initialized parser without prefixes so we don't need
// to initialize it explicitly in all tests, but the expectation is that
// in production run init is called on the system startup
let Parser: SparqlJs.SparqlParser = new SparqlJs.Parser();
export let RegisteredPrefixes: { [key: string]: string } = {};
export function init(registeredPrefixes: { [key: string]: string }) {
  RegisteredPrefixes = registeredPrefixes;
  Parser = new SparqlJs.Parser(registeredPrefixes);
}

const Generator = new SparqlJs.Generator();

export type RDFResultFormat = 'application/ld+json'
  | 'application/n-quads'
  | 'application/n-triples'
  | 'application/rdf+json'
  | 'application/rdf+xml'
  | 'application/trig'
  | 'application/trix'
  | 'application/x-binary-rdf'
  | 'application/x-trig'
  | 'application/x-turtle'
  | 'application/xml'
  | 'text/n3'
  | 'text/nquads'
  | 'text/plain'
  | 'text/rdf+n3'
github SynBioHub / synbiohub / lib / views / admin / sparql.js View on Github external
function post (req, res) {
  req.setTimeout(0) // no timeout

  var graphUri = req.body.graph

  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
      ]
    })
  }

  const queryString = generator.stringify(query)
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 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 dbcls / sparql-proxy / src / spike / request-chunking.js View on Github external
async function _req(backend, parsedQuery, accept, timeout, limit, chunkLimit, chunkOffset, data) {
    parsedQuery.limit = chunkLimit;
    parsedQuery.offset = chunkOffset;
    const generator = SparqlGenerator();
    const query = generator.stringify(parsedQuery);

    const options = {
      uri: backend,
      form: {query},
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Accept': accept,
      },
      json: true,
      timeout
    };

    console.log("REQ limit=" + limit + ", chunkLimit=" + chunkLimit + ", chunkOffset=" + chunkOffset);

    const {r, promise} = post(options);
github researchstudio-sat / webofneeds / webofneeds / won-owner-webapp / src / main / webapp / app / service / atom-builder.js View on Github external
let queryString = undefined;
    if (useCase && useCase.generateQuery) {
      const queryMask = {
        type: "query",
        queryType: "SELECT",
        variables: ["?result", "?score"],
      };

      let useCaseQuery = {
        ...useCase.generateQuery(args, "?result"),
        ...queryMask,
      };

      if (useCaseQuery) {
        const sparqlGenerator = new Generator();
        queryString = useCaseQuery && sparqlGenerator.stringify(useCaseQuery);
      }
    }

    const seeksContentNode = seeksContentUri
      ? buildSeeksContentNode(seeksContentUri, args.seeks)
      : {};

    const doNotMatchAfterFnOrLit = useCase && useCase.doNotMatchAfter;
    const doNotMatchAfter = is("Function", doNotMatchAfterFnOrLit)
      ? doNotMatchAfterFnOrLit(
          args,
          {
            "@graph": [seeksContentNode],
          },
          useCase && useCase.timeToLiveMillisDefault
github SynBioHub / synbiohub / lib / api / sparql.js View on Github external
function query (req, res, rawQuery, graphUri) {
  graphUri = graphUri || null

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

  var query
  var queryString

  if (rawQuery) {
    try {
      query = parser.parse(rawQuery)
    } catch (e) {
      res.status(500).send(e.stack)
      return
    }

    queryString = generator.stringify(query)

    try {
      checkQuery(query, req.user)

sparqljs

A parser for the SPARQL query language

MIT
Latest version published 3 days ago

Package Health Score

81 / 100
Full package analysis

Popular sparqljs functions