relaton 3.0.0.pre.alpha.4 → 3.0.0.pre.alpha.5
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/lib/relaton/adobe/processor.rb +9 -0
- data/lib/relaton/bib/converter/csl.rb +110 -0
- data/lib/relaton/bib/converter/ris.rb +104 -0
- data/lib/relaton/bib/converter/titles.rb +24 -0
- data/lib/relaton/bib/item_data.rb +9 -0
- data/lib/relaton/bib/model/item.rb +6 -6
- data/lib/relaton/bib/sanitizer.rb +71 -30
- data/lib/relaton/bib.rb +10 -0
- data/lib/relaton/bipm/processor.rb +1 -0
- data/lib/relaton/bipm/rawdata_bipm_metrologia/affiliations.rb +6 -6
- data/lib/relaton/bipm/si_brochure_parser.rb +2 -2
- data/lib/relaton/bsi/processor.rb +5 -0
- data/lib/relaton/ccsds/bibliography.rb +1 -0
- data/lib/relaton/ccsds/processor.rb +12 -0
- data/lib/relaton/cen/hit_collection.rb +1 -1
- data/lib/relaton/cen/processor.rb +5 -0
- data/lib/relaton/cen/scraper.rb +9 -9
- data/lib/relaton/cie/data_fetcher.rb +18 -18
- data/lib/relaton/cie/processor.rb +1 -0
- data/lib/relaton/cie.rb +1 -1
- data/lib/relaton/cloud.rb +127 -0
- data/lib/relaton/core/hit_collection.rb +6 -10
- data/lib/relaton/core/processor.rb +68 -0
- data/lib/relaton/db/cache.rb +444 -148
- data/lib/relaton/db/cache_entry.rb +33 -0
- data/lib/relaton/db/registry.rb +52 -0
- data/lib/relaton/db.rb +131 -72
- data/lib/relaton/doi/crossref.rb +23 -6
- data/lib/relaton/doi/processor.rb +1 -0
- data/lib/relaton/easc/processor.rb +1 -0
- data/lib/relaton/ecma/data_fetcher.rb +1 -1
- data/lib/relaton/ecma/data_parser.rb +1 -1
- data/lib/relaton/ecma/edition_parser.rb +2 -2
- data/lib/relaton/ecma/memento_parser.rb +4 -4
- data/lib/relaton/ecma/standard_parser.rb +6 -6
- data/lib/relaton/etsi/processor.rb +1 -0
- data/lib/relaton/gb/gb_scraper.rb +5 -5
- data/lib/relaton/gb/scraper.rb +16 -16
- data/lib/relaton/gb/sec_scraper.rb +8 -8
- data/lib/relaton/gb/t_scraper.rb +5 -5
- data/lib/relaton/gost/processor.rb +1 -0
- data/lib/relaton/iala/processor.rb +1 -0
- data/lib/relaton/iana/data_fetcher.rb +3 -3
- data/lib/relaton/iana/parser.rb +8 -4
- data/lib/relaton/iana/processor.rb +9 -0
- data/lib/relaton/iec/data_parser.rb +24 -9
- data/lib/relaton/iec/processor.rb +6 -0
- data/lib/relaton/iec.rb +1 -1
- data/lib/relaton/ieee/data_fetcher.rb +1 -1
- data/lib/relaton/ieee/processor.rb +8 -0
- data/lib/relaton/ietf/data_fetcher.rb +1 -1
- data/lib/relaton/ietf/processor.rb +1 -0
- data/lib/relaton/ietf/rfc/entry.rb +15 -19
- data/lib/relaton/iho/processor.rb +1 -0
- data/lib/relaton/index/file_io.rb +2 -2
- data/lib/relaton/index/pool.rb +4 -3
- data/lib/relaton/index/shard_source.rb +1 -1
- data/lib/relaton/index/type.rb +2 -5
- data/lib/relaton/isbn/open_library.rb +11 -7
- data/lib/relaton/isbn/processor.rb +10 -0
- data/lib/relaton/iso/data_parser.rb +2 -2
- data/lib/relaton/iso/processor.rb +5 -0
- data/lib/relaton/iso/scraper.rb +20 -20
- data/lib/relaton/itu/bibliography.rb +99 -13
- data/lib/relaton/itu/data_crawler_r.rb +2 -2
- data/lib/relaton/itu/hit_collection.rb +64 -52
- data/lib/relaton/itu/processor.rb +1 -0
- data/lib/relaton/itu/scraper.rb +13 -3
- data/lib/relaton/itu.rb +0 -2
- data/lib/relaton/jis/data_fetcher.rb +4 -4
- data/lib/relaton/jis/processor.rb +1 -0
- data/lib/relaton/jis/scraper.rb +8 -8
- data/lib/relaton/oasis/browser_agent.rb +2 -2
- data/lib/relaton/oasis/data_parser.rb +5 -5
- data/lib/relaton/oasis/data_parser_utils.rb +2 -2
- data/lib/relaton/oasis/data_part_parser.rb +7 -7
- data/lib/relaton/ogc/processor.rb +7 -0
- data/lib/relaton/oiml/processor.rb +1 -0
- data/lib/relaton/omg/scraper.rb +11 -11
- data/lib/relaton/omg.rb +1 -1
- data/lib/relaton/plateau/processor.rb +1 -0
- data/lib/relaton/un/bibliography.rb +21 -10
- data/lib/relaton/un/processor.rb +1 -0
- data/lib/relaton/version.rb +1 -1
- data/lib/relaton/w3c/processor.rb +1 -0
- data/lib/relaton.rb +13 -0
- metadata +48 -16
- data/lib/relaton/itu/pubid.rb +0 -199
data/lib/relaton/itu/pubid.rb
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
module Relaton
|
|
2
|
-
module Itu
|
|
3
|
-
class Pubid
|
|
4
|
-
class Parser < Parslet::Parser
|
|
5
|
-
rule(:dash) { str("-") }
|
|
6
|
-
rule(:dot) { str(".") }
|
|
7
|
-
rule(:dot?) { dot.maybe }
|
|
8
|
-
rule(:separator) { match['\s-'] }
|
|
9
|
-
rule(:space) { match("\s") }
|
|
10
|
-
rule(:num) { match["0-9"] }
|
|
11
|
-
|
|
12
|
-
rule(:prefix) { str("ITU").as(:prefix) }
|
|
13
|
-
rule(:sector) { separator >> match("[A-Z]").as(:sector) }
|
|
14
|
-
# "Report" is not decoration: ITU-R Recommendations and Reports number
|
|
15
|
-
# independently, so "ITU-R BT.2020-1" alone names two different documents
|
|
16
|
-
# (Rec. BT.2020-1, 06/2014 vs Report BT.2020-1, 2000). ITU writes the
|
|
17
|
-
# discriminator first ("Report ITU-R BT.2020-1"), which is the form
|
|
18
|
-
# `Pubid::Itu` parses as `pubid:itu:report`; the sector-first spelling is
|
|
19
|
-
# accepted too because bibliographies use both.
|
|
20
|
-
rule(:report) { (str("Report") | str("REP")).as(:type) >> space }
|
|
21
|
-
rule(:report?) { report.maybe }
|
|
22
|
-
rule(:type) { separator >> (str("REC") | str("Report") | str("REP")).as(:type) }
|
|
23
|
-
rule(:type?) { type.maybe }
|
|
24
|
-
rule(:code) { separator >> (match["A-Z0-9"].repeat(1) >> match["[:alnum:]/.-"].repeat).as(:code) }
|
|
25
|
-
rule(:year) { (match["12"] >> num.repeat(3, 3)).as(:year) }
|
|
26
|
-
|
|
27
|
-
rule(:month1) { num.repeat(2, 2).as(:month) }
|
|
28
|
-
rule(:date1) { str(" (") >> (month1 >> str("/")).maybe >> year >> str(")") }
|
|
29
|
-
rule(:month2) { match["IVX"].repeat(1, 3).as(:month) }
|
|
30
|
-
rule(:date2) { str(" - ") >> num.repeat(2, 2).as(:day) >> dot >> month2 >> dot >> year }
|
|
31
|
-
rule(:date) { date1 | date2 }
|
|
32
|
-
rule(:date?) { date.maybe }
|
|
33
|
-
|
|
34
|
-
rule(:amd_month) { num.repeat(2, 2) }
|
|
35
|
-
rule(:amd_year) { num.repeat(4, 4) }
|
|
36
|
-
rule(:amd_date) { str(" (") >> (amd_month >> str("/") >> amd_year).as(:amd_date) >> str(")") }
|
|
37
|
-
rule(:amd_date?) { amd_date.maybe }
|
|
38
|
-
rule(:amd) { space >> (str("Amd") | str("Amendment")) >> dot? >> space >> num.repeat(1, 2).as(:amd) >> amd_date? }
|
|
39
|
-
rule(:amd?) { amd.maybe }
|
|
40
|
-
|
|
41
|
-
rule(:sup) { space >> str("Suppl") >> dot? >> space >> num.repeat(1, 2).as(:suppl) }
|
|
42
|
-
rule(:sup?) { sup.maybe }
|
|
43
|
-
|
|
44
|
-
rule(:annex) { space >> str("Annex") >> space >> match["[:alnum:]"].repeat(1, 2).as(:annex) }
|
|
45
|
-
rule(:annex?) { annex.maybe }
|
|
46
|
-
|
|
47
|
-
rule(:ver) { space >> str("(V") >> num.repeat(1, 2).as(:version) >> str(")") }
|
|
48
|
-
rule(:ver?) { ver.maybe }
|
|
49
|
-
|
|
50
|
-
rule(:itu_pubid_sector) { prefix >> sector >> type? >> code >> sup? >> annex? >> ver? >> date? >> amd? >> any.repeat }
|
|
51
|
-
rule(:itu_pubid_no_sector) { prefix >> type? >> code >> sup? >> annex? >> ver? >> date? >> amd? >> any.repeat }
|
|
52
|
-
rule(:itu_pubid) { report? >> (itu_pubid_sector | itu_pubid_no_sector) }
|
|
53
|
-
root(:itu_pubid)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
attr_accessor :prefix, :sector, :type, :code, :suppl, :annex, :version, :year, :month, :day, :amd, :amd_date
|
|
57
|
-
|
|
58
|
-
#
|
|
59
|
-
# Create a new ITU publication identifier.
|
|
60
|
-
#
|
|
61
|
-
# @param [String] prefix
|
|
62
|
-
# @param [String] code
|
|
63
|
-
#
|
|
64
|
-
def initialize(prefix:, code:, **args)
|
|
65
|
-
@prefix = prefix
|
|
66
|
-
@sector = args[:sector]
|
|
67
|
-
@type = args[:type]
|
|
68
|
-
@day = args[:day]
|
|
69
|
-
@code, year, month = date_from_code code
|
|
70
|
-
@suppl = args[:suppl]
|
|
71
|
-
@annex = args[:annex]
|
|
72
|
-
@version = args[:version]
|
|
73
|
-
@year = args[:year] || year
|
|
74
|
-
@month = roman_to_2digit args[:month] || month
|
|
75
|
-
@amd = args[:amd]
|
|
76
|
-
@amd_date = args[:amd_date]
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def self.parse(id)
|
|
80
|
-
id_parts = Parser.new.parse(id).to_h.transform_values(&:to_s)
|
|
81
|
-
new(**id_parts)
|
|
82
|
-
rescue Parslet::ParseFailed => e
|
|
83
|
-
Util.error "`#{id}` is invalid ITU publication identifier\n" \
|
|
84
|
-
"#{e.parse_failure_cause.ascii_tree}"
|
|
85
|
-
# This grammar is local, so re-raise it as pubid's error: relaton-cli
|
|
86
|
-
# rescues `Pubid::Errors::Error`. `::` is needed, because inside this
|
|
87
|
-
# class a bare `Pubid` is `Relaton::Itu::Pubid`.
|
|
88
|
-
raise ::Pubid::Errors::ParseError.new(e.message, e.parse_failure_cause,
|
|
89
|
-
input: id, flavor: "itu")
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def to_h(with_type: true) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
93
|
-
hash = { prefix: prefix, code: code }
|
|
94
|
-
hash[:sector] = sector if sector
|
|
95
|
-
hash[:type] = type if type && with_type
|
|
96
|
-
hash[:suppl] = suppl if suppl
|
|
97
|
-
hash[:annex] = annex if annex
|
|
98
|
-
hash[:version] = version if version
|
|
99
|
-
hash[:year] = year if year
|
|
100
|
-
hash[:month] = month if month
|
|
101
|
-
hash[:day] = day if day
|
|
102
|
-
hash[:amd] = amd if amd
|
|
103
|
-
hash[:amd_date] = amd_date if amd_date
|
|
104
|
-
hash
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def to_ref
|
|
108
|
-
to_s ref: true
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
# @return [Boolean] whether this reference names an ITU-R Report rather
|
|
112
|
-
# than a Recommendation — the one type that must survive into #to_ref,
|
|
113
|
-
# because it is what tells the two apart (see the `report` parser rule).
|
|
114
|
-
def report?
|
|
115
|
-
%w[Report REP].include? type
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def to_s(ref: false) # rubocop:disable Metrics/AbcSize
|
|
119
|
-
# "Report" leads, the way ITU cites it and the way Pubid::Itu parses it;
|
|
120
|
-
# `REC` stays dropped from a reference because it is redundant there.
|
|
121
|
-
s = report? ? +"Report " : +""
|
|
122
|
-
s << prefix
|
|
123
|
-
s << "-#{sector}" if sector
|
|
124
|
-
s << " #{type}" if type && !ref && !report?
|
|
125
|
-
s << " #{code}"
|
|
126
|
-
s << " Suppl. #{suppl}" if suppl
|
|
127
|
-
s << " Annex #{annex}" if annex
|
|
128
|
-
s << " (V#{version})" if version
|
|
129
|
-
s << date_to_s
|
|
130
|
-
s << " Amd #{amd}" if amd
|
|
131
|
-
s << " (#{amd_date})" if amd_date
|
|
132
|
-
s
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def ===(other, ignore_args = [])
|
|
136
|
-
hash = to_h with_type: false
|
|
137
|
-
other_hash = other.to_h with_type: false
|
|
138
|
-
hash.delete(:version) if ignore_args.include?(:version)
|
|
139
|
-
other_hash.delete(:version) unless hash[:version]
|
|
140
|
-
hash.delete(:day)
|
|
141
|
-
other_hash.delete(:day)
|
|
142
|
-
hash.delete(:month)
|
|
143
|
-
other_hash.delete(:month)
|
|
144
|
-
hash.delete(:year) if ignore_args.include?(:year)
|
|
145
|
-
other_hash.delete(:year) unless hash[:year]
|
|
146
|
-
hash.delete(:amd_date) if ignore_args.include?(:amd_date)
|
|
147
|
-
other_hash.delete(:amd_date) unless hash[:amd_date]
|
|
148
|
-
hash == other_hash
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
private
|
|
152
|
-
|
|
153
|
-
def date_from_code(code)
|
|
154
|
-
/(?<cod>.+?)-(?<date>\d{6})(?:-I|$)/ =~ code
|
|
155
|
-
return [code, nil, nil] unless cod && date
|
|
156
|
-
|
|
157
|
-
[cod, date[0..3], date[4..5]]
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
def roman_to_2digit(num) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
161
|
-
return unless num
|
|
162
|
-
|
|
163
|
-
roman_nums = { "I" => 1, "V" => 5, "X" => 10 }
|
|
164
|
-
last = roman_nums[num[-1]]
|
|
165
|
-
return num unless last
|
|
166
|
-
|
|
167
|
-
return roman_nums[num].to_s.rjust(2, "0") if num.size == 1
|
|
168
|
-
|
|
169
|
-
num.chars.each_cons(2).reduce(last) do |acc, (a, b)|
|
|
170
|
-
if roman_nums[a] < roman_nums[b]
|
|
171
|
-
acc - roman_nums[a]
|
|
172
|
-
else
|
|
173
|
-
acc + roman_nums[a]
|
|
174
|
-
end
|
|
175
|
-
end.to_s.rjust(2, "0")
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
def month_to_roman
|
|
179
|
-
int = month.to_i
|
|
180
|
-
return month unless int.between? 1, 12
|
|
181
|
-
|
|
182
|
-
roman_tens = ["", "X"]
|
|
183
|
-
roman_units = ["", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"]
|
|
184
|
-
|
|
185
|
-
tens = int / 10
|
|
186
|
-
units = int % 10
|
|
187
|
-
|
|
188
|
-
roman_tens[tens] + roman_units[units]
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
def date_to_s
|
|
192
|
-
if month && year then " (#{month}/#{year})"
|
|
193
|
-
elsif year then " (#{year})"
|
|
194
|
-
else ""
|
|
195
|
-
end
|
|
196
|
-
end
|
|
197
|
-
end
|
|
198
|
-
end
|
|
199
|
-
end
|