wikidata_position_history 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6133f77b6d65f7decf2dcac481ff36a661a136fb79aff442677669801248437
4
- data.tar.gz: dccd3b0a0ed29d89c945756c9efa30e8c02f1c912b4402bec1a45a1c45d81e88
3
+ metadata.gz: dc98f35825bd450d052eaf0bbb84934db297933bce312b88fd8b545474b742bf
4
+ data.tar.gz: 663abb5df3df62744eebbdeaea9ce2e63bf90aeff5335bf2406ae66306dd7608
5
5
  SHA512:
6
- metadata.gz: 0112ca4aae8b9631d86bbf1c2cca5120808e9eb1bb207008e8ba8d221ec0c0c2d16e5f22ec0c59fe9454839c04fcd32bd71f67d1e1793e0d8c053b9d2f1d1471
7
- data.tar.gz: 8fd03fc79a37459686524927ba536ab770c22ac4c8d948fde53be1eafba155a3a0f2b072cd8ab8142867e0f57a8138ac62c1535d54bf5330e987bbfc7a2a553e
6
+ metadata.gz: d06f8f44b1b84107e9bed22f158479f2be66569511ee1f9dea33ceaa788a9cff118b15e3e0960723cc943a290f832c6442f5c8c8659fb275002449e57c90d285
7
+ data.tar.gz: edae0f0fc3223778d655546c873792f81da0f514c50be44e27a192717df11c2672eedc251e2cf210ab4e623cdd0c5a232b6e65671c7cc9b2a356a1498ed3426f
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ # [1.7.0] 2020-09-08
4
+
5
+ # Enchancements
6
+
7
+ * Yesterday’s future, when we said we'd do something a little better
8
+ with positions that have multiple inception or abolition dates, has
9
+ arrived. Now we display all of them (with a warning), rather than just
10
+ picking one semi-randomly.
11
+
12
+ # Improvements
13
+
14
+ * A query like https://w.wiki/bVz is taking about 6 seconds to run.
15
+ Changing that to https://w.wiki/bW3 drops that to about half a second.
16
+ If you were to guess that the first has now been replaced by the
17
+ second, you'd be entirely correct.
18
+
3
19
  # [1.6.0] 2020-09-07
4
20
 
5
21
  ## Enhancements
@@ -7,7 +7,7 @@ module WikidataPositionHistory
7
7
  # This is distinct from the mandate query itself to avoid complex
8
8
  # GROUP BY scenarios where people have multiple values for
9
9
  # biographical properties.
10
- class BioData < ItemQuery
10
+ class BioQuery < ItemQuery
11
11
  def raw_sparql
12
12
  <<~SPARQL
13
13
  # holder-biodata
@@ -24,7 +24,7 @@ module WikidataPositionHistory
24
24
  end
25
25
 
26
26
  # Represents a single row returned from the Position query
27
- class BioData
27
+ class BioRow
28
28
  def initialize(row)
29
29
  @row = row
30
30
  end
@@ -23,7 +23,11 @@ module WikidataPositionHistory
23
23
  attr_reader :itemid
24
24
 
25
25
  def sparql
26
- raw_sparql % itemid
26
+ raw_sparql % sparql_args
27
+ end
28
+
29
+ def sparql_args
30
+ itemid
27
31
  end
28
32
 
29
33
  def json
@@ -3,7 +3,7 @@
3
3
  module WikidataPositionHistory
4
4
  module SPARQL
5
5
  # SPARQL for fetching all officeholdings of a position
6
- class Mandates < ItemQuery
6
+ class MandatesQuery < ItemQuery
7
7
  def raw_sparql
8
8
  <<~SPARQL
9
9
  # position-mandates
@@ -28,7 +28,7 @@ module WikidataPositionHistory
28
28
  end
29
29
 
30
30
  # Represents a single row returned from the Mandates query
31
- class Mandate
31
+ class MandateRow
32
32
  def initialize(row)
33
33
  @row = row
34
34
  end
@@ -3,30 +3,42 @@
3
3
  module WikidataPositionHistory
4
4
  module SPARQL
5
5
  # SPARQL for fetching metadata about a position
6
- class PositionData < ItemQuery
6
+ class PositionQuery < ItemQuery
7
7
  def raw_sparql
8
8
  <<~SPARQL
9
9
  # position-metadata
10
10
 
