relaton-ietf 1.9.6 → 1.9.7

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: 05d7da0539d628af6e8dbe016497f640fe1a238c164e280e6d9bae3152de3bb5
4
- data.tar.gz: 4d7da3f63909c912630f6b2d2ac7c2224219662a6cd8ce840f4156bb59072e18
3
+ metadata.gz: 38c6632f8b954cf88746dac6e0560294cf8c546063e774f1b717dec2a4f0a9d8
4
+ data.tar.gz: dcf250a7d8c88a06ba9be27ba3d69bcbe3f5e50b3d41ee1616834011d6b2995c
5
5
  SHA512:
6
- metadata.gz: 688aefaa75847bfbb3dd9dc41dd91367b0e5749d78f2ef0f93296270d25165b69708a5a20367231df67525d536755f5eeef9c9f1f242a3e7b895381fac41f427
7
- data.tar.gz: adc30f681ff6be584b9025aaad6d14ffa728a1bb82b10caac5d88a14954017dfc9a6328fd34c9f13176c3e9a2a3496b676d18d8405070bf00b92c5b15536f380
6
+ metadata.gz: 55bb6cdf657772970caa7447097da8e38686aa7c0cc16a40e8f931963ecd26202ed1aed62a8c77269d8d0f49cf4e890002b8d4a2831235f566023dc3b13a06eb
7
+ data.tar.gz: cfb86b6c8f4a52a19ff52ecb93d0ca9211159f8499a782f2aa3904ae089d0f1f6ae7c9f96e00f532c7502cc4a718d0ebb9b6784e2d9f3d9ebc2b180489fc0b0a
data/README.adoc CHANGED
@@ -149,16 +149,6 @@ Arguments:
149
149
  - `output` - folder to save documents (default './data').
150
150
  - `format` - format in which the documents are saved. Possimle formats are: `yaml`, `xml`, `bibxml` (default `yaml`).
151
151
 
152
- For `ietf-rfcsubseries` dataset only special XML format is supported:
153
-
154
- [sourse.xml]
155
- ----
156
- <referencegroup anchor="BCP14" target="https://www.rfc-editor.org/info/bcp14">
157
- <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.2119.xml" />
158
- <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.8174.xml" />
159
- </referencegroup>
160
- ----
161
-
162
152
  [source,ruby]
163
153
  ----
164
154
  RelatonIetf::DataFetcher.fetch "ietf-internet-drafts"
@@ -7,7 +7,7 @@ module Relaton
7
7
  def from_rfcxml(xml)
8
8
  doc = Nokogiri::XML xml
9
9
  reference = doc.at "/rfc"
10
- RelatonIetf::Scrapper.fetch_rfc reference
10
+ RelatonIetf::BibXMLParser.fetch_rfc reference
11
11
  end
12
12
  end
13
13
  end
@@ -0,0 +1,31 @@
1
+ module RelatonIetf
2
+ module BibXMLParser
3
+ include RelatonBib::BibXMLParser
4
+ extend BibXMLParser
5
+
6
+ FLAVOR = "IETF".freeze
7
+
8
+ # @param attrs [Hash]
9
+ # @return [RelatonIetf::IetfBibliographicItem]
10
+ def bib_item(**attrs)
11
+ unless attrs.delete(:is_relation)
12
+ attrs[:fetched] = Date.today.to_s
13
+ attrs[:place] = ["Fremont, CA"]
14
+ end
15
+ RelatonIetf::IetfBibliographicItem.new(**attrs)
16
+ end
17
+
18
+ # @param [RelatonBib::WorkGroup]
19
+ # @return [RelatonIetf::Committee]
20
+ def committee(wgr)
21
+ Committee.new wgr
22
+ end
23
+
24
+ # @param reference [Nokogiri::XML::Element]
25
+ # @return [Array<Hash>]
26
+ def contributors(reference)
27
+ [{ entity: new_org("Internet Engineering Task Force", "IETF"), role: [type: "publisher"] }] + super
28
+ # persons(reference) + organizations(reference)
29
+ end
30
+ end
31
+ end
@@ -1,17 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "net/http"
4
- require "relaton_bib"
5
- require "relaton_ietf/ietf_bibliographic_item"
6
-
7
3
  module RelatonIetf
