User:MisterSynergy/tennis/queries

From Wikidata
Jump to navigation Jump to search

Via Wikidata talk:WikiProject Tennis#Problem with ~3700 tennis tournament items.

general tennis related queries[edit]

SELECT ?item ?itemLabel (COUNT(?part) AS ?cnt) WHERE {
  ?item wdt:P279* wd:Q13219666; wdt:P527 ?part .
  ?part wdt:P279* wd:Q13219666 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
} GROUP BY ?item ?itemLabel
Try it!
SELECT ?item ?itemLabel (COUNT(*) AS ?cnt) WHERE {
  ?tournament wdt:P361 ?item; wdt:P279* wd:Q13219666 .
  ?item wdt:P279* wd:Q13219666 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
} GROUP BY ?item ?itemLabel
Try it!
SELECT ?item ?label ?class ?sitelinks (GROUP_CONCAT(?tourL; separator=', ') AS ?tours) WHERE {
  ?item wdt:P279* wd:Q13219666; wdt:P279 [ rdfs:label ?class ]; wikibase:sitelinks ?sitelinks .
  OPTIONAL { ?item rdfs:label ?label . FILTER(LANG(?label) = 'en') }
  FILTER(LANG(?class) = 'en') .
  
  ?item wdt:P361 ?tour .
  ?tour rdfs:label ?tourL .
  FILTER(LANG(?tourL) = 'en') 
  
  MINUS { ?tour wdt:P279* wd:Q7700500 } # rm tours here
  MINUS { ?tour wdt:P31*/wdt:P279* wd:Q167170 } # rm tennis at multi-sport events
} GROUP BY ?item ?label ?class ?sitelinks
Try it!

event management[edit]

(Potenital) duplicates:

SELECT ?tournament ?cclabel (GROUP_CONCAT(SUBSTR(STR(?event), 32); separator=', ') AS ?events) (COUNT(*) AS ?cnt) WHERE {
  ?event wdt:P31 wd:Q46190676; wdt:P361 ?tournament; wdt:P2094 ?cc . ?cc p:P2094 [ ps:P2094 wd:Q2735683; pq:P1013 wd:Q185836 ]; rdfs:label ?cclabel .
  FILTER(LANG(?cclabel) = 'en') .
  ?tournament wdt:P31 wd:Q47345468 .
} GROUP BY ?tournament ?cclabel HAVING (?cnt > 1 )
Try it!

Completeness (P2094 and P361):

SELECT ?event ?eventLabel ?competitionclass ?tournament ?tournamentLabel WHERE {
  ?event wdt:P31/wdt:P279* wd:Q46190676 .
  OPTIONAL { ?event wdt:P2094 ?competitionclass }
  OPTIONAL { ?event wdt:P361 ?tournament }
  FILTER(!BOUND(?competitionclass)|| !BOUND(?tournament)) .
  SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
}
Try it!

tournament management[edit]

SELECT ?tournament ?tournamentLabel ?tInstance ?tInstanceLabel ?tClass ?tClassLabel ?event ?eventLabel WITH {
  SELECT DISTINCT ?event ?tournament WHERE {
    ?event wdt:P31/wdt:P279* wd:Q46190676; wdt:P361 ?tournament .
    MINUS { ?tournament wdt:P31 wd:Q47345468 }
    MINUS { ?tournament wdt:P31/wdt:P279* wd:Q13219666 }
  }
} AS %s WHERE {
  INCLUDE %s .
  OPTIONAL { ?tournament wdt:P31 ?tInstance }
  OPTIONAL { ?tournament wdt:P279 ?tInstance }
#  FILTER(!BOUND(?tClass)) .
  SERVICE wikibase:label { bd:serviceParam wikibase:language '[AUTO_LANGUAGE],en,it,es,de' }
}
Try it!
SELECT DISTINCT ?event ?eventLabel ?lang ?name WHERE {
  ?event wdt:P31/wdt:P279* wd:Q46190676 .
  MINUS { ?event wdt:P361 [] }
  ?sitelink schema:about ?event; schema:inLanguage ?lang; schema:name ?name; schema:isPartOf ?project .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,es". }
} ORDER BY ASC(?lang)
Try it!

tour management[edit]

