0

Using Sparql I can find person on Wikdata by his name:

SELECT distinct (SAMPLE(?image)as ?image) ?item ?itemLabel ?itemDescription
                (SAMPLE(?DR) as ?DR)(SAMPLE(?RIP) as ?RIP)(SAMPLE(?article) as ?article)
                WHERE {?item wdt:P31 wd:Q5. ?item ?label 'Putin' @en. OPTIONAL{?item wdt:P569 ?DR .}
                ?article schema:about ?item . ?article schema:inLanguage 'en'. ?article schema:isPartOf <https://en.wikipedia.org/>.
                OPTIONAL{?item wdt:P570 ?RIP .}
                OPTIONAL{?item wdt:P18 ?image .}
                SERVICE wikibase:label { bd:serviceParam wikibase:language 'en'. }}
                GROUP BY ?item ?itemLabel ?itemDescription

See this on Wikidat Query Service

Or if you know his ID:

SELECT distinct (SAMPLE(?image)as ?image)  ?item ?itemLabel ?itemDescription
            (SAMPLE(?DR) as ?DR)(SAMPLE(?RIP) as ?RIP)(SAMPLE(?article) as ?article)
            WHERE{ ?article  schema:about ?item ; schema:inLanguage  'en' ; schema:isPartOf    <https://en.wikipedia.org/>
            FILTER ( ?item = <http://www.wikidata.org/entity/Q303> )
            OPTIONAL { ?item  wdt:P569  ?DR }
            OPTIONAL { ?item  wdt:P570  ?RIP }
            OPTIONAL { ?item  wdt:P18  ?image }
            SERVICE wikibase:label { bd:serviceParam wikibase:language  'en'}}
            GROUP BY ?item ?itemLabel ?itemDescription

This query on Wikidata

But can't figure out how to get several random persons. If I remove search criteria and add limit 10, I get timeout, probably because it query all people even I just want 5 or 10.

Any idea how I can get 10 random people?

1 Answer 1

1

Below code gives different 10s of people in different runs (Random) but it gives new results only when running incognito or private tab (May be because of caching)

SELECT DISTINCT ?item ?itemLabel WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
  {
    SELECT DISTINCT ?item WHERE {
      ?item p:P31 ?statement0.
      ?statement0 (ps:P31/(wdt:P279*)) wd:Q5.
    }
    LIMIT 10
  }
}ORDER BY RAND() LIMIT 100

Screenshot of query results

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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