Wikidata:WikiProject Video games/Queries

From Wikidata
Jump to navigation Jump to search

Video game-related SPARQL queries.

Series with the most games[edit]

The following query uses these:

  • Properties: instance of (P31) View with Reasonator View with SQID, part of the series (P179) View with Reasonator View with SQID
     1 SELECT ?series (SAMPLE(?label) AS ?label) (COUNT(?game) AS ?count)
     2 WHERE
     3 {
     4   ?game wdt:P31 wd:Q7889;
     5           wdt:P179 ?series.
     6   ?series rdfs:label ?label.
     7   FILTER(LANG(?label) = "en").
     8 }
     9 GROUP BY ?series
    10 ORDER BY DESC(?count)
    

Upcoming video games[edit]

The following query uses these:

  • Properties: instance of (P31) View with Reasonator View with SQID, publication date (P577) View with Reasonator View with SQID
    1 SELECT ?item ?itemLabel ?date WHERE {
    2    ?item wdt:P31 wd:Q7889 .
    3    ?item wdt:P577 ?date .
    4    FILTER(?date > NOW()).
    5    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    6 }
    

Recent video-game-related items with sitelinks and external identifiers[edit]

The following query uses these:

  • Properties: instance of (P31) View with Reasonator View with SQID, formatter URL (P1630) View with Reasonator View with SQID, subject item of this property (P1629) View with Reasonator View with SQID
     1 SELECT ?item ?qid (GROUP_CONCAT( DISTINCT ?sitelink) as ?sitelinks) (GROUP_CONCAT( DISTINCT ?identifier) as ?identifiers) {
     2   VALUES ?gametype {wd:Q7889 wd:Q16070115 wd:Q7058673} .
     3   ?item wdt:P31 ?gametype .
     4   BIND (xsd:integer(STRAFTER(str(?item), "Q")) AS ?qid)
     5   FILTER (?qid > 51090000) . 
     6   OPTIONAL { 
     7     # Get sitelinks
     8     ?s schema:about ?item ; schema:inLanguage ?lang . 
     9     BIND(CONCAT("[", str(?s), " ", ?lang, "]") as ?sitelink)
    10     
    11     # Get external identifiers
    12     ?item ?prop ?id.
    13     ?propItem wikibase:directClaim ?prop.
    14     ?propItem wikibase:propertyType wikibase:ExternalId.
    15     ?propItem wdt:P31 wd:Q28147643 .
    16     ?propItem wdt:P1630 ?formatterurl . 
    17     ?propItem wdt:P1629 ?website .
    18     ?propItem rdfs:label ?propItemLabel .
    19     FILTER (lang(?propItemLabel) = "en"). 
    20     BIND(IRI(REPLACE(?id, '^(.+)$', ?formatterurl)) AS ?url).
    21     BIND(CONCAT("[", str(?url), " ", ?propItemLabel, "]") as ?identifier)
    22   } 
    23 } GROUP BY ?item ?qid ORDER BY DESC(?qid) LIMIT 50
    

Video game characters named after humans[edit]

The following query uses these:

  • Properties: instance of (P31) View with Reasonator View with SQID, subclass of (P279) View with Reasonator View with SQID, named after (P138) View with Reasonator View with SQID
    1 SELECT DISTINCT ?item ?itemLabel ?named ?namedLabel
    2 WHERE 
    3 {
    4   ?item wdt:P31/wdt:P279* wd:Q1569167.
    5   ?item wdt:P138 ?named. 
    6   ?named wdt:P31 wd:Q5.
    7   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    8 }
    

source

Films based on video games[edit]

The following query uses these:

  • Properties: instance of (P31) View with Reasonator View with SQID, based on (P144) View with Reasonator View with SQID, subclass of (P279) View with Reasonator View with SQID
    1 SELECT ?item ?itemLabel ?videogame ?videogameLabel WHERE {
    2   ?item wdt:P31 wd:Q11424.
    3   ?item wdt:P144 ?videogame.
    4   ?videogame (wdt:P31/wdt:P279*) wd:Q7889.
    5   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    6 }
    

Characters from the Mario franchise by games in which they appear[edit]

The following query uses these:

Features: Graph (Q24515287) View with Reasonator View with SQID

1 #defaultView:Graph
2 SELECT ?item ?itemLabel ?game ?gameLabel ("00FFFF" AS ?rgb) WHERE {
3   ?item wdt:P31 wd:Q33093124.
4  ?game wdt:P674 ?item.
5   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
6 }

source

Games with the most player characters[edit]

The following query uses these:

  • Properties: instance of (P31) View with Reasonator View with SQID, subclass of (P279) View with Reasonator View with SQID, characters (P674) View with Reasonator View with SQID, object has role (P3831) View with Reasonator View with SQID
    1 SELECT ?item ?itemLabel (COUNT(?character) AS ?playable_characters) WHERE {
    2   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    3   ?item (wdt:P31/(wdt:P279*)) wd:Q7889;
    4     p:P674 ?statement.
    5   ?statement ps:P674 ?character;
    6     pq:P3831 wd:Q1062345.
    7 }
    8 GROUP BY ?item ?itemLabel
    9 ORDER BY DESC (?playable_characters)
    

