relaton-iso 1.13.3 → 1.13.5

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: 36560c5f9f49d1ff9855a051c71b562bfddd82fc1c862cf08b35b1129ec69720
4
- data.tar.gz: 4900a496e3b112b40dda6ab2acc4fe40db02084b01f42545de104a9c12dff922
3
+ metadata.gz: 545043eab945ec715dbf08c77dbd3c07379b87d0c06c317431223a97cb0b7816
4
+ data.tar.gz: 8f7594c2399682c780e47eb4e770deb19d48a17ffd5c21efc1938a463768eb25
5
5
  SHA512:
6
- metadata.gz: 2bcea09926b89d5c6d3017376b75ee79916d9e5ace197592dc6d42cd77d715d4ad67896165c5a17a0b31e7d8ab45c9219f6713aea03f6c08d9dc622792bff074
7
- data.tar.gz: 883976ba644b4ffae07292c4ad754fda13d195a3b34a6c03ffdc1382f44184bd0b0fd50ad270ae97ad69cf7d4d5c47e4f3d18098ed5bb6fcaa292deeb5c00e17
6
+ metadata.gz: 15b2628861c98f99a4879ec5d4c94f52d6551cdd20b322127d9ec4f42e2370e6f85350b95a257ecaaa49843bd29975a74e33fadff12bcbacc594d5ab3dd00d75
7
+ data.tar.gz: d5491c7ac248b6e3ba7bee7dbd2c32527103a3ede84dc14bfc67d29597c35e735ea47b5beed488f104ae3e9a46e28201aad0bc2667a85203a95d9bb9c9486c6e
@@ -5,7 +5,6 @@ name: rake
5
5
  on:
6
6
  push:
7
7
  branches: [ master, main ]
8
- tags: [ v* ]
9
8
  pull_request:
10
9
 
11
10
  jobs:
@@ -40,6 +40,13 @@ module RelatonIso
40
40
 
41
41
  resp = isobib_search_filter(query_pubid, opts)
42
42
 
43
+ # Try with ISO/IEC prefix if ISO not found
44
+ if resp[:hits].empty? && query_pubid.copublisher.nil? &&
45
+ query_pubid.publisher == "ISO"
46
+ resp_isoiec = retry_isoiec_prefix(query_pubid, opts)
47
+ resp = resp_isoiec unless resp_isoiec.nil?
48
+ end
49
+
43
50
  # return only first one if not all_parts
44
51
  ret = if !opts[:all_parts] || resp[:hits].size == 1
45
52
  resp[:hits].any? && resp[:hits].first.fetch(opts[:lang])
@@ -47,17 +54,37 @@ module RelatonIso
47
54
  resp[:hits].to_all_parts(opts[:lang])
48
55
  end
49
56
 
50
- if ret
51
- warn "[relaton-iso] (\"#{query_pubid}\") found #{ret.docidentifier.first.id}"
52
- else
53
- return fetch_ref_err(query_pubid)
54
- end
57
+ return fetch_ref_err(query_pubid) unless ret
55
58
 
56
- if (query_pubid.year && opts[:keep_year].nil?) || opts[:keep_year] || opts[:all_parts]
57
- ret
58
- else
59
- ret.to_most_recent_reference
59
+ # puts "xxxxx #{ret.docidentifier.first.id.inspect}"
60
+ response_docid = ret.docidentifier.first.id.sub(" (all parts)", "")
61
+ response_pubid = Pubid::Iso::Identifier.parse(response_docid)
62
+
63
+ puts "xxxxx query_pubid(#{query_pubid}) response_pubid(#{response_pubid})"
64
+
65
+ if query_pubid.to_s == response_pubid.to_s
66
+ warn "[relaton-iso] (\"#{query_pubid}\") Found exact match."
67
+ elsif matches_base?(query_pubid, response_pubid)
68
+ warn "[relaton-iso] (\"#{query_pubid}\") " \
69
+ "Found (\"#{response_pubid}\")."
70
+ elsif matches_base?(query_pubid, response_pubid, any_types_stages: true)
71
+ warn "[relaton-iso] (\"#{query_pubid}\") TIP: " \
72
+ "Found with different type/stage, " \
73
+ "please amend to (\"#{response_pubid}\")."
74
+ else
75
+ # when there are all parts
76
+ warn "[relaton-iso] (\"#{query_pubid}\") Found (\"#{response_pubid}\")."
60
77
  end
78
+
79
+ get_all = (
80
+ (query_pubid.year && opts[:keep_year].nil?) ||
81
+ opts[:keep_year] ||
82
+ opts[:all_parts]
83
+ )
84
+ return ret if get_all
85
+
86
+ ret.to_most_recent_reference
87
+
61
88
  rescue Pubid::Core::Errors::ParseError
