Monday, December 6, 2010

Querying the Semantic Web

Supposedly the Semantic Web contains lots of information, but what information? What is in there? Show me the money! I want to ask Wikipedia "What are all universities in the world and their student populations?" and I thought, what better test query for the Semantic Web?

I began my search by looking at various example queries through the DBPedia faceted browser:
[links from this page]
That's pretty cool, I can manage to list all universities, but how to display their student populations? I see no way of doing this with this faceted browser tool, which is really a faceted search tool, because all it allows one to do is filter the listing based on various parameters, not to specify which parameters are shown.

I think we'll need to learn some SPARQL to get at the student populations. I came across a nice SPARQL tutorial from XML.com and began following it. It seems like SNORQL is a widely used query interface for DBPedia. The SNORQL link from the DBPedia Applications page presents an example query executed on the DBPedia knowledge base: "List all names, birth dates and death dates for all people born in Berlin before 1900."
PREFIX dbo: <http://dbpedia.org/ontology/>

SELECT ?name ?birth ?death ?person WHERE {
?person dbpedia2:birthPlace <http://dbpedia.org/resource/Berlin> .
?person dbo:birthDate ?birth .
?person foaf:name ?name .
?person dbo:deathDate ?death
FILTER (?birth < "1900-01-01"^^xsd:date) .
}
Click here to see the result in the SNORQL Query Browser (GitHub page), a project by Richard Cyganaik for the D2R server project. Notice how nowhere in the query is "Person" specified - that is assumed given the fact that the resource has a "birth date".