SELECT ?tour ?tourLabel ?year ?tourClass ?tourClassLabel ?start ?end ?early ?late WHERE {
  ?tour wdt:P31 wd:Q47358534 .
  OPTIONAL { ?tour wdt:P585 ?pit . BIND(YEAR(?pit) AS ?year) }
  OPTIONAL {
    ?tour wdt:P3450 ?tourClass .
    OPTIONAL { ?tourClass wdt:P571 ?inception . BIND(YEAR(?inception) AS ?start) }
    OPTIONAL { ?tourClass wdt:P576 ?abolished . BIND(YEAR(?abolished) AS ?end) }
  }
  BIND(IF(BOUND(?year) && BOUND(?start) && ?year < ?start, 'too early', '') AS ?early) .
  BIND(IF(BOUND(?year) && BOUND(?end) && ?year > ?end, 'too late', '') AS ?late) .
  FILTER(?tourClass NOT IN (wd:Q50658948, wd:Q300029, wd:Q4535172, wd:Q300008, wd:Q299345, wd:Q41000, wd:Q127678, wd:Q3775082, wd:Q1991741, wd:Q671970, wd:Q4017355, wd:Q1193885, wd:Q299363)) . # complete tours
  FILTER(?tourClass NOT IN (wd:Q1563479, wd:Q128471, wd:Q50574730, wd:Q2701085, wd:Q1334786, wd:Q3789061, wd:Q50657938, wd:Q50658266, wd:Q6978903, wd:Q50658729, wd:Q4824513)) . # incomplete tours
  FILTER(?tourClass NOT IN (wd:Q2537906, wd:Q50549235, wd:Q7934510)) . # womens tours; complicated
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY ASC(?tourClass) ASC(?year)
Try it!
SELECT ?wdt (COUNT(*) AS ?cnt) WHERE {
#SELECT ?item WHERE {
  ?tour wdt:P279 wd:Q7700500 .
  wikibase:WikibaseItem ^wikibase:propertyType/wikibase:directClaim ?wdt .
  [] ?wdt ?tour .
  FILTER(?tour != wd:Q50301185) .
#  ?item wdt:P31 ?tour .
#  FILTER(?wdt = wdt:P31) .
} GROUP BY ?wdt
Try it!
SELECT ?tournament ?tournamentLabel ?error WHERE {
  {
    ?tournament wdt:P31 wd:Q47358534 .
    MINUS { ?tournament (wdt:P31|wdt:P3450)/wdt:P279* wd:Q7700500 }
    BIND('missing subclass' AS ?error) .
  } UNION {
    ?tournament (wdt:P31|wdt:P3450)/wdt:P279* wd:Q7700500 . # also with wdt:P31/wdt:P279 and wdt:P31/wdt:P279/wdt:P279; mind that there are some special cases
    MINUS { ?tournament wdt:P31 wd:Q47358534 }
    MINUS { ?tournament wdt:P31 wd:Q50301185 }
    BIND('missing instance_of' AS ?error) .
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,it,es,de,fr". }
}
Try it!
SELECT ?quarterlySummary ?quarterlySummaryLabel ?tour ?tourLabel ?year WHERE {
  ?quarterlySummary wdt:P31 wd:Q48783127 .
  OPTIONAL { ?quarterlySummary wdt:P1269 ?tour . OPTIONAL { ?tour wdt:P585 ?pit . BIND(YEAR(?pit) AS ?year) } }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!

Lost items[edit]

See also:

SELECT DISTINCT ?item ?itemLabel ?year ?st ?sl WHERE {
  ?item wdt:P641 wd:Q847; wikibase:statements ?st; wikibase:sitelinks ?sl .
  OPTIONAL { ?item rdfs:label ?l }
  MINUS { ?item wdt:P31|wdt:P279 [] }
  BIND(xsd:integer(REPLACE(STR(?l), '^.*((20[01]|1[98]\\d)\\d).*$', '$1')) AS ?year) .
  SERVICE wikibase:label { bd:serviceParam wikibase:language '[AUTO_LANGUAGE],en,it,es,de,fr' }
} ORDER BY DESC(xsd:integer(STRAFTER(STR(?item), 'Q')))
Try it!