How to implement associated data query in JavaScript

Source: Internet
Author: User
Tags html page json

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.