11
- SELECT DISTINCT ?inception ?inception_precision ?abolition ?abolition_precision ?isPosition
11
+ SELECT DISTINCT ?item ?inception ?inception_precision ?abolition ?abolition_precision ?isPosition
12
12
  WHERE {
13
13
  VALUES ?item { wd:%s }
14
- BIND(EXISTS { ?item wdt:P279+ wd:Q4164871 } as ?isPosition)
15
- OPTIONAL { ?item p:P571/psv:P571 [ wikibase:timeValue ?inception; wikibase:timePrecision ?inception_precision ] }
16
- OPTIONAL { ?item p:P576/psv:P576 [ wikibase:timeValue ?abolition; wikibase:timePrecision ?abolition_precision ] }
14
+ BIND(EXISTS { wd:%s wdt:P279+ wd:Q4164871 } as ?isPosition)
15
+ OPTIONAL { ?item p:P571 [ a wikibase:BestRank ;
16
+ psv:P571 [ wikibase:timeValue ?inception; wikibase:timePrecision ?inception_precision ]
17
+ ] }
18
+ OPTIONAL { ?item p:P576 [ a wikibase:BestRank ;
19
+ psv:P576 [ wikibase:timeValue ?abolition; wikibase:timePrecision ?abolition_precision ]
20
+ ] }
17
21
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
18
22
  }
19
23
  SPARQL
20
24
  end
25
+
26
+ def sparql_args
27
+ [itemid, itemid]
28
+ end
21
29
  end
22
30
  end
23
31
 
24
32
  # Represents a single row returned from the Position query
25
- class PositionData
33
+ class PositionRow
26
34
  def initialize(row)
27
35
  @row = row
28
36
  end
29
37
 
38
+ def item
39
+ QueryService::WikidataItem.new(row.dig(:item, :value))
40
+ end
41
+
30
42
  def inception_date
31
43
  return if inception_date_raw.empty?
32
44
 
@@ -2,9 +2,9 @@
2
2
 
3
3
  require 'query_service'
4
4
  require 'sparql/item_query'
5
- require 'sparql/position_data'
6
- require 'sparql/bio_data'
7
- require 'sparql/mandates'
5
+ require 'sparql/position_query'
6
+ require 'sparql/bio_query'
7
+ require 'sparql/mandates_query'
8
8
  require 'wikidata_position_history/checks'
9
9
  require 'wikidata_position_history/template'
10
10
  require 'wikidata_position_history/report'
@@ -40,6 +40,68 @@ module WikidataPositionHistory
40
40
  attr_reader :later, :current, :earlier
41
41
  end
42
42
 
43
+ # Data about the position itself, to be passed to the report template
44
+ class Metadata
45
+ # simplified version of a WikidataPositionHistory::Check
46
+ Warning = Struct.new(:headline, :explanation)
47
+
48
+ def initialize(rows)
49
+ @rows = rows
50
+ end
51
+
52
+ def item
53
+ rows.map(&:item).first
54
+ end
55
+
56
+ def inception_date
57
+ return if inception_dates.empty?
58
+
59
+ inception_dates.join(' / ')
60
+ end
61
+
62
+ def inception_warning
63
+ count = inception_dates.count
64
+
65
+ return if count == 1
66
+ return Warning.new('Missing field', "#{item_qlink} is missing {{P|571}}") if count.zero?
67
+
68
+ Warning.new('Multiple values', "#{item_qlink} has more than one {{P|571}}")
69
+ end
70
+
71
+ def abolition_date
72
+ return if abolition_dates.empty?
73
+
74
+ abolition_dates.join(' / ')
75
+ end
76
+
77
+ def abolition_warning
78
+ return unless abolition_dates.count > 1
79
+
80
+ Warning.new('Multiple values', "#{item_qlink} has more than one {{P|576}}")
81
+ end
82
+
83
+ def position?
84
+ # this should be the same everywhere
85
+ rows.map(&:position?).first
86
+ end
87
+
88
+ private
89
+
90
+ attr_reader :rows
91
+
92
+ def inception_dates
93
+ rows.map(&:inception_date).compact.uniq(&:to_s).sort
94
+ end
95
+
96
+ def abolition_dates
97
+ rows.map(&:abolition_date).compact.uniq(&:to_s).sort
98
+ end
99
+
100
+ def item_qlink
101
+ item.qlink
102
+ end
103
+ end
104
+
43
105
  # The entire wikitext generated for this report
