4 ms·
...or we can just use SPARQL and dbpedia!(http://wiki.dbpedia.org/ http://wiki.dbpedia.org/) There are questions where you'll have to scrap more than one page t
by betolink 10y ago
...or we can just use SPARQL and dbpedia!(http://wiki.dbpedia.org/ http://wiki.dbpedia.org/) There are questions where you'll have to scrap more than one page to get an answer and things could get really complicated with shell commands.
dbpedia is a triple-store that allows us to perform simple queries against wikipedia data like listing music bands based on a particular city:
SELECT ?name ?place
WHERE {
?place rdfs:label "Denver"@en .
?band dbo:hometown ?place .
?band rdf:type dbo:Band .
?band rdfs:label ?name .
FILTER langMatches(lang(?name),'en')
}
or queries that involve multiple subjects, categories etc.
- crypto5 10y agodbpedia provides very low coverage of wikipedia information.
- lacksconfidence 10y agoI looked at dbpedia, but it was non-obvious to me what statements to use. We can also use SPARQL with wikidata, although the coverage isn't particularly great.I threw together an example query for medalists and michael phelps doesn't make the list, because he doesn't have the appropriate participant of/award received statements: https://query.wikidata.org/#SELECT%20%3Fhuman%20%3FhumanLabel%20%3Fcount%20WHERE%20%7B%0A%20%20%7B%0A%20%20%20%20SELECT%20%3Fhuman%20%28COUNT%28%2a%29%20as%20%3Fcount%29%20WHERE%20%7B%0A%20%20%20%20%20%20%3Fevent%20wdt%3AP31%20wd%3AQ18536594%20.%20%23%20All%20items%20that%20are%20instance%20of%20Olympic%20sporting%20event%0A%20%20%0A%20%20%20%20%20%20%3Fmedal%20wdt%3AP279%20wd%3AQ636830%20.%20%20%20%20%23%20All%20items%20that%20are%20subclass%20of%20Olympic%20medal%20%0A%0A%20%20%20%20%20%20%3Fhuman%20p%3AP1344%20%3FparticipantStat%20.%20%23%20Humans%20with%20a%20participant%20of%20statement%0A%20%20%20%20%20%20%3FparticipantStat%20ps%3AP1344%20%3Fevent%20.%20%23%20..%20that%20has%20any%20of%20the%20values%20of%20%3Fevent%0A%20%20%20%20%20%20%3FparticipantStat%20pq%3AP166%20%3Fmedal%20.%20%23%20..%20with%20the%20award%20received%20qualifier%20of%20any%20of%20the%20values%20of%20%3Fmedal%0A%20%20%20%20%7D%0A%20%20%20%20GROUP%20BY%20%3Fhuman%0A%20%20%7D%0A%20%20%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22en%22.%20%7D%0A%7D%0AORDER%20BY%20DESC%28%3Fcount%29%0ALIMIT%20100%0A https://query.wikidata.org/#SELECT%20%3Fhuman%20%3FhumanLabe... SELECT ?human ?humanLabel ?count WHERE { { SELECT ?human (COUNT(*) as ?count) WHERE { ?event wdt:P31 wd:Q18536594 . # All items that are instance of Olympic sporting event ?medal wdt:P279 wd:Q636830 . # All items that are subclass of Olympic medal ?human p:P1344 ?participantStat . # Humans with a participant of statement ?participantStat ps:P1344 ?event . # .. that has any of the values of ?event ?participantStat pq:P166 ?medal . # .. with the award received qualifier of any of the values of ?medal } GROUP BY ?human } SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?count) LIMIT 100 EDIT: The dbpedia search should be something like: http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=SELECT+%3Fhuman+%3Fcount+WHERE%0D%0A%7B%0D%0A++%7B%0D%0A++++SELECT+%3Fhuman+%28count%28*%29+as+%3Fcount%29+WHERE+%7B%0D%0A++++++%3Fevent+rdf%3Atype+dbo%3AOlympicEvent%0D%0A++++++%7B%0D%0A++++++++%3Fevent+dbo%3AbronzeMedalist+%3Fhuman+.++%0D%0A++++++%7D+UNION+%7B%0D%0A++++++++%3Fevent+dbo%3AsilverMedalist+%3Fhuman%0D%0A++++++%7D+UNION+%7B%0D%0A++++++++%3Fevent+dbo%3AgoldMedalist+%3Fhuman%0D%0A++++++%7D%0D%0A++++%7D%0D%0A++++GROUP+BY+%3Fhuman%0D%0A++%7D%0D%0A%7D%0D%0AORDER+BY+DESC%28%3Fcount%29%0D%0ALIMIT+100&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=30000&debug=on http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbp... SELECT ?human ?count WHERE { { SELECT ?human (count(*) as ?count) WHERE { ?event rdf:type dbo:OlympicEvent { ?event dbo:bronzeMedalist ?human . } UNION { ?event dbo:silverMedalist ?human } UNION { ?event dbo:goldMedalist ?human } } GROUP BY ?human } } ORDER BY DESC(?count) LIMIT 100
- betolink 10y agoIt's not surprising that Phelps is not on the list, you're grouping by ?human and he is not... jk, maybe there is an ontology issue i.e. new triples are using a different class or that triple-store is not up to date.