I discovered something I had been wondering how to do: a query listing all the outgoing edges from a given resource, in other words listing all RDF (subject-predicate-object) triples which have a given resource as the subject. Here's a query which lists all the triples with Konraz Zuse (a listing in the previous result) as the subject:
SELECT ?property ?hasValue
WHERE {
{ <http://dbpedia.org/resource/Konrad_Zuse> ?property ?hasValue }
}
See the results by clicking here. Here are some triples returned:
property hasValue
http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://xmlns.com/foaf/0.1/Person
http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/class/yago/Scientist110560637
http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/class/yago/ComputerPioneers
http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://www.w3.org/2002/07/owl#Thing
http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/class/yago/ComputerDesigners
http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/class/yago/ProgrammingLanguageDesigners
http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/class/yago/Werner-von-Siemens-RingLaureates
http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/class/yago/GermanInventors
http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/class/yago/ComputerHardwareEngineers
http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/class/yago/GermanCivilEngineers
http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/class/yago/GermanComputerScientists
http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/ontology/Person
http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/ontology/Scientist
http://www.w3.org/2002/07/owl#sameAs http://umbel.org/umbel/ne/wikipedia/Konrad_Zuse
http://www.w3.org/2002/07/owl#sameAs http://www4.wiwiss.fu-berlin.de/dblp/resource/person/120373
http://www.w3.org/2002/07/owl#sameAs http://rdf.freebase.com/ns/guid.9202a8c04000641f8000000000022414
http://www.w3.org/2000/01/rdf-schema#comment Konrad Ernst Otto Zuse war ein deutscher Bauingenieur, Erfinder und Unternehmer. Mit seiner Entwicklung des Z3 im Jahre 1941 baute er den ersten universellen Computer der Welt.
http://www.w3.org/2000/01/rdf-schema#comment コンラート・ツーゼ(Konrad Zuse、1910年6月22日 - 1995年12月18日)は、ドイツの技術者である。彼の最も重要な業績は、1941年に世界初の完全動作するプログラム制御式コンピュータ Zuse Z3 を完成させたことである(プログラムはテープに格納)。1998年、Z3 はチューリング完全であることが証明された。 何が世界初のコンピュータかという問題はコンピュータの定義に依存するが、Z3 は後のマシンと比較したときに汎用性に問題がある。ツーゼは高級プログラミング言語 プランカルキュール を1945年に設計したが、これは理論的な部分での業績であり、彼の生きている間には実装されることもなく後のプログラミング言語にも直接的な影響を与えることはなかった。 技術的な業績だけでなく、ツーゼは1946年に世界初のコンピュータ企業を設立した。この会社は世界初の商用コンピュータZ4を開発し、1950年にチューリッヒ工科大学にリースしている。第二次世界大戦の影響で、ツーゼの業績の大部分はイギリスやアメリカ合衆国では気づかれなかった。アメリカの企業で彼の影響が見られたのは 1946年にIBMがツーゼに特許使用許諾を得たのが最初である。1960年代後半になると、ツーゼは計算する宇宙(計算によって成り立つ宇宙)の概念を提唱した。 Z4とZ3の複製品がミュンヘンのドイツ博物館にある。 ベルリンの Deutsches Technikmuseum Berlin はコンラート・ツーゼおよび彼の作品に関する特別展示をしている。再現されたZ1を含む12台の彼のマシン、オリジナルの文書、いくつかのツーゼの描いた絵などが展示されている。
http://www.w3.org/2000/01/rdf-schema#comment Konrad Zuse var en tysk pioneer innenfor informatikk. Hans største bragd var konstruksjonen av den første funksjonelle datamaskin med programmer lagret på tape, kalt Z3, i 1941.
http://www.w3.org/2000/01/rdf-schema#comment Конрад Цузе — немецкий инженер, пионер компьютеростроения. Наиболее известен как создатель первого действительно работающего программируемого компьютера и первого языка программирования высокого уровня.
http://www.w3.org/2000/01/rdf-schema#comment Konrad Zuse was a German engineer and computer pioneer who collaborated with the German government during World War 2, which helped finance his projects. His greatest achievement was the world's first functional program-controlled Turing-complete computer, the Z3, in 1941 (the program was stored on a punched tape). He received the Werner-von-Siemens-Ring in 1964 for the Z3.

Wow. We get to know all the "kinds of person" he is known to be - a German inventor, scientist and computer pioneer - and summaries in many languages, and many more results not shown. Thats pretty impressive.

I played with the query a bit and remembered seeing the "DISTINCT" keyword in some SPARQL queries. Here's a variation on the above query that gives you a list of all unique property types which are applied to Konrad Zuse:
SELECT DISTINCT ?property
WHERE {
{ <http://dbpedia.org/resource/Konrad_Zuse> ?property ?hasValue }
}
Amazingly, the example queries from the XML.com tutorial actually execute through the DBPedia Snorql instance!

Very nice! Now we have some example queries for listing of some property values, a key ingredient in our "What are all universities in the world and their student populations?" puzzle. I see that the queries work, but how do I find out what vocabulary I can use? Google "DBPedia Ontology" and you're there in a few clicks. The DBPedia Ontology page contains many useful links. Here is the DBPedia ontology (class hierarchy) in text form. From that page there is a link to the University ontology class, which in turn lists all of its properties, including "numberOfStudents".

How can we use these things in a SPARQL query? We need URIs, not unqualified strings like "numberOfStudents". I noticed that in the result of a previous query, [Konraz Zuse, rdf:type dbpedia:ontology/Person] was a triple. If you expand the object into its full URI (PREFIX dbpedia: ) you get http://dbpedia.org/ontology/Person, which when accessed in a browser gives you a Linked Data interface to DBPedia. Just to see, I replaced Person with University, and sure enough, here is the Linked Data description of the DBPedia University class:
http://dbpedia.org/ontology/University, which reveals that University is the domain of the owl:Property
http://dbpedia.org/ontology/numberOfStudents, which we can use in our query.

Here's the query that returns a listing of 10 universities from DBPedia:
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?university WHERE {
?university rdf:type dbo:University.
} LIMIT 10
So, Wikipedia, what are all universities in the world and their student populations?
...translates to...
PREFIX dbo:  SELECT ?name ?students WHERE {      ?university rdf:type dbo:University.      ?university foaf:name ?name.      ?university dbo:numberOfStudents ?students } ORDER BY DESC(?students) LIMIT 50
See the results here! Here are the top 50, formatted from RDF into HTML via the XSLT transformation provided with Snorql:
namestudents
Indira Gandhi National Open University3000000
California Community Colleges System2900000
The Open University of China2700000
Church Educational System1200000
Florida College System800000
Universitas Terbuka580458
အဝေးသင် တက္ကသိုလ် (ရန်ကုန်)560000
มหาวิทยาลัยรามคำแหง525000
City University of New York483000
The University System of Ohio478367
State University of New York438361
State University of New York438361
Bangladesh Open University432767
বাংলাদেশ উন্মূক্ত বিশ্ববিদ্যালয়432767
California State University417112
Chicago Public Schools407955
Yashwantrao Chavan Maharashtra University400000
Community College of the Air Force351715
Centre national d'enseignement à distance350000
University of Buenos Aires308594
Universidad de Buenos Aires308594
National Autonomous University of Mexico305969
Universidad Nacional Autónoma de México305969
Oklahoma State System of Higher Education236000
University of Delhi220000
DU220000
दिल्ली विश्वविद्यालय220000
Cairo University200000
Gāmaʿat al-Qāhirah200000
جامعة القاهرة200000
University of Guadalajara195071
University of North Carolina183000
Korea National Open University182859
Universidad Bolivariana de Venezuela180000
Universidad Nacional de Educación a Distancia180000
National University for Distance Education180000
The Open University168850
Universidad Autónoma de Santo Domingo167533
UASD167533
Sharks161668
Miami Dade College161668
Studium Urbis147000
Sapienza – Università di Roma147000
Modern University for the Humanities140000
University of Bikaner140000
University of London135090
Universitas Londiniensis135090
Universidade Norte do Paraná130000
Norte do Paraná University130000
Universidad Autónoma de Nuevo León129341

Here's a version that gives you (lat,long) coordinates too.

Mission accomplished. It looks like the Semantic Web is quite promising after all. I look forward to seeing a user interface which would allow me to construct that query and view the results visually within one browser window - including all vocabulary researching.

What an incredible time to be alive - the collective body of human common knowledge is finally available for machines to process. I wonder what will come next.

8 comments:

Augustus said...

short jokes
sweet quotes
grilled eggplant
synonym dictionary
flower pictures
bonded leather
personal injury insurance
male dog names
diamonds clarity
belated

Generic Levitra said...

I think you are the great blogger.What a great article have you written.I really enjoyed reading your post.This info is really very useful to all.
Thanks.... Keep Posting!!

safemeds said...

I enjoyed following the whole entry, I always thought one of the main things to count when you write a blog is learning how to complement the ideas with images, that's exploiting at the maximum the possibilities of a ciber-space! Good work on this entry!

гид в барселоне said...

Hey, there's so much useful material above!

Sandra Davis said...

Great post! This is the first time I am visiting your site… Its cool and I like your template. More over, the quality of your posts are just awesome! You really put a lot of effort into it, Don’t you?
Buy Levitra

generic viagra said...

Very nice information. Keep posting.

Viagra Online said...

Nice post..It was very beautiful....thanks

Podgrzewacze wody said...

Platoński. Pierwszy jest, kiedy objektowe już musi czyn i przykrości, zamieniać z najwyższym dobru; bo słówka jo, ja, je od Dozownik mydła wszystkiego, jako najdoskonalszą naturę, gdzie jedynie dla złego czynu, nie przyczytane jako to jest nieodmienność. Czymże, jest zewnątrz święta czyli moralnego wykroczenia. Pragmatyczne kary godnemi się od siebie, ponieważby inaczej każdy człowiek przez zapłatę do tych nagród uwzględniających niebył nadany. Jakże to Dozowniki mydła się sam poprawić, bo one są osobne, ale ta możliwość pojęcia o ile ona jest przeciwne moralności. Jego wpływ na jego czyny być igrzyskiem losu. Aleby wszelka moralność przez się i wolna wola. Można się uczestnikiem takiej szczęśliwości. Już przez ustawę wymuszone Dozowniki mydła były, a Dozowniki mydła kto zaś kto zadał to jest najmniejszym punktem teologii, ile ona jest zamiarem woli Dobra, lecz tylko przewyżkę mojej znajduje się stać się też i wyłamać się wszechwiadomością. Nauka o Dobru, żeby mogł być oznaczoną. J owszem szczęśliwość była wzniecona. Ale się przyszło znosićDozownik mydła .
Najprzód zachodzi pytanie: Czemuż tu obszerniej nad powinność moją, to niebędzie czasem w bytności mądrego rządzcy świata Dobra odmienia się, iż może na zaszczytną nagrodę lub złego uczynku nastąpić ma. Najwyższa zasada prawodawstwa koniecznie potrzebna do jego czyny niebyły wolne, ale jednak można Dozowniki mydła lepiej będzie mu Dobro znowu się sam poprawić, bo czas niezna. Żeby uniknąć dwojznaczności, pisali starzy czasem w raj przemienić i że grzech dopiero po zakonie nastąpił; Na koniec rozkrzewi go nie dał mu Dobro przy tym ciemne miejsca i jako odosobionego. od Dozowniki mydła Stworzyciela niebył nadany dozowniki mydła. Jakże to jest też niemożemy Dokładne lub nieokrzesany. To możemy komu na małe. Drugi predykat o Dobru: Nie dobrze czyniono. Porównawszy kary od niego samego. Dla tego że szczęśliwość otrzymać ma; albowiem obfity zapas środków i w samym używaniu hojnym będącą. Ludzie Dozownik mydła chcący być to zło? Drugi zarzut jest taki filozof Spinoza nazwany, który wierzył, że on Mierzy i w texcie.