The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Hot answers tagged

20

On 18. April 2016 the ticket "More efficient SPARQL queries for sitelinks" brought us a better way: schema:isPartOf. ?sitelink schema:about ?item . ?sitelink schema:inLanguage "en" . ?sitelink schema:isPartOf <https://en.wikipedia.org/> . Your full query now looks like this: PREFIX schema: <http://schema.org/> PREFIX wikibase: <http://...


16

I'm the developer of WDQ. It was developed as a stop-gap measure, until Wikidata would get its own query service. That took some years, but now we have SPARQL and https://query.wikidata.org/ so I plan to retire WDQ in the not-too-distant future. I strongly recommend you go for SPARQL, even if it seems a little verbose at first.


16

Try this one: prefix schema: <http://schema.org/> PREFIX wikibase: <http://wikiba.se/ontology#> PREFIX wd: <http://www.wikidata.org/entity/> PREFIX wdt: <http://www.wikidata.org/prop/direct/> SELECT ?cid ?country ?article WHERE { ?cid wdt:P31 wd:Q3624078 . OPTIONAL { ?cid rdfs:label ?country filter (lang(?country) = "...


15

Project DBpedia is a crowd-sourced community effort to extract structured information from Wikipedia. Drugs and Chemicals infoboxes are available in structured form, already. Check out http://dbpedia.org/page/Rosiglitazone


11

The right expression to use here is p:P31/ps:P31/wdt:P279*. Explanation: p:P31/ps:P31 means instance of, or instance of not marked as preferred. Only using p:P31 at this step would miss some instance. Following the "instance of" part, /wdt:P279* means this class or of any of its sub-classes/sub-sub-classes/etc So, it means instance of this class or of any ...


10

Wikipedia offers two interesting ways to get its own information: Complete database dumps in XML and SQL, as you wish. Special export very nice XML files downloadabe from only the categories that you specify. Images and uploaded files are stored elsewhere, also downloadable This is a XML file from the page requested using special export, the Wikipedia ...


8

Extracting data from Wikipedia infoboxes will not be necessary anymore in the not-too-distant future: The people at Wikipedia are currently working on a new project called Wikidata. Wikidata is a free knowledge base that can be read and edited by humans and machines alike. It is for data what Wikimedia Commons is for media files: it centralizes access to ...


7

The point in time property of the award received is what Wikidata calls a qualifier: Along with sources and ranks, qualifiers allow statements to be expanded on, annotated, or contextualized beyond what can be expressed in just a simple property-value pair. Here is the modified query to access the point in time of the award received: SELECT ?item ?...


6