62
89
  warn "[relaton-iso] (\"#{code}\") is not recognized as a standards identifier."
63
90
  end
@@ -67,12 +94,10 @@ module RelatonIso
67
94
  # @param all_parts [Boolean] match with any parts when true
68
95
  # @return [Boolean]
69
96
  def matches_parts?(query_pubid, pubid, all_parts: false)
70
- if all_parts
71
- # match only with documents with part number
72
- !pubid.part.nil?
73
- else
74
- query_pubid.part == pubid.part
75
- end
97
+ # match only with documents with part number
98
+ return !pubid.part.nil? if all_parts
99
+
100
+ query_pubid.part == pubid.part
76
101
  end
77
102
 
78
103
  def matches_base?(query_pubid, pubid, any_types_stages: false) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics?PerceivedComplexity
@@ -111,22 +136,68 @@ module RelatonIso
111
136
 
112
137
  private
113
138
 
139
+ # @param query_pubid [Pubid::Iso::Identifier] PubID with no results
114
140
  def fetch_ref_err(query_pubid) # rubocop:disable Metrics/MethodLength
115
- warn "[relaton-iso] WARNING: no match found online for #{query_pubid}. " \
116
- "The code must be exactly like it is on the standards website."
117
- if /\d-\d/.match? query_pubid.to_s
118
- warn "[relaton-iso] The provided document part may not exist, " \
119
- "or the document may no longer be published in parts."
141
+ warn "[relaton-iso] (\"#{query_pubid}\") " \
142
+ "Not found. " \
143
+ "The identifier must be exactly as shown on the ISO website."
144
+
145
+ if query_pubid.part
146
+ warn "[relaton-iso] (\"#{query_pubid}\") TIP: " \
147
+ "If it cannot be found, the document may no longer be published in parts."
120
148
  else
121
- warn "[relaton-iso] If you wanted to cite all document parts for " \
122
- "the reference, use \"#{query_pubid} (all parts)\"."
123
- warn "[relaton-iso] If the document is not a standard, use its " \
124
- "document type abbreviation (TS, TR, PAS, Guide)."
149
+ warn "[relaton-iso] (\"#{query_pubid}\") TIP: " \
150
+ "If you wish to cite all document parts for the reference, " \
151
+ "use (\"#{query_pubid.to_s(with_date: false)} (all parts)\")."
125
152
  end
153
+
154
+ unless %w(TS TR PAS Guide).include?(query_pubid.type)
155
+ warn "[relaton-iso] (\"#{query_pubid}\") TIP: " \
156
+ "If the document is not an International Standard, use its " \
157
+ "deliverable type abbreviation (TS, TR, PAS, Guide)."
158
+ end
159
+
126
160
  nil
127
161
  end
128
162
 
129
- # Search for hits. If no found then trying missed stages and ISO/IEC.
163
+ # @param pubid [Pubid::Iso::Identifier]
164
+ # @param missed_years [Array<String>]
165
+ def warn_missing_years(pubid, missed_years)
166
+ warn "[relaton-iso] (\"#{pubid}\") TIP: " \
167
+ "No match for edition year #{pubid.year}, " \
168
+ "but matches exist for #{missed_years.uniq.join(', ')}."
169
+ end
170
+
171
+ # Search for hits using ISO/IEC prefix.
172
+ #
173
+ # @param old_pubid [Pubid::Iso::Identifier] reference with ISO prefix
174
+ # @param opts [Hash]
175
+ # @return [Array<RelatonIso::Hit>]
176
+ def retry_isoiec_prefix(old_pubid, opts)
177
+ return nil unless (
178
+ old_pubid.copublisher.nil? &&
179
+ old_pubid.publisher == "ISO"
180
+ )
181
+
182
+ pubid = old_pubid.dup
183
+ pubid.copublisher = "IEC"
184
+ warn "[relaton-iso] (\"#{old_pubid}\") Not found, " \
185
+ "trying with ISO/IEC prefix (\"#{pubid}\")..."
186
+ resp_isoiec = isobib_search_filter(pubid, opts)
187
+
188
+ if resp_isoiec[:hits].empty?
189
+ warn "[relaton-iso] (\"#{pubid}\") Not found. "
190
+ return nil
191
+ end
192
+
193
+ warn "[relaton-iso] (\"#{pubid}\") TIP: " \
194
+ "Found with ISO/IEC prefix, " \
195
+ "please amend to (\"#{pubid}\")."
196
+
197
+ resp_isoiec
198
+ end
199
+
200
+ # Search for hits. If no found then trying missed stages.
130
201
  #
131
202
  # @param query_pubid [Pubid::Iso::Identifier] reference without correction