8
4
  # Scrapper module
9
5
  module Scrapper
10
- extend RelatonBib::BibXMLParser
11
6
  extend Scrapper
12
7
 
13
- FLAVOR = "IETF"
14
-
15
8
  GH_URL = "https://raw.githubusercontent.com/relaton/relaton-data-ietf/master/data/reference."
16
9
 
17
10
  # @param text [String]
@@ -24,76 +17,13 @@ module RelatonIetf
24
17
  ref.sub!(/(?<=^(?:RFC|BCP|FYI|STD)\s)(\d+)/, num.rjust(4, "0")) if num
25
18
  rfc_item ref, is_relation
26
19
  rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
27
- Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
28
- Net::ProtocolError, SocketError
20
+ Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
21
+ Net::ProtocolError, SocketError
29
22
  raise RelatonBib::RequestError, "No document found for #{ref} reference"
30
23
  end
31
24
 
32
- # @param reference [Nokogiri::XML::Element, nil]
33
- # @param is_relation [Boolean] don't add fetched date for relation
34
- # @param url [String, NilClass]
35
- # @param ver [String, NilClass] Internet Draft version
36
- # @return [RelatonBib::tfBibliographicItem]
37
- # def fetch_rfc(reference, is_relation: false, url: nil, ver: nil) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
38
- # return unless reference
39
-
40
- # hash = {
41
- # id: reference[:anchor],
42
- # type: "standard",
43
- # docid: docids(reference, ver),
44
- # status: status(reference),
45
- # language: [language(reference)],
46
- # script: ["Latn"],
47
- # link: link(reference, url, ver),
48
- # title: titles(reference),
49
- # formattedref: formattedref(reference),
50
- # abstract: abstracts(reference),
51
- # contributor: contributors(reference),
52
- # relation: relations(reference),
53
- # date: dates(reference),
54
- # series: series(reference),
55
- # keyword: reference.xpath("front/keyword").map(&:text),
56
- # doctype: doctype(reference[:anchor]),
57
- # }
58
- # hash[:fetched] = Date.today.to_s unless is_relation
59
- # bib_item(**hash)
60
- # end
61
-
62
25
  private
63
26
 
64
- # @param anchor [String]
65
- # @return [String]
66
- # def doctype(anchor)
67
- # anchor&.include?("I-D") ? "internet-draft" : "rfc"
68
- # end
69
-
70
- # @param reference [Nokogiri::XML::Element]
71
- # @param url [String]
72
- # @param ver [String, NilClass] Internet Draft version
73
- # @return [Array<Hash>]
74
- # def link(reference, url, ver)
75
- # l = []
76
- # l << { type: "xml", content: url } if url
77
- # l << { type: "src", content: reference[:target] } if reference[:target]
78
- # if /^I-D/.match? reference[:anchor]
79
- # reference.xpath("format").each do |f|
80
- # c = ver ? f[:target].sub(/(?<=-)\d{2}(?=\.)/, ver) : f[:target]
81
- # l << { type: f[:type], content: c }
82
- # end
83
- # end
84
- # l
85
- # end
86
-
87
- # @param attrs [Hash]
88
- # @return [RelatonIetf::IetfBibliographicItem]
89
- def bib_item(**attrs)
90
- unless attrs.delete(:is_relation)
91
- attrs[:fetched] = Date.today.to_s
92
- attrs[:place] = ["Fremont, CA"]
93
- end
94
- RelatonIetf::IetfBibliographicItem.new(**attrs)
95
- end
96
-
97
27
  # @param ref [String]
98
28
  # @param is_relation [Boolen, nil]
99
29
  # @return [RelatonIetf::IetfBibliographicItem]
@@ -108,17 +38,9 @@ module RelatonIetf
108
38
  # doc = Nokogiri::XML get_page(uri)
109
39
  # r = doc.at("/referencegroup", "/reference")
