Archive for the 'SPARQL' Category

Viewing the CIA World Factbook

The CIA World Factbook provides a lot of data about  geography, people, government, economy, communications, transportation, military and transnational issues of each country in the world and also of some other entities like the European Union. The data are constantly updated. The CIA World Factbook does not provide maps for the data that I think would help the user that want to understand some issues that are in front of us in the years to come. To begin the job I wanted to put on a map of the world the population of each contry in the year 2009, the growth rate and the total area of the country. The CIA World Factbook provides the data in the html file and also in machine-readable csv format for some entries like the ones needed for my purposes so I did not need to scrape their site. In fact I think I did not have started neither in that case. Anyway I also found the D2R Server for the CIA Factbook that provides a SPARQL endpoint and client to be queried in order to get the data so I decided to use this service and then put the data in a Google Fusion Table in order to view the data in a world map. The job has been quite easy. I made the  SPARQL query

PREFIX factbook: <;
SELECT ?country ?population ?growthrate ?capital_city ?area
?x  factbook:name ?country ;
factbook:population_total ?population ;
factbook:populationgrowthrate ?growthrate ;
factbook:capital_name ?capital_city ;
factbook:area_total ?area .

I wrote few lines of PHP code to parse the data returned in the JSON format. I put the data in a five columns Google spreadsheet to be imported in a  fusion table for the countries, populations, growth rates, capital name and total areas and I was instantly able to view the populations and the growth rates in two world maps with intensity degree to take account of the values. Before that, Google needs to geocode the countries, but it takes one minute to do that. After that I made some calculations using the spreadsheet in order to get the density of the population in each country, number of people per km², in the year 2009, the expected population at the end of the decade and again the density. The expected population was carried out using the formula

p2 = p1(1 + g)^y

where p2 is the population expected after y = 10 years, p1 is the population in the year 2009 and g is the growth rate of the country. I created three more columns for the calculated data. At the end of the job I had my fusion table with all the data viewable in a map of the world. A lot of considerations can be made viewing the maps, more easily than simply reading the data in a csv file or in a html page, one for each country. I do not want to enter the demographic issues here, but I think we are facing more problems in the years to come since the populations in countries in the southern side of the world are growing rapidly without a  strong enough economy to support that. China and India have a smaller growth rate than most african countries but their population are already big and so their contribution to the population growth for the decade will be big. This means that migration from these countries will go on. Going back to the technical arguments I have put all the maps in a page with the population maps side by side and the same for the density maps.