0

I am trying to write a query that returns all possible information from a wikidata page, as https://www.wikidata.org/wiki/Q1299. Ideally I would like to retrieve all info that are present in that page in english language.

So I am trying this query:

SELECT ?wdLabel ?ps_Label ?wdpqLabel ?pq_Label WHERE {
  VALUES ?artist {
    wd:Q1299
  }
  ?artist ?p ?statement.
  ?statement ?ps ?ps_.
  ?wd wikibase:claim ?p;
    wikibase:statementProperty ?ps.
  OPTIONAL {
    ?statement ?pq ?pq_.
    ?wdpq wikibase:qualifier ?pq.
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

which works quite fine but I would like to retrieve all wikidata ids on the ps_Label column.

For example here I have Paul McCartney as string and I would like to also have the wikidata ID associated to that item, which is Q2599

has part    Paul McCartney  start time  1960-01-01T00:00:00Z
has part    Paul McCartney  end time    1970-01-01T00:00:00Z
has part    Paul McCartney  object has role singer
has part    Paul McCartney  object has role instrumentalist

Something similar to this other below but I can't merge the two together as I am missing some hint on sub-properties here.

SELECT ?propUrl ?propLabel ?valUrl ?valLabel WHERE {
  wd:Q1299 ?propUrl ?valUrl.
  ?property ?ref ?propUrl;
    rdf:type wikibase:Property;
    rdfs:label ?propLabel.
  ?valUrl rdfs:label ?valLabel.
  FILTER((LANG(?valLabel)) = "en")
  FILTER((LANG(?propLabel)) = "en")
}
ORDER BY (?propUrl) (?valUrl)

Thanks a lot for your help!

  • 1
    if you want to Wikidata ID of the `ps_Label` why are you not just selecting `?ps_` as well? I mean, just do `SELECT ?wdLabel ?ps_ ?ps_Label ?wdpqLabel ?pq_Label WHERE {` - done. Or are you asking for something different? – UninformedUser Apr 03 '21 at 09:55
  • This is exactly what I need! Thanks a lot! – shoegazerstella Apr 06 '21 at 09:09

1 Answers1

0

This isn’t exactly what you’re asking for, but if you really just want all data on a single object, it is far easier and more economical to use the data access provided by https://www.wikidata.org/wiki/Special:EntityData/Q2599.json

Matthias Winkelmann
  • 15,870
  • 7
  • 64
  • 76