Games with female protagonists[edit]

The following query uses these:

Games with female player characters[edit]

The following query uses these:

Graph of video games genres[edit]

Graph of video game genre (Q659563) and outline the ones that are linked to OLAC video game genre vocabulary (P6352)

The following query uses these:

Features: Graph (Q24515287) View with Reasonator View with SQID

 1 #defaultView:Graph
 2 SELECT DISTINCT ?genre ?genreLabel ?rgb ?OLAC ?_subclass_of ?_subclass_ofLabel WHERE {
 3   ?genre wdt:P31 wd:Q659563.
 4   OPTIONAL {
 5     ?genre wdt:P279 ?_subclass_of.
 6     { ?_subclass_of wdt:P31 wd:Q659563. } UNION {?_subclass_of wdt:P279 wd:Q2249149.}
 7   }
 8 
 9   OPTIONAL { ?genre wdt:P6352 ?OLAC. }
10   BIND(IF(BOUND(?OLAC), "FFA500", "7FFF00") AS ?rgb)
11   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
12 }


Video games whose composer is Japanese, not born in Tokyo, and less than 25 at the time[edit]

The following query uses these:

Timeline of games per platform[edit]

The following query uses these:

  • Properties: instance of (P31) View with Reasonator View with SQID, platform (P400) View with Reasonator View with SQID, publication date (P577) View with Reasonator View with SQID
     1 #defaultView:AreaChart
     2 SELECT (SAMPLE(?year) AS ?year) (COUNT(?_platform) AS ?count) (SAMPLE(?_platformLabel) AS ?platformLabel)  WHERE {
     3   ?video_game wdt:P31 wd:Q7889.
     4   ?video_game wdt:P400 ?_platform.
     5   ?video_game wdt:P577 ?date.
     6   BIND ( STR(year(?date)) as ?year )
     7   FILTER(BOUND(?year))
     8   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
     9                           ?_platform rdfs:label ?_platformLabel.}
    10 }
    11 GROUP BY ?year ?_platform
    12 HAVING (?count > 10)
    

Video games and their trailers[edit]

The following query uses these:

  • Properties: instance of (P31) View with Reasonator View with SQID, subclass of (P279) View with Reasonator View with SQID, YouTube video ID (P1651) View with Reasonator View with SQID, video (P10) View with Reasonator View with SQID, object has role (P3831) View with Reasonator View with SQID
     1 SELECT ?item ?itemLabel (GROUP_CONCAT(DISTINCT ?value; SEPARATOR = " ") AS ?trailer) WHERE {
     2   {
     3     ?item p:P1651 ?statement.
     4     ?statement ps:P1651 ?v;
     5       pq:P3831 wd:Q65972034.
     6     BIND(CONCAT("https://www.youtube.com/watch?v=", ?v) AS ?value)
     7   }
     8   UNION
     9   {
    10     ?item p:P10 ?statement.
    11     ?statement ps:P10 ?v;
    12       pq:P3831 wd:Q65972034.
    13     BIND(CONCAT("[", STR(?v), " C]") AS ?value)
    14   }
    15   ?item (wdt:P31/(wdt:P279*)) wd:Q7889.
    16   SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    17 }
    18 GROUP BY ?item ?itemLabel
    19 ORDER BY DESC (xsd:integer(STRAFTER(STR(?item), "Q")))
    

Video games with few statements and identifiers[edit]

See report at Wikidata:WikiProject Video games/Maintenance/Few statements

The following query uses these:

  • Properties: instance of (P31) View with Reasonator View with SQID
     1 #adapted from query by User:Matěj Suchánek
     2 SELECT ?item ?st ?sl ?ids str(?i) as ?offset)
     3 WITH { SELECT DISTINCT ?item        WHERE { ?item wdt:P31 wd:Q7889 ; wikibase:statements ?st . FILTER(?st < 2) }  } AS %all
     4 WITH { SELECT (COUNT(*) AS ?count)  WHERE { INCLUDE %all }  } AS %count
     5 WITH { SELECT (?item AS ?item2)     WHERE { INCLUDE %all }  } AS %all2
     6 WITH
     7 {
     8   SELECT ?item (SUM(?x) AS ?i)  WHERE  { INCLUDE %all . INCLUDE %all2 .
     9     BIND( IF( STR( ?item ) > STR( ?item2 ), 1, 0 ) AS ?x ) .
    10   } GROUP BY ?item
    11 } AS %main 
    12 WHERE
    13 {
    14   hint:Query hint:optimizer "None".
    15   INCLUDE %count .
    16   BIND(ROUND( ?count / 20) as ?slice ) BIND( ROUND(FLOOR( RAND() * ?count / 20 )) AS ?rnd) 
    17   INCLUDE %main .
    18   FILTER( ROUND( ( ?i/ ?slice - FLOOR( ?i / ?slice ) ) * ?slice ) = ?rnd)
    19   ?item wikibase:statements ?st; wikibase:sitelinks ?sl; wikibase:identifiers ?ids.
    20 }