Saturday, February 16, 2013

DBPedia

By the end of previous posts, I got an overview of how DBPedia, RDF & SPARQL are related and learnt what RDF and SPARQL are in more detail. Since my initially set aim was to be able to query on DBPedia using SPARQL, I had to understand the schema of DBPedia and also, try out some simple examples to query DBPedia. In this post, that would be my agenda.

One important point to know is that for any wikipedia page, there mostly exists a corresponding dbpedia page and this page URI can be easily obtained as I will indicate through an example. Consider the wikipage on Civil Engineering. Its URI is http://en.wikipedia.org/wiki/Civil_engineering. Then, its corresponding dbpedia page is http://dbpedia.org/page/Civil_engineering. Thus, all one has to do to get the dbpedia page from wikipedia page is to replace http://en.wikipedia.org/wiki/ with http://dbpedia.org/page/ or http://dbpedia.org/resource/.

Now, how do I extract some information from this dbpedia page? First, lets have a look at the dbpedia page on Civil Engineering.


We can see that it has many properties whose value can be queried.

EXAMPLE:

Lets get the abstract in English from dbpedia page on Civil Engineering. As can be seen, abstract is a property defined in dbpedia-owl namespace whose URI is http://dbpedia.org/ontology/. With this information, we are ready to write SPARQL query (Taken from http://blog.3kbo.com/2008/08/11/dbpedia-examples-using-linked-data-and-sparql/ after modifying it).

SPARQL Query:

SELECT ?abstract
WHERE {
{ <http://dbpedia.org/resource/Civil_engineering> <http://dbpedia.org/ontology/abstract> ?abstract .
FILTER langMatches( lang(?abstract), 'en') }
}
Try it out at DBPedia specific SNORQL's endpoint.


Explanation:

The first sentence inside the WHERE block gets the value corresponding to property 'abstract'. Then, the FILTER command extracts only English abstract, which is finally displayed.

Result as displayed when SNORQL endpoint is used:

SPARQL results:

abstract
"Civil engineering is a professional engineering discipline that deals with the design, construction and maintenance of the physical and naturally built environment, including works such as bridges, roads, canals, dams and buildings. Civil engineering is the oldest engineering discipline after military engineering, and it was defined to distinguish non-military engineering from military engineering. It is traditionally broken into several sub-disciplines including environmental engineering, geotechnical engineering, structural engineering, transportation engineering, municipal or urban engineering, water resources engineering, materials engineering, coastal engineering, surveying, and construction engineering. Civil engineering takes place on all levels: in the public sector from municipal through to federal levels, and in the private sector from individual homeowners through to international companies."@en



TRY OUT: Write a SPARQL query to get us a list of all churches in Paris.

No comments:

Post a Comment