44
106
  class Report
45
107
  def initialize(position_id, template_class = ReportTemplate)
@@ -81,13 +143,11 @@ module WikidataPositionHistory
81
143
  private
82
144
 
83
145
  def metadata
84
- # TODO: we might get more than one response, if a position has
85
- # multiple dates
86
- @metadata ||= SPARQL::PositionData.new(position_id).results_as(PositionData).first
146
+ @metadata ||= Metadata.new(SPARQL::PositionQuery.new(position_id).results_as(PositionRow))
87
147
  end
88
148
 
89
149
  def biodata
90
- @biodata ||= SPARQL::BioData.new(position_id).results_as(BioData)
150
+ @biodata ||= SPARQL::BioQuery.new(position_id).results_as(BioRow)
91
151
  end
92
152
 
93
153
  def biodata_for(officeholder)
@@ -99,11 +159,11 @@ module WikidataPositionHistory
99
159
  end
100
160
 
101
161
  def sparql
102
- @sparql ||= SPARQL::Mandates.new(position_id)
162
+ @sparql ||= SPARQL::MandatesQuery.new(position_id)
103
163
  end
104
164
 
105
165
  def mandates
106
- @mandates ||= sparql.results_as(Mandate)
166
+ @mandates ||= sparql.results_as(MandateRow)
107
167
  end
108
168
 
109
169
  def no_items_output
@@ -25,7 +25,10 @@ module WikidataPositionHistory
25
25
  <% if metadata.abolition_date -%>
26
26
  |-
27
27
  | colspan="3" style="padding:0.5em 2em; border: none; background: #fff; font-size: 1.25em; text-align: right;" | '''Position abolished''': <%= metadata.abolition_date %>
28
- | style="padding:0.5em 2em 0.5em 1em; border: none; background: #fff; text-align: left;" |
28
+ | style="padding:0.5em 2em 0.5em 1em; border: none; background: #fff; text-align: left;" | \
29
+ <% [metadata.abolition_warning].compact.each do |warning| -%>
30
+ <span style="display: block">[[File:Pictogram voting comment.svg|15px|link=]]&nbsp;<span style="color: #d33; font-weight: bold; vertical-align: middle;"><%= warning.headline %></span>&nbsp;<ref><%= warning.explanation %></ref></span>\
31
+ <% end %>
29
32
  <% end -%>
30
33
  <% table_rows.map(&:values).each do |mandate, bio| -%>
31
34
  |-
@@ -40,7 +43,10 @@ module WikidataPositionHistory
40
43
  <% if metadata.inception_date -%>
41
44
  |-
42
45
  | colspan="3" style="padding:0.5em 2em; border: none; background: #fff; font-size: 1.25em; text-align: right;" | '''Position created''': <%= metadata.inception_date %>
43
- | style="padding:0.5em 2em 0.5em 1em; border: none; background: #fff; text-align: left;" |
46
+ | style="padding:0.5em 2em 0.5em 1em; border: none; background: #fff; text-align: left;" | \
47
+ <% [metadata.inception_warning].compact.each do |warning| -%>
48
+ <span style="display: block">[[File:Pictogram voting comment.svg|15px|link=]]&nbsp;<span style="color: #d33; font-weight: bold; vertical-align: middle;"><%= warning.headline %></span>&nbsp;<ref><%= warning.explanation %></ref></span>\
49
+ <% end %>
44
50
  <% end -%>
45
51
  |}
46
52
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WikidataPositionHistory
4
- VERSION = '1.6.0'
4
+ VERSION = '1.7.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikidata_position_history
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Bowden
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-09-07 00:00:00.000000000 Z
12
+ date: 2020-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mediawiki-replaceable-content
@@ -204,10 +204,10 @@ files:
204
204
  - exe/position-history-for-item
205
205
  - exe/update_wikidata_page
206
206
  - lib/query_service.rb
207
- - lib/sparql/bio_data.rb
207
+ - lib/sparql/bio_query.rb
208
208
  - lib/sparql/item_query.rb
209
- - lib/sparql/mandates.rb
210
- - lib/sparql/position_data.rb
209
+ - lib/sparql/mandates_query.rb
210
+ - lib/sparql/position_query.rb
211
211
  - lib/wikidata_position_history.rb
212
212
  - lib/wikidata_position_history/checks.rb
213
213
  - lib/wikidata_position_history/report.rb