8

Is there a way to extract the labels of the statements (property and object) in Wikidata? I want to get all the information that there is here:https://www.wikidata.org/wiki/Q42, properties and objects with label so both (wikidata.org/wiki/Property:P21, sex or gender) and (wikidata.org/wiki/Q6581097, male).

I've tried to do this using the wikidata toolkit, but I can't find a way to avoid doing multiple request to the api (I'm now getting ids from the Q42 entities and than, for each of this, I send an api request to get the label.)

The problem is the same I've found in this two questions:

How to get the name of a Wikidata item

https://stackoverflow.com/questions/31266398/getting-readable-results-from-wikidata

There's a way to get all the information when I retrieve the data for the Q42 entity?

Thanks!

5

You could do it with SPARQL:

SELECT ?wdLabel ?ooLabel
WHERE {
  VALUES (?s) {(wd:Q42)}
  ?s ?wdt ?o .
  ?wd wikibase:directClaim ?wdt .
  ?wd rdfs:label ?wdLabel .
  OPTIONAL {
    ?o rdfs:label ?oLabel .
    FILTER (lang(?oLabel) = "en")
  }
  FILTER (lang(?wdLabel) = "en")
  BIND (COALESCE(?oLabel, ?o) AS ?ooLabel)
 } ORDER BY xsd:integer(STRAFTER(STR(?wd), "http://www.wikidata.org/entity/P"))

Try it.

Perhaps the problem was that Wikidata supplies labels for entities in the wd: namespace only.

In order to provide labels for properties in the wdt: namespace, one have to use the special predicate wikibase:directClaim, which connects the wd: namespace entity for the property to its wdt: namespace representation.

2

You could try this one:

https://www.wikidata.org/wiki/Special:EntityData/Q42.ttl?flavor=full

Which generates RDF description of Q42 containing most of what you need I think (also available as .nt or .rdf). Be careful with it though - it can produce a lot of info, for Q42 it's over 1M but can be even more.

You can make more specific query using the SPARQL interface but I don't understand the requirements enough to write an actual query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.