Page MenuHomePhabricator

Get a random set of entities from Wikidata
Closed, ResolvedPublic

Description

There are many entities in Wikidata and processing them all is too expensive for certain purposes. However, for statistical purposes (for example, to get any kind of proportion of property use, completeness, consistency, etc.), it's not necessary to retrieve and process them all, a small subset can be enough if representative (random).

Currently, it's hard to retrieve a random data set from Wikidata because:

  • the Wikidata Query Service doesn't retrieve entities randomly;
  • Special:Random requires two requests for every retrieved entity (first, a HTTP GET to Special:Random; then, a HTTP GET to the suggested item), doesn't support filters, and offers no significant advantage over directly generating random integers and addressing HTTP requests to the corresponding URIs.

It would be useful to have either:

  • the possibility of randomly retrieving data through the Wikidata Query Service (best option), or
  • a new tool to download an arbitrary number of random entities from Wikidata as a single file on demand.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Vvjjkkii renamed this task from Get a random set of entities from Wikidata to vtcaaaaaaa.Jul 1 2018, 1:09 AM
Vvjjkkii triaged this task as High priority.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii removed a subscriber: Aklapper.
CommunityTechBot renamed this task from vtcaaaaaaa to Get a random set of entities from Wikidata.Jul 2 2018, 4:05 PM
CommunityTechBot raised the priority of this task from High to Needs Triage.
CommunityTechBot updated the task description. (Show Details)
CommunityTechBot added a subscriber: Aklapper.

How random should it be?
What I mean, when you get a result set from WDQS, without sorting, it is in kind of "random" order already, due to multi-threaded nature of query processing in Blazegraph. But this order is not truly random - it just has some randomness in it due to the internals of the engine, but not suitable for, say, statistical sampling.

Theres's a sample service:

SELECT * WHERE {
service bd:sample {
  ?s wdt:P31 wd:Q5 .
   #
   # optional service params for the sample 
   bd:serviceParam bd:sample.limit 200 .
#   bd:serviceParam bd:sample.seed 0 .
   bd:serviceParam bd:sample.sampleType "RANDOM" .
}
}

That produces 200 random items about humans. Would that work for your use case?

abian claimed this task.

This query...

SELECT ?s WHERE { ?s wdt:P31 ?o } LIMIT 200

... gives us the following distribution of QIDs...

non-random.png (605×340 px, 8 KB)

... while this query...

SELECT ?s WHERE {
  SERVICE bd:sample {
    ?s wdt:P31 ?o .
    bd:serviceParam bd:sample.limit 200 .
    bd:serviceParam bd:sample.sampleType "RANDOM" .
  }
}

... gives us the following distribution of QIDs. <3

random.png (605×340 px, 11 KB)

This is great, @Smalyshev! We could prepare an example query so that people can see this trick (and so that we don't forget it). :-)