Class: WikidataPositionHistory::SPARQL::PositionQuery
- Defined in:
- lib/sparql/position_query.rb
Overview
SPARQL for fetching metadata about a position
Instance Method Summary collapse
Methods inherited from ItemQuery
#initialize, #results_as, #wdqs_url
Constructor Details
This class inherits a constructor from WikidataPositionHistory::SPARQL::ItemQuery
Instance Method Details
#raw_sparql ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sparql/position_query.rb', line 7 def raw_sparql <<~SPARQL # position-metadata SELECT DISTINCT ?item ?inception ?inception_precision ?abolition ?abolition_precision ?replaces ?replacedBy ?derivedReplaces ?derivedReplacedBy ?isPosition ?isLegislator ?isConstituency ?representative_count ?legislature WHERE { VALUES ?item { wd:%s } BIND(EXISTS { wd:%s wdt:P279+ wd:Q4164871 } as ?isPosition) BIND(EXISTS { wd:%s wdt:P279+ wd:Q4175034 } as ?isLegislator) BIND(EXISTS { wd:%s wdt:P31/wdt:P279+ wd:Q192611 } as ?isConstituency) OPTIONAL { ?item p:P571 [ a wikibase:BestRank ; psv:P571 [ wikibase:timeValue ?inception; wikibase:timePrecision ?inception_precision ] ] } OPTIONAL { ?item p:P576 [ a wikibase:BestRank ; psv:P576 [ wikibase:timeValue ?abolition; wikibase:timePrecision ?abolition_precision ] ] } OPTIONAL { ?item wdt:P1365 ?replaces } OPTIONAL { ?item wdt:P1366 ?replacedBy } OPTIONAL { ?derivedReplaces wdt:P1366 ?item } OPTIONAL { ?derivedReplacedBy wdt:P1365 ?item } OPTIONAL { # if constituency ?item p:P1410 [ a wikibase:BestRank ; ps:P1410 ?representative_count ; pq:P194 ?legislature ] } } SPARQL end |
#sparql_args ⇒ Object
39 40 41 |
# File 'lib/sparql/position_query.rb', line 39 def sparql_args [itemid] * 4 end |