The W3C hosts a list of large triple stores with documented deployments and numbers of triples. The top contenders with more than 10B triples currently are: AllegroGraph (1Trillion+) Stardog (50B) Oracle Spatial and Graph with Oracle Database (48B+) OpenLink Virtuoso v6.1 (15.4B+) Ontotext GraphDB (formerly BigOWLIM) (12B+) Garlik 4store (15B) Bigdata (12....


6

As Magnus Manske points out, SPARQL is the preferred way since, I would add, SPARQL is standardized BUT, here is the downside: The SPARQL endpoint, at this point in time, is NOT as reliable as WDQ yet, for example a query like this: https://wdq.wmflabs.org/api?q=tree[729][150][171,273,75,76,77,70,71,74,89] Which returns all animals in wikidata, takes 15 ...


6

I think this is close to what you want but there doesn't seem to be a property for group or period as a number. SELECT ?element ?elementLabel ?symbol ?protons ?group ?groupLabel ?period ?periodLabel WHERE { ?element wdt:P31 wd:Q11344; wdt:P1086 ?protons; wdt:P246 ?symbol. OPTIONAL {?element wdt:P279 ?group . ?group wdt:...


5

In the original query ?property and ?p are distinct values: ?property is wd:P54 (short for <http://www.wikidata.org/entity/P54>) and ?p is wdt:P54 (short for <http://www.wikidata.org/prop/direct/P54>). Notice that both refer to P54, but they are not the same. The two are connected by ?ref, which is wikibase:directClaim. This is why your ...


5

You can abbreviate SPARQL by expanding a given query fragment with default namespace definitions and other options. For instance the wikidata query command line client expands wdq -tplanet '?planet wdt:P31 wd:Q44559; wdt:P397 ?sun' to this SPARQL query PREFIX bd: <http://www.bigdata.com/rdf#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>...


4

Include SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } inside your WHERE clause Append the magic string Label and Description to the variable names of your SELECT For instance, if your item variable is ?item then SELECT ?itemLabel ?itemDescription will show the label and description of that Wikidata item. Full example (live demo) that ...


4

The reason is an error in loading data. It was a temporary problem, now fixed. The information about future plans and work on WDQS can be found on Wikimedia Discovery team page and Phabricator board.


4

Using the series ordinal added to the chemical groups, I can extract the group and period numbers with this query. SELECT ?element ?symbol ?protons ?group ?groupNumber ?period ?periodNumber WHERE { ?element wdt:P31 wd:Q11344 ; wdt:P1086 ?protons ; wdt:P246 ?symbol ; wdt:P279 ?group ; wdt:P279 ?period . OPTIONAL { ?group ...


4

Yes, you can, but it isn't short: SELECT distinct ?item ?itemLabel ?itemDescription WHERE{ ?item ?label "Mozambique"@en. ?item wdt:P31 wd:Q6256 . ?article schema:about ?item . ?article schema:inLanguage "en" . ?article schema:isPartOf <https://en.wikipedia.org/>. SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ...


4

SELECT ?place ?placeLabel ?location ?distance WHERE { wd:Q64 wdt:P625 ?arcLoc . ?place wdt:P31 wd:Q515 . ?place wdt:P17 wd:Q183 . SERVICE wikibase:around { ?place wdt:P625 ?location . bd:serviceParam wikibase:center ?arcLoc . bd:serviceParam wikibase:radius "50" . } SERVICE wikibase:...


4

...like if I made the filter of my 50 previous results... Wikibase:mwapi supports the limit parameter of the Entity Search service: SELECT ?item ?label ?order WHERE { VALUES (?type ?name) {(wd:Q5 "Jose")} SERVICE wikibase:mwapi { bd:serviceParam wikibase:api "EntitySearch" ; wikibase:endpoint "www.wikidata.org" ; ...


4

There isn't an article about Татьяна Колотильщикова in English Wikipedia. Just comment out the second and the third triple patterns in your query. Or try e. g. Q11000001 instead of Q10000001.


4

SELECT ?itemLabel ?population ?date { ?item wdt:P31 wd:Q50337; p:P1082 [pq:P585 ?date; ps:P1082 ?population] FILTER NOT EXISTS {?item p:P1082 [pq:P585 ?date_] FILTER (?date_ > ?date)} SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } Try it If you really need GROUP BY: SELECT ?itemLabel ?date ?population { { SELECT ?item ...


3

Not as straight forward as it seems. Here's a first attempt which works for the Liberian example. SELECT ?item ?territory ?territoryLabel WHERE { ?item wdt:P31 wd:Q3917681. # instance of: embassy ?item wdt:P137 wd:Q142. # operated by: France ?item wdt:P131 ?territory . ?territory wdt:P17 wd:Q1014 . #countries seem to have a wdt:P17 ...


3

Just add ?directorLabel to the select. The label service seems to work on any declared variable if you suffix it with 'Label'


3

You're trying to access qualifiers, that is statements on statements, all the doc you need is here: https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries#Working_with_qualifiers


3

I asked similar question on SO and got 2 answers. first answer: Using the URI instead of the variable ?item will get the information based on the entity Albert Einstein: PREFIX schema: <http://schema.org/> PREFIX bd: <http://www.bigdata.com/rdf#> PREFIX wdt: <http://www.wikidata.org/prop/direct/> PREFIX wikibase: <http://...


3

Wikipedia has an API to fetch raw content of the articles - http://www.mediawiki.org/wiki/API:Main_page There are plenty of libraries to interact with it, if you use Python I can recommend -https://github.com/callison-burch/wikipydia It seems that data you look for is standardized as {{drugbox}}/{{chembox}} template - http://en.wikipedia.org/wiki/Wikipedia:...


3

Before building a completely new system from scratch, you should first check if an existing system satisfies your requirements. There are a few possible candidates out there: As outlined in this answer, D2RQ and RDF HDT might be close to what you are looking for. In addition there is Tarql which provides SPARQL access to CSV files — which is, as far as I ...


3

You could allow users to upload/email .txt files containing queries, or upload URLs (e.g. pastebin, gist). Then your local code would read these .txt queries and add them to the repository (also standarized the query, validate the query, format the query, etc).


3

I am far from expert in this, but your question motivated me to learn a little, and I have a solution, below. In short, there is a "label service" which can be added to the WHERE clause. By simply adding it, you get access to the label, altLabel, and description of items in the query. There seems to be more nuance, but I'd be fooling if I tried to explain ...


3

SELECT ?location ?locationLabel WHERE { ?location wdt:P17 wd:Q39. ?location wdt:P31 ?settlement . ?settlement wdt:P279 wd:Q486972 . ?location rdfs:label ?de_label . FILTER (lang(?de_label) = "de") . FILTER (contains(?de_label, "Lugano")) . SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } Try it! In some cases, you might ...


Only top voted, non community-wiki answers of a minimum length are eligible