This article describes how to use JavaScript to get the data we want from DBpedia.
The role of DBpedia: The data in Wikipedia is turned into linked, which allows the machine to read and freely access the data.
Sparql
Trying to use the semantic Web without SPARQL are like trying to use a relational database without SQL.
--tim Berners-lee
SPARQL is the SQL of the semantic Web (semantic network), the language used for data querying.
SPARQL Endpoint
SPARQL Query terminal, is an HTTP binding protocol for SPARQL queries through HTTP, and returns the corresponding data.
DBpedia's SPARQL endpoint address is: HTTP://DBPEDIA.ORG/SPARQL
We can open this page through the browser, for SPARQL inquiries (preferably over the wall, did not turn the wall query often failed, do not understand why = =).
But this query eventually returns the result is an HTML page, not what we want, and we can specify the return data type by setting the Accept property of the request header.
For example, if specified as: Text/xml, then the returned RDF format data.
So how do we enter SPARQL query code?
Simply pass the code through a Get or POST method with parameter query. For example:
If you want to query: SELECT DISTINCT? Concept where {[] a? Concept} LIMIT 100
You can use the link to get the data:
Http://dbpedia.org/sparql?query=select%20distinct%20?concept%20where%20{[]%20a%20? concept}%20limit%20100
Where the spaces are turned into%20.
Implementation Details
Cross-domain
We can do this with Ajax, but Ajax is not cross-domain in some browsers, but it's clear that the linked data we want is almost always cross-domain.
In fact, in some older versions of the browser, we do not have to change its data form in the front-end dynamic Cross-domain asynchronous read.
However, we can solve cross-domain problems through the server proxy approach.
Get or POST
How do I post with Get?
This may be considered in many ways, but given that get may be cached, we use post to prevent data from being cached.
Return data in what form
We talked about using Text/xml to return RDF data, but RDF doesn't work well in JavaScript, so we return with JSON, which means we need to set accept to Application/sparql-results+json.