Javascript query DBpedia small application
In the previous article , we learned about SPARQL and SPARQL Endpoint, and simply made a SPARQLWrapper.js to query some data from DBpedia.
This article attempts to use SPARQLWrapper.js to read DBpedia data and display it.
Goal
By inputting an English word, and then returning the relevant information in the WIKI.
The main problem to be solved is what kind of SPARQL statement can query what we need.
First look at a simple SPARQL query statement
PREFIX :
SELECT ?instrument
WHERE {
:andrew :playsInstrument ?instrument .
}
First define a domain name space http://aabs.purl.org/music#.
Then select the instrument variable like this, which satisfies:
The subject is http://aabs.purl.org/music#andrew, the predicate is http://aabs.purl.org/music#playsInstrument, and the object is the instrument.
bif:contains() bif:contains() is a variant of the contains() function. As the name suggests, it is a function that determines whether it is included.
Using this, we can query the data we need.
prefix foaf:
select distinct ?url ?alma ?comment
where {
?s foaf:name ?sname .
?sname bif:contains 'China'.
? s foaf:depiction ?url .
?s dbpedia-owl:wikiPageExternalLink ?alma .
?s rdfs:comment ?comment .
}
limit 10
this The SPARQL statement is to query the entry containing China's name, and then return the URL of its picture, the URL of the homepage, and the introduction.
Let’s finish writing the entire program.
Complete code