132
203
  # @param opts [Hash]
@@ -134,32 +205,29 @@ module RelatonIso
134
205
  def isobib_search_filter(query_pubid, opts) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
135
206
  missed_years = []
136
207
  query_pubid.part = nil if opts[:all_parts]
137
- warn "[relaton-iso] (\"#{query_pubid}\") fetching..."
208
+ warn "[relaton-iso] (\"#{query_pubid}\") Fetching from ISO..."
209
+
138
210
  # fetch hits collection
139
- hit_collection = search(query_pubid.to_s(with_date: false))
211
+ query_pubid_without_year = query_pubid.dup
212
+ # remove year for query
213
+ query_pubid_without_year.year = nil
214
+ hit_collection = search(query_pubid_without_year.to_s(with_date: false))
215
+
140
216
  # filter only matching hits
141
217
  res = filter_hits hit_collection, query_pubid, all_parts: opts[:all_parts]
142
218
  return res unless res[:hits].empty?
143
-
144
219
  missed_years += res[:missed_years]
220
+
145
221
  # lookup for documents with stages when no match without stage
146
222
  res = filter_hits hit_collection, query_pubid,
147
223
  all_parts: opts[:all_parts], any_types_stages: true
148
224
  return res unless res[:hits].empty?
149
-
150
225
  missed_years += res[:missed_years]
151
- # TODO: do this at pubid-iso
152
- if query_pubid.publisher == "ISO" && query_pubid.copublisher.nil? # try ISO/IEC if ISO not found
153
- warn "[relaton-iso] Attempting ISO/IEC retrieval"
154
- query_pubid.copublisher = "IEC"
155
- res = filter_hits hit_collection, query_pubid, all_parts: opts[:all_parts]
156
- missed_years += res[:missed_years]
157
- end
158
226
 
159
- if res[:hits].empty? && missed_years.any?
160
- warn "[relaton-iso] (There was no match for #{query_pubid.year}, though there "\
161
- "were matches found for #{missed_years.uniq.join(', ')}.)"
227
+ if missed_years.any?
228
+ warn_missing_years(query_pubid, missed_years)
162
229
  end
230
+
163
231
  res
164
232
  end
165
233
 
@@ -180,6 +248,7 @@ module RelatonIso
180
248
 
181
249
  filter_hits_by_year(result, query_pubid.year)
182
250
  end
251
+
183
252
  end
184
253
  end
185
254
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonIso
4
- VERSION = "1.13.3"
4
+ VERSION = "1.13.5"
5
5
  end
data/relaton_iso.gemspec CHANGED
@@ -39,6 +39,7 @@ Gem::Specification.new do |spec|
39
39
  spec.add_development_dependency "webmock"
40
40
 
41
41
  spec.add_dependency "algolia"
42
- spec.add_dependency "pubid-iso", "0.1.10"
42
+ spec.add_dependency "pubid-core", "1.2.1"
43
+ spec.add_dependency "pubid-iso", "~> 0.2.0"
43
44
  spec.add_dependency "relaton-iso-bib", "~> 1.13.0"
44
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-iso
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.3
4
+ version: 1.13.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-17 00:00:00.000000000 Z
11
+ date: 2022-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -179,19 +179,33 @@ dependencies:
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  - !ruby/object:Gem::Dependency
182
- name: pubid-iso
182
+ name: pubid-core
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - '='
186
186
  - !ruby/object:Gem::Version
187
- version: 0.1.10
187
+ version: 1.2.1
188
188
  type: :runtime
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - '='
193
193
  - !ruby/object:Gem::Version
194
- version: 0.1.10
194
+ version: 1.2.1
195
+ - !ruby/object:Gem::Dependency
196
+ name: pubid-iso
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 0.2.0
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 0.2.0
195
209
  - !ruby/object:Gem::Dependency
196
210
  name: relaton-iso-bib
197
211
  requirement: !ruby/object:Gem::Requirement
@@ -259,7 +273,7 @@ homepage: https://github.com/relaton/relaton-iso
259
273
  licenses:
260
274
  - BSD-2-Clause
261
275
  metadata: {}
262
- post_install_message:
276
+ post_install_message:
263
277
  rdoc_options: []
264
278
  require_paths:
265
279
  - lib
@@ -274,8 +288,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
274
288
  - !ruby/object:Gem::Version
275
289
  version: '0'
276
290
  requirements: []
277
- rubygems_version: 3.2.3
278
- signing_key:
291
+ rubygems_version: 3.1.6
292
+ signing_key:
279
293
  specification_version: 4
280
294
  summary: 'RelatonIso: retrieve ISO Standards for bibliographic use using the IsoBibliographicItem
281
295
  model'