relaton 2.1.0 → 2.2.0.pre.alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +1 -1
- data/CLAUDE.md +8 -0
- data/Gemfile +8 -0
- data/lib/relaton/db/cache.rb +232 -0
- data/lib/relaton/db/config.rb +24 -0
- data/lib/relaton/db/registry.rb +119 -0
- data/lib/relaton/db/util.rb +9 -0
- data/lib/relaton/db/version.rb +5 -0
- data/lib/relaton/db/workers_pool.rb +22 -0
- data/lib/relaton/db.rb +21 -206
- data/lib/relaton/version.rb +1 -1
- data/lib/relaton.rb +2 -10
- data/relaton.gemspec +47 -36
- data/spec/relaton/config_spec.rb +1 -1
- data/spec/relaton/db_cache_spec.rb +4 -4
- data/spec/relaton/db_spec.rb +18 -7
- data/spec/relaton/registry_spec.rb +39 -39
- data/spec/relaton/util_spec.rb +1 -1
- data/spec/relaton_meta_spec.rb +25 -0
- data/spec/relaton_spec.rb +163 -88
- data/spec/spec_helper.rb +2 -2
- data/spec/vcr_cassetes/api_relaton_org.yml +8 -8
- data/spec/vcr_cassetes/api_relaton_org_unavailable.yml +76 -79
- data/spec/vcr_cassetes/cc_dir_10005_2019.yml +80 -77
- data/spec/vcr_cassetes/cipm_meeting_43.yml +1372 -1380
- data/spec/vcr_cassetes/gb_t_20223_2006.yml +500 -504
- data/spec/vcr_cassetes/iso_19115_1.yml +17204 -13047
- data/spec/vcr_cassetes/iso_19115_1_2.yml +193 -240
- data/spec/vcr_cassetes/iso_19115_1_std.yml +17207 -13050
- data/spec/vcr_cassetes/iso_19115_all_parts.yml +116 -160
- data/spec/vcr_cassetes/iso_19133_2005.yml +78 -82
- data/spec/vcr_cassetes/iso_combined_applied.yml +186 -232
- data/spec/vcr_cassetes/iso_combined_included.yml +187 -233
- data/spec/vcr_cassetes/ogc_19_025r1.yml +211 -208
- data/spec/vcr_cassetes/omg_ami4ccm_1_0.yml +246 -246
- data/spec/vcr_cassetes/rfc_8341.yml +1026 -1020
- metadata +133 -78
- data/.rubocop.yml +0 -12
- data/lib/relaton/config.rb +0 -24
- data/lib/relaton/db_cache.rb +0 -230
- data/lib/relaton/registry.rb +0 -118
- data/lib/relaton/util.rb +0 -7
- data/lib/relaton/workers_pool.rb +0 -21
- data/spec/vcr_cassetes/3gpp_tr_00_01u_umts_3_0_0.yml +0 -12720
- data/spec/vcr_cassetes/cie_001_1980.yml +0 -401
- data/spec/vcr_cassetes/doi_10_6028_nist_ir_8245.yml +0 -86
- data/spec/vcr_cassetes/ecma_6.yml +0 -112
- data/spec/vcr_cassetes/en_10160_1999.yml +0 -13624
- data/spec/vcr_cassetes/ieee_528_2019.yml +0 -2786
- data/spec/vcr_cassetes/iso_dis.yml +0 -157
data/lib/relaton/db.rb
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
require "relaton/bib"
|
|
2
|
+
require "yaml"
|
|
3
|
+
require "net/http"
|
|
4
|
+
require "nokogiri"
|
|
5
|
+
require "fileutils"
|
|
6
|
+
require "date"
|
|
7
|
+
|
|
1
8
|
module Relaton
|
|
2
9
|
class Db
|
|
3
10
|
# @param global_cache [String] directory of global DB
|
|
4
11
|
# @param local_cache [String] directory of local DB
|
|
5
12
|
def initialize(global_cache, local_cache)
|
|
6
|
-
@registry =
|
|
13
|
+
@registry = Registry.instance
|
|
7
14
|
gpath = global_cache && File.expand_path(global_cache)
|
|
8
15
|
@db = open_cache_biblio(gpath)
|
|
9
16
|
lpath = local_cache && File.expand_path(local_cache)
|
|
@@ -53,14 +60,7 @@ module Relaton
|
|
|
53
60
|
# after this date (inclusive, formats: "YYYY", "YYYY-MM",
|
|
54
61
|
# or "YYYY-MM-DD")
|
|
55
62
|
#
|
|
56
|
-
# @return [nil, RelatonBib::BibliographicItem,
|
|
57
|
-
# RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
|
|
58
|
-
# RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
|
|
59
|
-
# RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
|
|
60
|
-
# RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
|
|
61
|
-
# RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
|
|
62
|
-
# RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
|
|
63
|
-
# RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
|
|
63
|
+
# @return [nil, RelatonBib::BibliographicItem, ...]
|
|
64
64
|
##
|
|
65
65
|
def fetch(text, year = nil, opts = {})
|
|
66
66
|
reference = text.strip
|
|
@@ -132,24 +132,6 @@ module Relaton
|
|
|
132
132
|
end
|
|
133
133
|
end
|
|
134
134
|
|
|
135
|
-
# @param code [String]
|
|
136
|
-
# @param year [String, NilClass]
|
|
137
|
-
# @param stdclass [Symbol, NilClass]
|
|
138
|
-
#
|
|
139
|
-
# @param opts [Hash]
|
|
140
|
-
# @option opts [Boolean] :all_parts If all-parts reference is required
|
|
141
|
-
# @option opts [Boolean] :keep_year If undated reference should return
|
|
142
|
-
# actual reference with year
|
|
143
|
-
# @option opts [Integer] :retries (1) Number of network retries
|
|
144
|
-
#
|
|
145
|
-
# @return [nil, RelatonBib::BibliographicItem,
|
|
146
|
-
# RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
|
|
147
|
-
# RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
|
|
148
|
-
# RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
|
|
149
|
-
# RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
|
|
150
|
-
# RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
|
|
151
|
-
# RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
|
|
152
|
-
# RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
|
|
153
135
|
def fetch_std(code, year = nil, stdclass = nil, opts = {})
|
|
154
136
|
std = nil
|
|
155
137
|
@registry.processors.each do |name, processor|
|
|
@@ -194,28 +176,14 @@ module Relaton
|
|
|
194
176
|
|
|
195
177
|
private
|
|
196
178
|
|
|
197
|
-
# @param (see #fetch_api)
|
|
198
|
-
# @return (see #fetch_api)
|
|
199
179
|
def fetch_doc(code, year, opts, processor)
|
|
200
|
-
if
|
|
201
|
-
processor)
|
|
180
|
+
if Db.configuration.use_api then fetch_api(code, year, opts, processor)
|
|
202
181
|
else processor.get(code, year, opts)
|
|
203
182
|
end
|
|
204
183
|
end
|
|
205
184
|
|
|
206
|
-
#
|
|
207
|
-
# @param code [String]
|
|
208
|
-
# @param year [String]
|
|
209
|
-
#
|
|
210
|
-
# @param opts [Hash]
|
|
211
|
-
# @option opts [Boolean] :all_parts If all-parts reference is required
|
|
212
|
-
# @option opts [Boolean] :keep_year If undated reference should return
|
|
213
|
-
# actual reference with year
|
|
214
|
-
#
|
|
215
|
-
# @param processor [Relaton::Processor]
|
|
216
|
-
# @return [RelatonBib::BibliographicItem, nil]
|
|
217
185
|
def fetch_api(code, year, opts, processor)
|
|
218
|
-
url = "#{
|
|
186
|
+
url = "#{Db.configuration.api_host}" \
|
|
219
187
|
"/api/v1/document?#{params(code, year, opts)}"
|
|
220
188
|
rsp = Net::HTTP.get_response URI(url)
|
|
221
189
|
processor.from_xml rsp.body if rsp.code == "200"
|
|
@@ -223,36 +191,16 @@ module Relaton
|
|
|
223
191
|
processor.get(code, year, opts)
|
|
224
192
|
end
|
|
225
193
|
|
|
226
|
-
#
|
|
227
|
-
# Make string of parametrs
|
|
228
|
-
#
|
|
229
|
-
# @param [String] code
|
|
230
|
-
# @param [String] year
|
|
231
|
-
# @param [Hash] opts
|
|
232
|
-
#
|
|
233
|
-
# @return [String]
|
|
234
|
-
#
|
|
235
194
|
def params(code, year, opts)
|
|
236
195
|
opts.merge(code: code, year: year).map { |k, v| "#{k}=#{v}" }.join "&"
|
|
237
196
|
end
|
|
238
197
|
|
|
239
|
-
# @param file [String] file path
|
|
240
|
-
# @param xml [String] content in XML format
|
|
241
|
-
# @param text [String, nil] text to serach
|
|
242
|
-
# @param edition [String, nil] edition to filter
|
|
243
|
-
# @param year [Integer, nil] year to filter
|
|
244
|
-
# @return [BibliographicItem, nil]
|
|
245
198
|
def search_xml(file, xml, text, edition, year)
|
|
246
199
|
return unless text.nil? || match_xml_text?(xml, text)
|
|
247
200
|
|
|
248
201
|
search_edition_year(file, xml, edition, year)
|
|
249
202
|
end
|
|
250
203
|
|
|
251
|
-
# @param file [String] file path
|
|
252
|
-
# @param content [String] content in XML or YAML format
|
|
253
|
-
# @param edition [String, nil] edition to filter
|
|
254
|
-
# @param year [Integer, nil] year to filter
|
|
255
|
-
# @return [BibliographicItem, nil]
|
|
256
204
|
def search_edition_year(file, content, edition, year) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
|
257
205
|
processor = @registry.processor_by_ref(file.split("/")[-2])
|
|
258
206
|
item = if file.match?(/xml$/) then processor.from_xml(content)
|
|
@@ -264,14 +212,6 @@ module Relaton
|
|
|
264
212
|
end)
|
|
265
213
|
end
|
|
266
214
|
|
|
267
|
-
#
|
|
268
|
-
# Look up text in the XML elements attributes and content
|
|
269
|
-
#
|
|
270
|
-
# @param xml [String] content in XML format
|
|
271
|
-
# @param text [String, nil] text to serach
|
|
272
|
-
#
|
|
273
|
-
# @return [Boolean]
|
|
274
|
-
#
|
|
275
215
|
def match_xml_text?(xml, text)
|
|
276
216
|
esc = Regexp.escape(text)
|
|
277
217
|
pat = "((?<attr>=((?<apstr>')|\"" \
|
|
@@ -281,18 +221,6 @@ module Relaton
|
|
|
281
221
|
.match?(xml)
|
|
282
222
|
end
|
|
283
223
|
|
|
284
|
-
# @param code [String]
|
|
285
|
-
# @param year [String, nil]
|
|
286
|
-
# @param stdslass [String]
|
|
287
|
-
#
|
|
288
|
-
# @param opts [Hash] options
|
|
289
|
-
# @option opts [Boolean] :all_parts If all-parts reference is required
|
|
290
|
-
# @option opts [Boolean] :keep_year If undated reference should return
|
|
291
|
-
# actual reference with year
|
|
292
|
-
# @option opts [Integer] :retries (1) Number of network retries
|
|
293
|
-
#
|
|
294
|
-
# @return [nil, Relaton::Bib::ItemData
|
|
295
|
-
#
|
|
296
224
|
def combine_doc(code, year, opts, stdclass) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
|
297
225
|
return if stdclass == :relaton_bipm
|
|
298
226
|
|
|
@@ -323,19 +251,6 @@ module Relaton
|
|
|
323
251
|
end
|
|
324
252
|
end
|
|
325
253
|
|
|
326
|
-
# TODO: i18n
|
|
327
|
-
# Fofmat ID
|
|
328
|
-
# @param code [String]
|
|
329
|
-
# @param year [String]
|
|
330
|
-
#
|
|
331
|
-
# @param opts [Hash]
|
|
332
|
-
# @option opts [Boolean] :all_parts If all-parts reference is required
|
|
333
|
-
# @option opts [Boolean] :keep_year If undated reference should return
|
|
334
|
-
# actual reference with year
|
|
335
|
-
# @option opts [Integer] :retries (1) Number of network retries
|
|
336
|
-
#
|
|
337
|
-
# @param stdClass [Symbol]
|
|
338
|
-
# @return [Array<String>] docid and code
|
|
339
254
|
def std_id(code, year, opts, stdclass)
|
|
340
255
|
prefix, code = strip_id_wrapper(code, stdclass)
|
|
341
256
|
ret = code
|
|
@@ -348,59 +263,23 @@ module Relaton
|
|
|
348
263
|
["#{prefix}(#{ret.strip})", code]
|
|
349
264
|
end
|
|
350
265
|
|
|
351
|
-
# Find prefix and clean code
|
|
352
|
-
# @param code [String]
|
|
353
|
-
# @param stdClass [Symbol]
|
|
354
|
-
# @return [Array]
|
|
355
266
|
def strip_id_wrapper(code, stdclass)
|
|
356
267
|
prefix = @registry[stdclass].prefix
|
|
357
268
|
code =
|
|
358
269
|
if code.is_a?(String)
|
|
359
|
-
code.sub("
|
|
270
|
+
code.sub("–", "-").sub(/^#{prefix}\((.+)\)$/, "\\1")
|
|
360
271
|
else code.to_s
|
|
361
272
|
end
|
|
362
273
|
[prefix, code]
|
|
363
274
|
end
|
|
364
275
|
|
|
365
|
-
#
|
|
366
|
-
# @param entry [String, nil] XML string
|
|
367
|
-
# @param stdclass [Symbol]
|
|
368
|
-
#
|
|
369
|
-
# @return [nil, RelatonBib::BibliographicItem,
|
|
370
|
-
# RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
|
|
371
|
-
# RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
|
|
372
|
-
# RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
|
|
373
|
-
# RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
|
|
374
|
-
# RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
|
|
375
|
-
# RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
|
|
376
|
-
# RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
|
|
377
276
|
def bib_retval(entry, stdclass)
|
|
378
277
|
if entry && !entry.match?(/^not_found/)
|
|
379
278
|
@registry[stdclass].from_xml(entry)
|
|
380
279
|
end
|
|
381
280
|
end
|
|
382
281
|
|
|
383
|
-
# @param code [String]
|
|
384
|
-
# @param year [String]
|
|
385
|
-
#
|
|
386
|
-
# @param opts [Hash]
|
|
387
|
-
# @option opts [Boolean] :all_parts If all-parts reference is required
|
|
388
|
-
# @option opts [Boolean] :keep_year If undated reference should return
|
|
389
|
-
# actual reference with year
|
|
390
|
-
# @option opts [Integer] :retries (1) Number of network retries
|
|
391
|
-
#
|
|
392
|
-
# @param stdclass [Symbol]
|
|
393
|
-
# @return [nil, RelatonBib::BibliographicItem,
|
|
394
|
-
# RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
|
|
395
|
-
# RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
|
|
396
|
-
# RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
|
|
397
|
-
# RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
|
|
398
|
-
# RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
|
|
399
|
-
# RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
|
|
400
|
-
# RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
|
|
401
282
|
def check_bibliocache(code, year, opts, stdclass) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
|
402
|
-
# When date filters are present, check if the base
|
|
403
|
-
# (non-date-filtered) cache entry satisfies the range
|
|
404
283
|
if opts[:publication_date_before] || opts[:publication_date_after]
|
|
405
284
|
base_opts = opts.except(
|
|
406
285
|
:publication_date_before, :publication_date_after
|
|
@@ -447,27 +326,6 @@ module Relaton
|
|
|
447
326
|
bib_retval(db[id], stdclass)
|
|
448
327
|
end
|
|
449
328
|
|
|
450
|
-
#
|
|
451
|
-
# Create new bibliographic entry if it doesn't exist in database
|
|
452
|
-
#
|
|
453
|
-
# @param code [String]
|
|
454
|
-
# @param year [String]
|
|
455
|
-
#
|
|
456
|
-
# @param opts [Hash]
|
|
457
|
-
# @option opts [Boolean, nil] :all_parts If true then all-parts reference is
|
|
458
|
-
# requested
|
|
459
|
-
# @option opts [Boolean, nil] :keep_year If true then undated reference
|
|
460
|
-
# should return actual reference with year
|
|
461
|
-
# @option opts [Integer] :retries (1) Number of network retries
|
|
462
|
-
# @option opts [Boolean] :no_cache If true then don't use cache
|
|
463
|
-
#
|
|
464
|
-
# @param stdclass [Symbol]
|
|
465
|
-
# @param db [Relaton::DbCache,`nil]
|
|
466
|
-
# @param id [String, nil] docid
|
|
467
|
-
#
|
|
468
|
-
# @return [String] bibliographic entry
|
|
469
|
-
# XML or "redirection ID" or "not_found YYYY-MM-DD" string
|
|
470
|
-
#
|
|
471
329
|
def new_bib_entry(code, year, opts, stdclass, **args)
|
|
472
330
|
entry = @semaphore.synchronize { args[:db] && args[:db][args[:id]] }
|
|
473
331
|
if !entry || opts[:no_cache]
|
|
@@ -493,21 +351,9 @@ module Relaton
|
|
|
493
351
|
args[:no_cache] ? bib_entry(bib) : entry
|
|
494
352
|
end
|
|
495
353
|
|
|
496
|
-
#
|
|
497
|
-
# If the reference isn't equal to the document identifier
|
|
498
|
-
# then store the document in the cache and create
|
|
499
|
-
# for the reference a redirection to the document
|
|
500
|
-
#
|
|
501
|
-
# @param [<Type>] bib <description>
|
|
502
|
-
# @param [<Type>] stdclass <description>
|
|
503
|
-
# @param [<Type>] **args <description>
|
|
504
|
-
#
|
|
505
|
-
# @return [<Type>] <description>
|
|
506
|
-
#
|
|
507
354
|
def check_entry(bib, stdclass, **args) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
|
508
355
|
bib_id = bib && bib.docidentifier.first&.content
|
|
509
356
|
|
|
510
|
-
# when ref isn't equal to bib's id then return a redirection to bib's id
|
|
511
357
|
quoted = Regexp.quote("(#{bib_id})")
|
|
512
358
|
if args[:db] && args[:id] && bib_id &&
|
|
513
359
|
args[:id] !~ /#{quoted}/
|
|
@@ -518,21 +364,6 @@ module Relaton
|
|
|
518
364
|
end
|
|
519
365
|
end
|
|
520
366
|
|
|
521
|
-
#
|
|
522
|
-
# @param code [String]
|
|
523
|
-
# @param year [String]
|
|
524
|
-
#
|
|
525
|
-
# @param opts [Hash]
|
|
526
|
-
# @option opts [Boolean] :all_parts If all-parts reference is required
|
|
527
|
-
# @option opts [Boolean] :keep_year If undated reference should return
|
|
528
|
-
# actual reference with year
|
|
529
|
-
#
|
|
530
|
-
# @param processor [Relaton::Processor]
|
|
531
|
-
# @param retries [Integer] remain Number of network retries
|
|
532
|
-
#
|
|
533
|
-
# @raise [RelatonBib::RequestError]
|
|
534
|
-
# @return [RelatonBib::BibliographicItem]
|
|
535
|
-
#
|
|
536
367
|
def net_retry(code, year, opts, processor, retries)
|
|
537
368
|
fetch_doc code, year, opts, processor
|
|
538
369
|
rescue Relaton::RequestError => e
|
|
@@ -541,15 +372,6 @@ module Relaton
|
|
|
541
372
|
net_retry(code, year, opts, processor, retries - 1)
|
|
542
373
|
end
|
|
543
374
|
|
|
544
|
-
# @param bib [RelatonBib::BibliographicItem,
|
|
545
|
-
# RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
|
|
546
|
-
# RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
|
|
547
|
-
# RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
|
|
548
|
-
# RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
|
|
549
|
-
# RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
|
|
550
|
-
# RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
|
|
551
|
-
# RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
|
|
552
|
-
# @return [String] XML or "not_found mm-dd-yyyy"
|
|
553
375
|
def bib_entry(bib)
|
|
554
376
|
if bib.respond_to?(:to_xml)
|
|
555
377
|
bib.to_xml(bibdata: true)
|
|
@@ -558,12 +380,6 @@ module Relaton
|
|
|
558
380
|
end
|
|
559
381
|
end
|
|
560
382
|
|
|
561
|
-
# Check if an XML entry's published date falls within the requested range.
|
|
562
|
-
# Range semantics: [after, before) — inclusive start, exclusive end.
|
|
563
|
-
#
|
|
564
|
-
# @param entry [String] XML string
|
|
565
|
-
# @param opts [Hash]
|
|
566
|
-
# @return [Boolean]
|
|
567
383
|
def pub_date_in_range?(entry, opts) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
|
568
384
|
doc = Nokogiri::XML(entry)
|
|
569
385
|
date_str = doc.at("//date[@type='published']/on")&.text
|
|
@@ -581,9 +397,6 @@ module Relaton
|
|
|
581
397
|
true
|
|
582
398
|
end
|
|
583
399
|
|
|
584
|
-
# @param str [String] date string in "YYYY", "YYYY-MM",
|
|
585
|
-
# or "YYYY-MM-DD" format
|
|
586
|
-
# @return [Date, nil]
|
|
587
400
|
def parse_pub_date(str)
|
|
588
401
|
case str
|
|
589
402
|
when /^\d{4}-\d{1,2}-\d{1,2}/ then Date.parse(str)
|
|
@@ -594,12 +407,10 @@ module Relaton
|
|
|
594
407
|
nil
|
|
595
408
|
end
|
|
596
409
|
|
|
597
|
-
# @param dir [String, nil] DB directory
|
|
598
|
-
# @return [Relaton::DbCache, NilClass]
|
|
599
410
|
def open_cache_biblio(dir) # rubocop:disable Metrics/MethodLength
|
|
600
411
|
return nil if dir.nil?
|
|
601
412
|
|
|
602
|
-
db =
|
|
413
|
+
db = Cache.new dir
|
|
603
414
|
|
|
604
415
|
Dir["#{dir}/*/"].each do |fdir|
|
|
605
416
|
next if db.check_version?(fdir)
|
|
@@ -610,9 +421,6 @@ module Relaton
|
|
|
610
421
|
db
|
|
611
422
|
end
|
|
612
423
|
|
|
613
|
-
# @param qwp [Hash]
|
|
614
|
-
# @option qwp [Queue] :queue The queue of references to fetch
|
|
615
|
-
# @option qwp [Relaton::WorkersPool] :workers_pool The pool of workers
|
|
616
424
|
def process_queue(qwp)
|
|
617
425
|
while args = qwp[:queue].pop; qwp[:workers_pool] << args end
|
|
618
426
|
end
|
|
@@ -632,7 +440,7 @@ module Relaton
|
|
|
632
440
|
globalname = global_bibliocache_name if opts[:global_cache]
|
|
633
441
|
localname = local_bibliocache_name(opts[:local_cache])
|
|
634
442
|
flush_caches globalname, localname if opts[:flush_caches]
|
|
635
|
-
|
|
443
|
+
new(globalname, localname)
|
|
636
444
|
end
|
|
637
445
|
|
|
638
446
|
def flush_caches(gcache, lcache)
|
|
@@ -653,3 +461,10 @@ module Relaton
|
|
|
653
461
|
end
|
|
654
462
|
end
|
|
655
463
|
end
|
|
464
|
+
|
|
465
|
+
require_relative "db/version"
|
|
466
|
+
require_relative "db/util"
|
|
467
|
+
require_relative "db/config"
|
|
468
|
+
require_relative "db/workers_pool"
|
|
469
|
+
require_relative "db/cache"
|
|
470
|
+
require_relative "db/registry"
|
data/lib/relaton/version.rb
CHANGED
data/lib/relaton.rb
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
require "relaton/
|
|
2
|
-
require "relaton/
|
|
3
|
-
require "relaton/config"
|
|
4
|
-
require "yaml"
|
|
5
|
-
|
|
6
|
-
require_relative "relaton/workers_pool"
|
|
7
|
-
require_relative "relaton/db"
|
|
8
|
-
require_relative "relaton/db_cache"
|
|
9
|
-
require_relative "relaton/version"
|
|
10
|
-
require_relative "relaton/registry"
|
|
1
|
+
require "relaton/version"
|
|
2
|
+
require "relaton/db"
|
data/relaton.gemspec
CHANGED
|
@@ -10,14 +10,20 @@ Gem::Specification.new do |spec|
|
|
|
10
10
|
spec.authors = ["Ribose Inc."]
|
|
11
11
|
spec.email = ["open.source@ribose.com"]
|
|
12
12
|
|
|
13
|
-
spec.summary = "
|
|
14
|
-
"
|
|
13
|
+
spec.summary = "Relaton: bibliographic references to technical " \
|
|
14
|
+
"standards — database, registry, cache, and all " \
|
|
15
|
+
"flavor plugins bundled in one gem."
|
|
15
16
|
spec.description = <<~DESCRIPTION
|
|
16
|
-
|
|
17
|
+
Relaton is the central database, registry, and cache for bibliographic
|
|
17
18
|
references to technical standards in the Relaton/XML bibliographic
|
|
18
|
-
model.
|
|
19
|
+
model. It provides the Relaton::Db API, a plugin registry that lazily
|
|
20
|
+
loads flavor gems (relaton-iso, relaton-ietf, etc.) on demand, and a
|
|
21
|
+
file-based cache for fetched references.
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
Installing this gem also pulls in every Relaton flavor plugin so you
|
|
24
|
+
can fetch references from any supported standards body out of the
|
|
25
|
+
box. The CLI (relaton-cli) is intentionally NOT a dependency —
|
|
26
|
+
install it separately when you need command-line access.
|
|
21
27
|
DESCRIPTION
|
|
22
28
|
|
|
23
29
|
spec.homepage = "https://github.com/relaton/relaton"
|
|
@@ -26,36 +32,41 @@ Gem::Specification.new do |spec|
|
|
|
26
32
|
spec.bindir = "bin"
|
|
27
33
|
spec.require_paths = ["lib"]
|
|
28
34
|
spec.files = `git ls-files`.split("\n")
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
spec.add_dependency "relaton-
|
|
33
|
-
spec.add_dependency "relaton-
|
|
34
|
-
spec.add_dependency "relaton-
|
|
35
|
-
|
|
36
|
-
spec.add_dependency "relaton-
|
|
37
|
-
spec.add_dependency "relaton-
|
|
38
|
-
spec.add_dependency "relaton-
|
|
39
|
-
spec.add_dependency "relaton-
|
|
40
|
-
spec.add_dependency "relaton-
|
|
41
|
-
spec.add_dependency "relaton-
|
|
42
|
-
spec.add_dependency "relaton-
|
|
43
|
-
spec.add_dependency "relaton-
|
|
44
|
-
spec.add_dependency "relaton-
|
|
45
|
-
spec.add_dependency "relaton-
|
|
46
|
-
spec.add_dependency "relaton-
|
|
47
|
-
spec.add_dependency "relaton-
|
|
48
|
-
spec.add_dependency "relaton-
|
|
49
|
-
spec.add_dependency "relaton-
|
|
50
|
-
spec.add_dependency "relaton-
|
|
51
|
-
spec.add_dependency "relaton-
|
|
52
|
-
spec.add_dependency "relaton-
|
|
53
|
-
spec.add_dependency "relaton-
|
|
54
|
-
spec.add_dependency "relaton-
|
|
55
|
-
spec.add_dependency "relaton-
|
|
56
|
-
spec.add_dependency "relaton-
|
|
57
|
-
spec.add_dependency "relaton-
|
|
58
|
-
spec.add_dependency "relaton-
|
|
59
|
-
spec.add_dependency "relaton-
|
|
35
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.3.0")
|
|
36
|
+
|
|
37
|
+
spec.add_dependency "relaton-bib", "~> 2.2.0.pre.alpha.1"
|
|
38
|
+
spec.add_dependency "relaton-core", "~> 2.2.0.pre.alpha.1"
|
|
39
|
+
spec.add_dependency "relaton-index", "~> 2.2.0.pre.alpha.1"
|
|
40
|
+
spec.add_dependency "relaton-logger", "~> 2.2.0.pre.alpha.1"
|
|
41
|
+
|
|
42
|
+
spec.add_dependency "relaton-3gpp", "~> 2.2.0.pre.alpha.1"
|
|
43
|
+
spec.add_dependency "relaton-bipm", "~> 2.2.0.pre.alpha.1"
|
|
44
|
+
spec.add_dependency "relaton-bsi", "~> 2.2.0.pre.alpha.1"
|
|
45
|
+
spec.add_dependency "relaton-calconnect", "~> 2.2.0.pre.alpha.1"
|
|
46
|
+
spec.add_dependency "relaton-ccsds", "~> 2.2.0.pre.alpha.1"
|
|
47
|
+
spec.add_dependency "relaton-cen", "~> 2.2.0.pre.alpha.1"
|
|
48
|
+
spec.add_dependency "relaton-cie", "~> 2.2.0.pre.alpha.1"
|
|
49
|
+
spec.add_dependency "relaton-doi", "~> 2.2.0.pre.alpha.1"
|
|
50
|
+
spec.add_dependency "relaton-ecma", "~> 2.2.0.pre.alpha.1"
|
|
51
|
+
spec.add_dependency "relaton-etsi", "~> 2.2.0.pre.alpha.1"
|
|
52
|
+
spec.add_dependency "relaton-gb", "~> 2.2.0.pre.alpha.1"
|
|
53
|
+
spec.add_dependency "relaton-iana", "~> 2.2.0.pre.alpha.1"
|
|
54
|
+
spec.add_dependency "relaton-iec", "~> 2.2.0.pre.alpha.1"
|
|
55
|
+
spec.add_dependency "relaton-ieee", "~> 2.2.0.pre.alpha.1"
|
|
56
|
+
spec.add_dependency "relaton-ietf", "~> 2.2.0.pre.alpha.1"
|
|
57
|
+
spec.add_dependency "relaton-iho", "~> 2.2.0.pre.alpha.1"
|
|
58
|
+
spec.add_dependency "relaton-isbn", "~> 2.2.0.pre.alpha.1"
|
|
59
|
+
spec.add_dependency "relaton-iso", "~> 2.2.0.pre.alpha.1"
|
|
60
|
+
spec.add_dependency "relaton-itu", "~> 2.2.0.pre.alpha.1"
|
|
61
|
+
spec.add_dependency "relaton-jis", "~> 2.2.0.pre.alpha.1"
|
|
62
|
+
spec.add_dependency "relaton-nist", "~> 2.2.0.pre.alpha.1"
|
|
63
|
+
spec.add_dependency "relaton-oasis", "~> 2.2.0.pre.alpha.1"
|
|
64
|
+
spec.add_dependency "relaton-ogc", "~> 2.2.0.pre.alpha.1"
|
|
65
|
+
spec.add_dependency "relaton-omg", "~> 2.2.0.pre.alpha.1"
|
|
66
|
+
spec.add_dependency "relaton-plateau", "~> 2.2.0.pre.alpha.1"
|
|
67
|
+
spec.add_dependency "relaton-un", "~> 2.2.0.pre.alpha.1"
|
|
68
|
+
spec.add_dependency "relaton-w3c", "~> 2.2.0.pre.alpha.1"
|
|
69
|
+
spec.add_dependency "relaton-xsf", "~> 2.2.0.pre.alpha.1"
|
|
70
|
+
|
|
60
71
|
spec.metadata["rubygems_mfa_required"] = "true"
|
|
61
72
|
end
|
data/spec/relaton/config_spec.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require "fileutils"
|
|
2
2
|
require "timeout"
|
|
3
3
|
|
|
4
|
-
RSpec.describe Relaton::
|
|
4
|
+
RSpec.describe Relaton::Db::Cache do
|
|
5
5
|
it "creates default caches" do
|
|
6
6
|
cache_path = File.expand_path("~/.relaton/cache")
|
|
7
7
|
FileUtils.mv cache_path, "relaton1/cache", force: true
|
|
@@ -21,8 +21,8 @@ RSpec.describe Relaton::DbCache do
|
|
|
21
21
|
file = File.open(file_name, File::RDWR | File::CREAT, encoding: "UTF-8") # rubocop:disable Style/FileOpen
|
|
22
22
|
file.flock File::LOCK_EX
|
|
23
23
|
command = <<~RBY
|
|
24
|
-
require "relaton"
|
|
25
|
-
cache = Relaton::
|
|
24
|
+
require "relaton/db"
|
|
25
|
+
cache = Relaton::Db::Cache.new "testcache"
|
|
26
26
|
cache["ISO(ISO 123)"] = "test 1"
|
|
27
27
|
RBY
|
|
28
28
|
pid = spawn RbConfig.ruby, "-e #{command}"
|
|
@@ -38,7 +38,7 @@ RSpec.describe Relaton::DbCache do
|
|
|
38
38
|
|
|
39
39
|
context "delete file from cache" do
|
|
40
40
|
it "delete redirect file and its original" do
|
|
41
|
-
cache = Relaton::
|
|
41
|
+
cache = Relaton::Db::Cache.new "testcache"
|
|
42
42
|
cache["ISO(ISO 123)"] = "test 1"
|
|
43
43
|
cache["ISO(123)"] = "redirection ISO(ISO 123)"
|
|
44
44
|
expect(File.exist?("testcache/iso/iso_123.xml")).to be true
|
data/spec/relaton/db_spec.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
RSpec.describe Relaton::Db do
|
|
2
2
|
before(:each) do |example|
|
|
3
|
-
# Relaton.instance_variable_set :@configuration, nil
|
|
3
|
+
# Relaton::Db.instance_variable_set :@configuration, nil
|
|
4
4
|
FileUtils.rm_rf %w[testcache testcache2]
|
|
5
5
|
|
|
6
6
|
if example.metadata[:vcr]
|
|
@@ -39,7 +39,7 @@ RSpec.describe Relaton::Db do
|
|
|
39
39
|
:relaton_iso, db: db, id: "ISO(ISO 123)"
|
|
40
40
|
expect(entry).to be_nil
|
|
41
41
|
end.to output(
|
|
42
|
-
"[relaton] INFO: (ISO 123) not found in cache, " \
|
|
42
|
+
"[relaton-db] INFO: (ISO 123) not found in cache, " \
|
|
43
43
|
"if you wish to ignore cache please use " \
|
|
44
44
|
"`no-cache` option.\n",
|
|
45
45
|
).to_stderr_from_any_process
|
|
@@ -350,7 +350,7 @@ RSpec.describe Relaton::Db do
|
|
|
350
350
|
expect do
|
|
351
351
|
expect(db.mv("new_cache_dir")).to be_nil
|
|
352
352
|
end.to output(
|
|
353
|
-
/\[relaton\] INFO: target directory exists/,
|
|
353
|
+
/\[relaton-db\] INFO: target directory exists/,
|
|
354
354
|
).to_stderr_from_any_process
|
|
355
355
|
end
|
|
356
356
|
|
|
@@ -453,7 +453,13 @@ RSpec.describe Relaton::Db do
|
|
|
453
453
|
expect(bib).to be_instance_of Relaton::Iso::ItemData
|
|
454
454
|
end
|
|
455
455
|
|
|
456
|
-
it "when no local db"
|
|
456
|
+
it "when no local db" do
|
|
457
|
+
docid = Relaton::Bib::Docidentifier.new(content: "ISO 19115-1",
|
|
458
|
+
type: "ISO")
|
|
459
|
+
item = Relaton::Iso::ItemData.new(docidentifier: [docid],
|
|
460
|
+
fetched: Date.today.to_s)
|
|
461
|
+
expect(Relaton::Iso::Bibliography).to receive(:get)
|
|
462
|
+
.with("ISO 19115-1", nil, {}).and_return item
|
|
457
463
|
db = Relaton::Db.new "testcache", nil
|
|
458
464
|
bib = db.fetch("ISO 19115-1", nil, {})
|
|
459
465
|
expect(bib).to be_instance_of Relaton::Iso::ItemData
|
|
@@ -481,7 +487,12 @@ RSpec.describe Relaton::Db do
|
|
|
481
487
|
end
|
|
482
488
|
end
|
|
483
489
|
|
|
484
|
-
it "fetch std"
|
|
490
|
+
it "fetch std" do
|
|
491
|
+
docid = Relaton::Bib::Docidentifier.new(content: "ISO 19115-1", type: "ISO")
|
|
492
|
+
item = Relaton::Iso::ItemData.new(docidentifier: [docid],
|
|
493
|
+
fetched: Date.today.to_s)
|
|
494
|
+
expect(Relaton::Iso::Bibliography).to receive(:get)
|
|
495
|
+
.with("ISO 19115-1", nil, {}).and_return item
|
|
485
496
|
db = Relaton::Db.new "testcache", nil
|
|
486
497
|
bib = db.fetch_std("ISO 19115-1", nil, :relaton_iso, {})
|
|
487
498
|
expect(bib).to be_instance_of Relaton::Iso::ItemData
|
|
@@ -537,7 +548,7 @@ RSpec.describe Relaton::Db do
|
|
|
537
548
|
expect(subject).to receive(:fetch).and_raise Errno::EACCES
|
|
538
549
|
log_io = Relaton.logger_pool[:default].instance_variable_get(:@logdev)
|
|
539
550
|
expect(log_io).to receive(:write).with(
|
|
540
|
-
"[relaton] ERROR: `ISO REF` -- Permission denied\n",
|
|
551
|
+
"[relaton-db] ERROR: `ISO REF` -- Permission denied\n",
|
|
541
552
|
)
|
|
542
553
|
subject.fetch_async("ISO REF") { |r| queue << r }
|
|
543
554
|
result = Timeout.timeout(5) { queue.pop }
|
|
@@ -547,7 +558,7 @@ RSpec.describe Relaton::Db do
|
|
|
547
558
|
it "use threads number from RELATON_FETCH_PARALLEL" do
|
|
548
559
|
expect(ENV).to receive(:[]).with("RELATON_FETCH_PARALLEL").and_return(1)
|
|
549
560
|
allow(ENV).to receive(:[]).and_call_original
|
|
550
|
-
expect(Relaton::WorkersPool).to receive(:new).with(1).and_call_original
|
|
561
|
+
expect(Relaton::Db::WorkersPool).to receive(:new).with(1).and_call_original
|
|
551
562
|
expect(subject).to receive(:fetch).with("ITU-T G.993.5", nil, {})
|
|
552
563
|
subject.fetch_async("ITU-T G.993.5") { |r| queue << r }
|
|
553
564
|
Timeout.timeout(50) { queue.pop }
|