Skip to content
Advertisement

How to convert some queries from sql to sparql?

I am just learning Sparql and I have the following tables:

Countries, European Country, City and Capital

I would like to know how to make the following queries, because I didnt understand them…

1) Which country has the city “Paris” as capital. 2) Print all the European Countries 3) Print all the countries and theis capitals.

Thank you very much in advance.

Advertisement

Answer

This said, there is DBpedia that offers info similar to what is described, and is a good playground. To query it, http://yasgui.org (which is a better sparql editor) or http://factforge.net/sparql (which is our own integration, a few months old, but has some extra goodies).

Which country has the city “Paris” as capital

The yasgui results will surprise you:

I understand all the historic kingdoms, but dbr:Office_International_d’Hygiène_Publique is a bit of a shock. The reason is that it’s an International Organization (uses Infobox Former International Organization, and it redirects to https://en.wikipedia.org/wiki/Template:Infobox_former_country, which “is currently being merged with Template:Infobox country”. See http://mappings.dbpedia.org/index.php/Cleaning_up_Countries

factforge returns even more results from linked datasets (all these mean just France):

All the European Countries

That’s better because there happens to be a Wikipedia category:

yasgui

all countries and their capitals

This returns a bunch of historic countries and capitals, and again some international organizations, eg

SO THEN, you may have better luck with Wikidata (https://query.wikidata.org/). At https://twitter.com/search?q=wikidatafacts%20country you can find a bunch of interesting queries related to countries.

countries and capitals on Wikidata

It uses a bunch of Qnn and Pnn but you can decode them when you mouse-over.

  • How did I find that wdt:P36 means “capital”? Search for property:capital
  • why filter exists? Because a country may have several subtypes of wd:Q6256 “country”, and if I use that in the main query, it returns several results per country. This way it returns only one.

Map

You can also easily display it on a map:

See a couple of shots https://twitter.com/valexiev1/status/844870994942603264

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement