Click here to Skip to main content
15,435,745 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

JavaScript
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;
      }


What I have tried:

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

JavaScript
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?what is Javascript SPARQL API for DBpedia?Please help
Posted
Updated 29-Jan-20 5:05am
v3

1 solution

The URL you are looking for uses ?query= to specify the query. However, you are going to have to cope with the fact that the query format for Sparql is rather odd. Here's an example[^].
 
Share this answer
 
Comments
Member 8840306 29-Jan-20 9:08am    
here is SPARQL query for this situation for dbpedia is :select distinct ?s { ?s rdfs:label ?l . FILTER(langmatches(lang(?l), 'en')) ?l bif:contains "here_your_input_token" } limit 20
Member 8840306 29-Jan-20 9:15am    
how I can use this query within the code of javascript .As I am new newbie in javascript and node.js.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900