简体   繁体   中英

Get records for a list of multiple entities on Wikidata

I am mapping multiple entities (Q entries) in Wikidata for which I need the same record of properties (P entries). For sake of this question, say I have a list of five Wikidata entities (Q1, Q2, Q3, Q4, Q5) for which I want to retrieve the same property records (say, P1, P2, and P3). I know all Q and P in advance.

I understand how to pose a SPARQL query for an individual record (say for Q1), and I also understand how to specify the return of labels using the special SERVICE wikibase:label function for P1, P2, and P3.

First question, is there a way to loop over a list of entities (Q1 to Q5) with a given SPARQL query using only SPARQL?

If the answer is No, does any example Python or pseudocode exist for issuing single SPARQL queries looping over a list of external identifiers (Q1 to Q5), say provided as an external text or CSV file?

If there is a simple way to approach this, I'd love to hear.

I think you're looking for the VALUES clause:

SELECT ?item ?itemLabel ?class ?classLabel ?projectLabel WHERE {
  VALUES ?item { wd:Q1 wd:Q2 wd:Q3 wd:Q4 wd:Q5 }
  ?item wdt:P31 ?class;
        wdt:P5008 ?project.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM