How to use the wikidata-sdk.sparqlQuery 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 mapbox / wikimama / query-wikidata.js View on Github external
# Berlin coordinates
    wd:${wikidataId} wdt:P625 ?singLoc . 
    SERVICE wikibase:around { 
      ?place wdt:P625 ?location . 
      bd:serviceParam wikibase:center ?singLoc . 
      bd:serviceParam wikibase:radius ${radius} . 
    } 
    # Is a human settlement
    ?place wdt:P31/wdt:P279* wd:Q486972 .
    SERVICE wikibase:label {
      bd:serviceParam wikibase:language "en" . 
    }
  }
  `;

  var url = wdk.sparqlQuery(sparql);
  request(url, function (err, response) {
    if (err) {
      console.log(err);
    } else {
      var body = JSON.parse(response.body);
      try {
        var bindings = body['results']['bindings'];
        var count = 0;
        bindings.forEach(function (binding) {
          bindings[count]['wikidata_url'] = binding['place']['value'];
          bindings[count]['wikidata_qid'] = binding['place']['value'].split('entity/')[1];
          bindings[count]['place_label'] = binding['placeLabel']['value'];
          bindings[count]['location'] = binding['location']['value'];
          count += 1;
        });
        var uniqueBindings = uniqBy(bindings, 'place');
github osmlab / name-suggestion-index / match_wikiTags.js View on Github external
result.search.forEach((entity) => {
                choices.push(entity);
                entity.lang = lang;
                queue.push(
                    fetch(wdk.sparqlQuery(instancesSPARQL(entity)))
                        .then(response => response.json())
                        .then(result => getInstances(result, entity))
                        .catch(e => console.error(colors.red(e)))
                );
                queue.push(
                    fetch(wdk.sparqlQuery(sitelinkSPARQL(entity)))
                        .then(response => response.json())
                        .then(result => getSitelink(result, entity))
                        .catch(e => console.error(colors.red(e)))
                );
            });
            return Promise.all(queue);
github osmlab / name-suggestion-index / match_wikiTags.js View on Github external
result.search.forEach((entity) => {
                choices.push(entity);
                entity.lang = lang;
                queue.push(
                    fetch(wdk.sparqlQuery(instancesSPARQL(entity)))
                        .then(response => response.json())
                        .then(result => getInstances(result, entity))
                        .catch(e => console.error(colors.red(e)))
                );
                queue.push(
                    fetch(wdk.sparqlQuery(sitelinkSPARQL(entity)))
                        .then(response => response.json())
                        .then(result => getSitelink(result, entity))
                        .catch(e => console.error(colors.red(e)))
                );
            });
            return Promise.all(queue);