110
40
  # fetch_rfc r, is_relation: is_relation, url: uri, ver: ver
111
- parse get_page(uri), url: uri, is_relation: is_relation, ver: ver
41
+ BibXMLParser.parse get_page(uri), url: uri, is_relation: is_relation, ver: ver
112
42
  end
113
43
 
114
- # @param reference [Nokogiri::XML::Element]
115
- # @return [Hash]
116
- # def relations(reference)
117
- # reference.xpath("reference").map do |ref|
118
- # { type: "includes", bibitem: fetch_rfc(ref, is_relation: true) }
119
- # end
120
- # end
121
-
122
44
  # @param uri [String]
123
45
  # @return [String] HTTP response body
124
46
  def get_page(uri)
@@ -127,251 +49,5 @@ module RelatonIetf
127
49
 
128
50
  res.body
129
51
  end
130
-
131
- # @param [RelatonBib::WorkGroup]
132
- # @return [RelatonIetf::Committee]
133
- def committee(wgr)
134
- Committee.new wgr
135
- end
136
-
137
- # @param reference [Nokogiri::XML::Element]
138
- # @return [String]
139
- # def language(reference)
140
- # reference[:lang] || "en"
141
- # end
142
-
143
- # @param reference [Nokogiri::XML::Element]
144
- # @return [Array<Hash>]
145
- # def titles(reference)
146
- # reference.xpath("./front/title").map do |title|
147
- # { content: title.text, language: language(reference), script: "Latn" }
148
- # end
149
- # end
150
-
151
- # @param reference [Nokogiri::XML::Element]
152
- # @return [RelatonBib::FormattedRef, nil]
153
- # def formattedref(reference)
154
- # return if reference.at "./front/title"
155
-
156
- # cont = (reference[:anchor] || reference[:docName] || reference[:number])
157
- # if cont
158
- # RelatonBib::FormattedRef.new(
159
- # content: cont, language: language(reference), script: "Latn",
160
- # )
161
- # end
162
- # end
163
-
164
- # @param reference [Nokogiri::XML::Element]
165
- # @return [Array<RelatonBib::FormattedString>]
166
- # def abstracts(ref)
167
- # ref.xpath("./front/abstract").map do |a|
168
- # RelatonBib::FormattedString.new(
169
- # content: a.text.gsub(/\\n\\t{2,4}/, " ").strip,
170
- # language: language(ref), script: "Latn"
171
- # )
172
- # end
173
- # end
174
-
175
- # @param reference [Nokogiri::XML::Element]
176
- # @return [Array<Hash>]
177
- def contributors(reference)
178
- [{ entity: new_org("Internet Engineering Task Force", "IETF"), role: [type: "publisher"] }] + super
179
- # persons(reference) + organizations(reference)
180
- end
181
-
182
- # @param reference [Nokogiri::XML::Element]
183
- # @return [Array<Hash{Symbol=>RelatonBib::Person,Symbol=>Array<String>}>]
184
- # def persons(reference)
185
- # reference.xpath("./front/author[@surname]|./front/author[@fullname]")
186
- # .map do |author|
187
- # entity = RelatonBib::Person.new(
188
- # name: full_name(author, reference),
189
- # affiliation: affiliation(author),
190
- # contact: contacts(author.at("./address")),
191
- # )
192
- # { entity: entity, role: [contributor_role(author)] }
193
- # end
194
- # end
195
-
196
- # @param reference [Nokogiri::XML::Element]
197
- # @return [Array<Hash{Symbol=>RelatonBib::Organization,
198
- # Symbol=>Array<String>}>]
199
- # def organizations(reference)
200
- # publisher = { entity: new_org, role: [type: "publisher"] }
201
- # orgs = reference.xpath("./seriesinfo").reduce([publisher]) do |mem, si|
202
- # next mem unless si[:stream]
203
-
204
- # mem << { entity: new_org(si[:stream], nil), role: [type: "author"] }
205
- # end
206
- # orgs + reference.xpath(
207
- # "front/author[not(@surname)][not(@fullname)]/organization",
208
- # ).map do |org|
209
- # { entity: new_org(org.text, nil), role: [type: "author"] }
210
- # end
211
- # end
212
-
213
- # @param author [Nokogiri::XML::Element]
214
- # @param ref [Nokogiri::XML::Element]
215
- # @return [RelatonBib::FullName]
216
- # def full_name(author, ref)
217
- # lang = language ref
218
- # RelatonBib::FullName.new(
219
- # completename: localized_string(author[:fullname], lang),
220
- # initial: [localized_string(author[:initials], lang)].compact,
221
- # surname: localized_string(author[:surname], lang),
222
- # )
223
- # end
224
-
225
- # @param content [String]
226
- # @param lang [String]
227
- # @return [RelatonBib::LocalizedString]
228
- # def localized_string(content, lang)
229
- # return unless content
230
-
231
- # RelatonBib::LocalizedString.new(content, lang)
232
- # end
233
-
234
- # @param postal [Nokogiri::XML::Element]
235
- # @return [Array<RelatonBib::Address, RelatonBib::Phone>]
236
- # def contacts(addr)
237
- # contacts = []
238
- # return contacts unless addr
239
-
240
- # postal = addr.at("./postal")
241
- # contacts << address(postal) if postal
242
- # add_contact(contacts, "phone", addr.at("./phone"))
243
- # add_contact(contacts, "email", addr.at("./email"))
244
- # add_contact(contacts, "uri", addr.at("./uri"))
245
- # contacts
246
- # end
247
-
248
- # @param postal [Nokogiri::XML::Element]
249
- # @rerurn [RelatonBib::Address]
250
- # def address(postal) # rubocop:disable Metrics/CyclomaticComplexity
251
- # RelatonBib::Address.new(
252
- # street: [(postal.at("./postalLine") || postal.at("./street"))&.text],
253
- # city: postal.at("./city")&.text,
254
- # postcode: postal.at("./code")&.text,
255
- # country: postal.at("./country")&.text,
256
- # state: postal.at("./region")&.text,
257
- # )
258
- # end
259
-
260
- # @param type [String] allowed "phone", "email" or "uri"
261
- # @param value [String]
262
- # def add_contact(contacts, type, value)
263
- # return unless value
264
-
265
- # contacts << RelatonBib::Contact.new(type: type, value: value.text)
266
- # end
267
-
268
- # @param author [Nokogiri::XML::Element]
269
- # @return [RelatonBib::Affiliation]
270
- # def affiliation(author)
271
- # organization = author.at("./organization")
272
- # org = if organization.nil? || organization&.text&.empty?
273
- # new_org
274
- # else
275
- # new_org organization.text, organization[:abbrev]
276
- # end
277
- # RelatonBib::Affiliation.new organization: org
278
- # end
279
-
280
- # @param name [String]
281
- # @param abbr [String]
282
- # @return [RelatonBib::Organization]
283
- # def new_org(name = "Internet Engineering Task Force", abbr = "IETF")
284
- # RelatonBib::Organization.new name: name, abbreviation: abbr
285
- # end
286
-
287
- # @param author [Nokogiri::XML::Document]
288
- # @return [Hash]
289
- # def contributor_role(author)
290
- # { type: author[:role] || "author" }
291
- # end
292
-
293
- # def month(mon)
294
- # return 1 if !mon || mon.empty?
295
- # return mon if /^\d+$/.match? mon
296
-
297
- # Date::MONTHNAMES.index(mon)
298
- # end
299
-
300
- #
301
- # Extract date from reference.
302
- #
303
- # @param reference [Nokogiri::XML::Element]
304
- # @return [Array<RelatonBib::BibliographicDate>] published data.
305
- #
306
- # def dates(reference)
307
- # return unless (date = reference.at "./front/date")
308
-
309
- # d = [date[:year], month(date[:month]),
310
- # (date[:day] || 1)].compact.join "-"
311
- # date = Time.parse(d).strftime "%Y-%m-%d"
312
- # [RelatonBib::BibliographicDate.new(type: "published", on: date)]
313
- # end
314
-
315
- #
316
- # Extract document identifiers from reference
317
- #
318
- # @param reference [Nokogiri::XML::Element]
319
- # @param ver [String, NilClass] Internet Draft version
320
- #
321
- # @return [Array<RelatonBib::DocumentIdentifier>]
322
- #
323
- # def docids(reference, ver) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/AbcSize
324
- # id = (reference[:anchor] || reference[:docName] || reference[:number])
325
- # ret = []
326
- # if id
327
- # ret << RelatonBib::DocumentIdentifier.new(
328
- # type: "IETF", id: id.sub(/^(RFC)/, "\\1 "),
329
- # )
330
- # end
331
- # if (id = reference[:anchor])
332
- # ret << RelatonBib::DocumentIdentifier.new(type: "rfc-anchor", id: id)
333
- # end
334
- # names = ["DOI", "Internet-Draft"]
335
- # ret + reference.xpath("./seriesInfo").map do |si|
336
- # next unless names.include? si[:name]
337
-
338
- # id = si[:value]
339
- # id.sub!(/(?<=-)\d{2}$/, ver) if ver && si[:name] == "Internet-Draft"
340
- # RelatonBib::DocumentIdentifier.new(id: id, type: si[:name])
341
- # end.compact
342
- # end
343
-
344
- #
345
- # Extract series form reference
346
- # @param reference [Nokogiri::XML::Element]
347
- #
348
- # @return [Array<RelatonBib::Series>]
349
- #
350
- # def series(reference)
351
- # reference.xpath("./seriesInfo").map do |si|
352
- # next if si[:name] == "DOI" || si[:stream] || si[:status]
353
-
354
- # RelatonBib::Series.new(
355
- # title: RelatonBib::TypedTitleString.new(
356
- # content: si[:name], language: language(reference), script: "Latn",
357
- # ),
358
- # number: si[:value],
359
- # type: "main",
360
- # )
361
- # end.compact
362
- # end
363
-
364
- #
365
- # extract status
366
- # @param reference [Nokogiri::XML::Element]
367
- #
368
- # @return [RelatonBib::DocumentStatus]
369
- #
370
- # def status(reference)
371
- # st = reference.at("./seriesinfo[@status]")
372
- # return unless st
373
-
374
- # RelatonBib::DocumentStatus.new(stage: st[:status])
375
- # end
376
52
  end
