0

I am new in node.js.I downloaded and executed a project from GitHub from this link. Here on this link there is live demo of this app. It is running rdf search using wikidata. This is the function that I found for the search of keyword from wikidata written in file public/scripts/controllers/main.js.

 function search () {
    //TODO: fix when null;
    if (vm.searchInput != vm.lastSearch) {
      var input = vm.searchInput;
      vm.lastSearch = input;
      vm.searchWait = true;
      vm.noResults  = false;
      //$http.get('https://www.wikidata.org/w/api.php?action=wbsearchentities&format=json&language=en&limit=20&uselang=en&type=item&continue=0&search='+input).then(
      $http({
        method: 'GET',
        url: 'https://www.wikidata.org/w/api.php',
        params: {
          action: 'wbsearchentities',
          format: 'json',
          language: 'en',
          uselang: 'en',
          type: 'item',
          continue: '0',
          limit: '20',
          search: input,
          origin: '*',
        }
      }).then(
        function onSuccess (response) {
          onSearch(response.data.search);
        },
        function onError (response) { onSearchErr(); console.log('Error: ' + response.data); }
      );
      //request.execQuery(query.search(input), onSearch, onSearchErr);
    }
    vm.searchActive = true;
  }

I have changed the above function for DBpedia but it not search the keyword from DBpedia

  function search2 () {
    //TODO: fix when null;
    if (vm.searchInput != vm.lastSearch) {
      var input = vm.searchInput;
      vm.lastSearch = input;
      vm.searchWait = true;
      vm.noResults  = false;
      //$http.get('https://www.wikidata.org/w/api.php?action=wbsearchentities&format=json&language=en&limit=20&uselang=en&type=item&continue=0&search='+input).then(
      $http({
        method: 'GET',
        url: 'http://dbpedia.org/sparql',
        params: {
          action: 'wbsearchentities',
          format: 'json',
          language: 'en',
          uselang: 'en',
          type: 'item',
          continue: '0',
          limit: '20',
          search: input,
          origin: '*',
        }
      }).then(
        function onSuccess (response) {
          onSearch(response.data.search);
        },
        function onError (response) { onSearchErr(); console.log('Error: ' + response.data); }
      );
      //request.execQuery(query.search(input), onSearch, onSearchErr);
    }
    vm.searchActive = true;
  }

how I can change this above function for search in DBpedia?Please help

  • ehm, DBpedia is **not** Wikidata ... in your first snippet you're using a Wikidata REST API service for entity lookup, in particular the `wbsearchentities` service. The DBpedia SPARQL endpoint in your second code snippet is ... just a SPARQL endpoint. You have to write and send a SPARQL query – UninformedUser Jan 29 '20 at 07:16
  • just as a minor hint (I will not rewrite your Javascript code) - a query you can use is `select distinct ?s { ?s rdfs:label ?l . FILTER(langmatches(lang(?l), 'en')) ?l bif:contains "here_your_input_token" } limit 20` - your task is to find and use a Javascript SPARQL API or just use plain HTTP request (`query` param is the way to go) – UninformedUser Jan 29 '20 at 07:24
  • what is Javascript SPARQL API for DBpedia? –  Jan 29 '20 at 09:59

0 Answers0