How to use the wikidata-sdk.simplifySparqlResults function in wikidata-sdk

To help you get started, we’ve selected a few wikidata-sdk 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 nichtich / wikidata-taxonomy / lib / query.js View on Github external
module.exports = (id, env) => {
  try {
    env = options(env)
  } catch (e) {
    return Promise.reject(e)
  }

  const queries = sparqlQueries(id, env)

  const simplify = wdk.simplifySparqlResults

  return Promise.all(queries.map(
      sparql => executeQuery(sparql, env).then(simplify).then(
        results => results.map(row => {
          ['item', 'class'].forEach(field => {
            if (typeof row[field] === 'string') {
              row[field] = { value: row[field] }
            }
          })
          return row
        })
      )
    )).catch(e => {
      throw new Error('SPARQL request failed')
    })
    .then(results => {
github nichtich / wikidata-taxonomy / lib / wikidata-taxonomy.js View on Github external
var executeQuery = function(sparql) {
    var options = {
      uri: env.endpoint,
      qs: {
        format: 'json',
        query: sparql
      }
    }
    if (env.post) options.method = 'POST'
    if (env.user || env.password) {
      options.auth = {}
      if (env.user) options.auth.user = env.user
      if (env.password) options.auth.password = env.password
    }
    return request(options).then(wdk.simplifySparqlResults)
  };