377
53
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonIetf
2
- VERSION = "1.9.6".freeze
2
+ VERSION = "1.9.7".freeze
3
3
  end
data/lib/relaton_ietf.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "net/http"
4
+ require "relaton_bib"
3
5
  require "relaton_ietf/version"
6
+ require "relaton_ietf/bibxml_parser"
4
7
  require "relaton_ietf/ietf_bibliography"
5
8
  require "relaton_ietf/ietf_bibliographic_item"
6
9
  require "relaton_ietf/xml_parser"
data/relaton_ietf.gemspec CHANGED
@@ -38,6 +38,6 @@ Gem::Specification.new do |spec|
38
38
  spec.add_development_dependency "vcr"
39
39
  spec.add_development_dependency "webmock"
40
40
 
41
- spec.add_dependency "relaton-bib", ">= 1.9.8"
41
+ spec.add_dependency "relaton-bib", ">= 1.9.12"
42
42
  spec.add_dependency "zlib", "~> 1.1.0"
43
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-ietf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.6
4
+ version: 1.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-24 00:00:00.000000000 Z
11
+ date: 2021-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: equivalent-xml
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: 1.9.8
131
+ version: 1.9.12
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: 1.9.8
138
+ version: 1.9.12
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: zlib
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -177,6 +177,7 @@ files:
177
177
  - grammars/reqt.rng
178
178
  - lib/relaton/provider_ietf.rb
179
179
  - lib/relaton_ietf.rb
180
+ - lib/relaton_ietf/bibxml_parser.rb
180
181
  - lib/relaton_ietf/committee.rb
181
182
  - lib/relaton_ietf/data_fetcher.rb
182
183
  - lib/relaton_ietf/hash_converter.rb