relaton-bib 1.0.4 → 1.2.2
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/.gitmodules +0 -3
- data/grammars/basicdoc.rng +986 -0
- data/grammars/biblio.rng +1237 -0
- data/grammars/isodoc.rng +1504 -0
- data/grammars/reqt.rng +171 -0
- data/lib/relaton_bib.rb +7 -4
- data/lib/relaton_bib/bibliographic_item.rb +128 -26
- data/lib/relaton_bib/copyright_association.rb +28 -9
- data/lib/relaton_bib/document_relation.rb +1 -1
- data/lib/relaton_bib/document_relation_collection.rb +2 -2
- data/lib/relaton_bib/document_status.rb +3 -2
- data/lib/relaton_bib/editorial_group.rb +27 -0
- data/lib/relaton_bib/hash_converter.rb +78 -23
- data/lib/relaton_bib/ics.rb +26 -0
- data/lib/relaton_bib/structured_identifier.rb +141 -0
- data/lib/relaton_bib/technical_committee.rb +25 -0
- data/lib/relaton_bib/typed_title_string.rb +38 -8
- data/lib/relaton_bib/version.rb +1 -1
- data/lib/relaton_bib/workgroup.rb +36 -0
- data/lib/relaton_bib/xml_parser.rb +69 -23
- metadata +11 -2
@@ -0,0 +1,25 @@
|
|
1
|
+
require "relaton_bib/workgroup"
|
2
|
+
|
3
|
+
module RelatonBib
|
4
|
+
class TechnicalCommittee
|
5
|
+
# @return [RelatonBib::WorkGroup]
|
6
|
+
attr_reader :workgroup
|
7
|
+
|
8
|
+
# @param workgroup [RelatonBib::WorkGroup]
|
9
|
+
def initialize(workgroup)
|
10
|
+
@workgroup = workgroup
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param builder [Nokogiri::XML::Builder]
|
14
|
+
def to_xml(builder)
|
15
|
+
builder.send "technical-committee" do |b|
|
16
|
+
workgroup.to_xml b
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Hash]
|
21
|
+
def to_hash
|
22
|
+
workgroup.to_hash
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,14 +1,12 @@
|
|
1
1
|
module RelatonBib
|
2
2
|
class TypedTitleString
|
3
|
-
# TITLE_TYPES = %w[alternative original unofficial subtitle main].freeze
|
4
|
-
|
5
3
|
# @return [String]
|
6
4
|
attr_reader :type
|
7
5
|
|
8
6
|
# @return [RelatonBib::FormattedString]
|
9
7
|
attr_reader :title
|
10
8
|
|
11
|
-
# rubocop:disable Metrics/
|
9
|
+
# rubocop:disable Metrics/MethodLength
|
12
10
|
|
13
11
|
# @param type [String]
|
14
12
|
# @param title [RelatonBib::FormattedString, Hash]
|
@@ -16,10 +14,6 @@ module RelatonBib
|
|
16
14
|
# @param language [String]
|
17
15
|
# @param script [String]
|
18
16
|
def initialize(**args)
|
19
|
-
# if args[:type] && !TITLE_TYPES.include?(args[:type])
|
20
|
-
# warn %{[relaton-bib] title type "#{args[:type]}" is invalid.}
|
21
|
-
# end
|
22
|
-
|
23
17
|
unless args[:title] || args[:content]
|
24
18
|
raise ArgumentError, %{Keyword "title" or "content" should be passed.}
|
25
19
|
end
|
@@ -35,7 +29,43 @@ module RelatonBib
|
|
35
29
|
@title = FormattedString.new(fsargs)
|
36
30
|
end
|
37
31
|
end
|
38
|
-
# rubocop:enable Metrics/
|
32
|
+
# rubocop:enable Metrics/MethodLength
|
33
|
+
|
34
|
+
# @param title [String]
|
35
|
+
# @return [Array<self>]
|
36
|
+
def self.from_string(title, lang = nil, script = nil)
|
37
|
+
types = %w[title-intro title-main title-part]
|
38
|
+
ttls = split_title(title)
|
39
|
+
tts = ttls.map.with_index do |p, i|
|
40
|
+
new type: types[i], content: p, language: lang, script: script if p
|
41
|
+
end.compact
|
42
|
+
tts << new(type: "main", content: ttls.compact.join(" - "),
|
43
|
+
language: lang, script: script)
|
44
|
+
end
|
45
|
+
|
46
|
+
# @param title [String]
|
47
|
+
# @return [Array<String, nil>]
|
48
|
+
def self.split_title(title)
|
49
|
+
ttls = title.sub(/\w\.Imp\s?\d+\u00A0:\u00A0/, "").split " - "
|
50
|
+
case ttls.size
|
51
|
+
when 0, 1 then [nil, ttls.first.to_s, nil]
|
52
|
+
else intro_or_part ttls
|
53
|
+
# when 2, 3 then intro_or_part ttls
|
54
|
+
# else [ttls[0], ttls[1], ttls[2..-1].join(" -- ")]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# @param ttls [Array<String>]
|
59
|
+
# @return [Array<Strin, nil>]
|
60
|
+
def self.intro_or_part(ttls)
|
61
|
+
if /^(Part|Partie) \d+:/ =~ ttls[1]
|
62
|
+
[nil, ttls[0], ttls[1..-1].join(" -- ")]
|
63
|
+
else
|
64
|
+
parts = ttls.slice(2..-1)
|
65
|
+
part = parts.join " -- " if parts.any?
|
66
|
+
[ttls[0], ttls[1], part]
|
67
|
+
end
|
68
|
+
end
|
39
69
|
|
40
70
|
# @param builder [Nokogiri::XML::Builder]
|
41
71
|
def to_xml(builder)
|
data/lib/relaton_bib/version.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
module RelatonBib
|
2
|
+
class WorkGroup
|
3
|
+
# @return [String]
|
4
|
+
attr_reader :content
|
5
|
+
|
6
|
+
# @return [Integer, nil]
|
7
|
+
attr_reader :number
|
8
|
+
|
9
|
+
# @return [String, nil]
|
10
|
+
attr_reader :type
|
11
|
+
|
12
|
+
# @param content [String]
|
13
|
+
# @param number [Integer, nil]
|
14
|
+
# @param type [String, nil]
|
15
|
+
def initialize(content:, number: nil, type: nil)
|
16
|
+
@content = content
|
17
|
+
@number = number
|
18
|
+
@type = type
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param builder [Nokogiri::XML::Builder]
|
22
|
+
def to_xml(builder)
|
23
|
+
builder.text content
|
24
|
+
builder.parent[:number] = number if number
|
25
|
+
builder.parent[:type] = type if type
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [Hash]
|
29
|
+
def to_hash
|
30
|
+
hash = { "content" => content }
|
31
|
+
hash["number"] = number if number
|
32
|
+
hash["type"] = type if type
|
33
|
+
hash
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -20,6 +20,7 @@ module RelatonBib
|
|
20
20
|
|
21
21
|
# @return [Hash]
|
22
22
|
def item_data(bibitem)
|
23
|
+
ext = bibitem.at "//ext"
|
23
24
|
{
|
24
25
|
id: bibitem[:id]&.empty? ? nil : bibitem[:id],
|
25
26
|
type: bibitem[:type]&.empty? ? nil : bibitem[:type],
|
@@ -49,6 +50,10 @@ module RelatonBib
|
|
49
50
|
keyword: bibitem.xpath("keyword").map(&:text),
|
50
51
|
license: bibitem.xpath("license").map(&:text),
|
51
52
|
validity: fetch_validity(bibitem),
|
53
|
+
doctype: ext&.at("doctype")&.text,
|
54
|
+
editorialgroup: fetch_editorialgroup(ext),
|
55
|
+
ics: fetch_ics(ext),
|
56
|
+
structuredidentifier: fetch_structuredidentifier(ext),
|
52
57
|
}
|
53
58
|
end
|
54
59
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
@@ -244,14 +249,9 @@ module RelatonBib
|
|
244
249
|
end
|
245
250
|
|
246
251
|
cn = person.at "./name/completename"
|
247
|
-
cname =
|
248
|
-
LocalizedString.new(cn.text, cn[:language], cn[:script])
|
249
|
-
else
|
250
|
-
nil
|
251
|
-
end
|
252
|
-
|
252
|
+
cname = cn && LocalizedString.new(cn.text, cn[:language], cn[:script])
|
253
253
|
sn = person.at "./name/surname"
|
254
|
-
sname = sn
|
254
|
+
sname = sn && LocalizedString.new(sn.text, sn[:language], sn[:script])
|
255
255
|
|
256
256
|
name = FullName.new(
|
257
257
|
completename: cname, surname: sname,
|
@@ -291,25 +291,24 @@ module RelatonBib
|
|
291
291
|
# @return [Array<RelatonBib::FormattedString>]
|
292
292
|
def fetch_abstract(item)
|
293
293
|
item.xpath("./abstract").map do |a|
|
294
|
-
FormattedString.new(
|
295
|
-
|
296
|
-
)
|
294
|
+
FormattedString.new(content: a.text, language: a[:language],
|
295
|
+
script: a[:script], format: a[:format])
|
297
296
|
end
|
298
297
|
end
|
299
298
|
|
300
299
|
# @param item [Nokogiri::XML::Element]
|
301
|
-
# @return [RelatonBib::CopyrightAssociation]
|
300
|
+
# @return [Array<RelatonBib::CopyrightAssociation>]
|
302
301
|
def fetch_copyright(item)
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
302
|
+
item.xpath("./copyright").map do |cp|
|
303
|
+
owner = cp.xpath("owner").map do |o|
|
304
|
+
ContributionInfo.new entity: get_org(o.at("organization"))
|
305
|
+
end
|
306
|
+
from = cp.at("from")&.text
|
307
|
+
to = cp.at("to")&.text
|
308
|
+
scope = cp.at("scope")&.text
|
309
|
+
CopyrightAssociation.new(owner: owner, from: from, to: to,
|
310
|
+
scope: scope)
|
311
|
+
end
|
313
312
|
end
|
314
313
|
|
315
314
|
# @param item [Nokogiri::XML::Element]
|
@@ -357,7 +356,7 @@ module RelatonBib
|
|
357
356
|
if lc[:type]
|
358
357
|
LocalityStack.new [locality(lc)]
|
359
358
|
else
|
360
|
-
LocalityStack.new
|
359
|
+
LocalityStack.new(lc.xpath("./locality").map { |l| locality l })
|
361
360
|
end
|
362
361
|
end
|
363
362
|
end
|
@@ -365,7 +364,7 @@ module RelatonBib
|
|
365
364
|
# @param loc [Nokogiri::XML::Element]
|
366
365
|
# @return [RelatonBib::Locality]
|
367
366
|
def locality(loc, klass = Locality)
|
368
|
-
ref_to = (rt = loc.at("./referenceTo"))
|
367
|
+
ref_to = (rt = loc.at("./referenceTo")) && LocalizedString.new(rt.text)
|
369
368
|
klass.new(
|
370
369
|
loc[:type],
|
371
370
|
LocalizedString.new(loc.at("./referenceFrom").text),
|
@@ -397,6 +396,53 @@ module RelatonBib
|
|
397
396
|
language: ident[:language], script: ident[:script]
|
398
397
|
)
|
399
398
|
end
|
399
|
+
|
400
|
+
# @param ext [Nokogiri::XML::Element]
|
401
|
+
# @return [RelatonBib::EditorialGroup, nil]
|
402
|
+
def fetch_editorialgroup(ext)
|
403
|
+
return unless ext && (eg = ext.at "editorialgroup")
|
404
|
+
|
405
|
+
eg = eg.xpath("technical-committee").map do |tc|
|
406
|
+
wg = WorkGroup.new(content: tc.text, number: tc[:number]&.to_i,
|
407
|
+
type: tc[:type])
|
408
|
+
TechnicalCommittee.new wg
|
409
|
+
end
|
410
|
+
EditorialGroup.new eg if eg.any?
|
411
|
+
end
|
412
|
+
|
413
|
+
def fetch_ics(ext)
|
414
|
+
return [] unless ext
|
415
|
+
|
416
|
+
ext.xpath("ics").map do |ics|
|
417
|
+
ICS.new code: ics.at("code")&.text, text: ics.at("text")&.text
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
422
|
+
|
423
|
+
# @param ext [Nokogiri::XML::Element]
|
424
|
+
# @return [RelatonBib::StructuredIdentifierCollection]
|
425
|
+
def fetch_structuredidentifier(ext)
|
426
|
+
return unless ext
|
427
|
+
|
428
|
+
sids = ext.xpath("structuredidentifier").map do |si|
|
429
|
+
StructuredIdentifier.new(
|
430
|
+
type: si[:type],
|
431
|
+
agency: si.xpath("agency").map(&:text),
|
432
|
+
class: si.at("class")&.text,
|
433
|
+
docnumber: si.at("docnumber")&.text,
|
434
|
+
partnumber: si.at("partnumber")&.text,
|
435
|
+
edition: si.at("edition")&.text,
|
436
|
+
version: si.at("version")&.text,
|
437
|
+
supplementtype: si.at("supplementtype")&.text,
|
438
|
+
supplementnumber: si.at("supplementnumber")&.text,
|
439
|
+
language: si.at("language")&.text,
|
440
|
+
year: si.at("year")&.text,
|
441
|
+
)
|
442
|
+
end
|
443
|
+
StructuredIdentifierCollection.new sids
|
444
|
+
end
|
445
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
400
446
|
end
|
401
447
|
end
|
402
448
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-bib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -201,6 +201,10 @@ files:
|
|
201
201
|
- bin/rspec
|
202
202
|
- bin/setup
|
203
203
|
- docs/hash.adoc
|
204
|
+
- grammars/basicdoc.rng
|
205
|
+
- grammars/biblio.rng
|
206
|
+
- grammars/isodoc.rng
|
207
|
+
- grammars/reqt.rng
|
204
208
|
- lib/relaton_bib.rb
|
205
209
|
- lib/relaton_bib/bib_item_locality.rb
|
206
210
|
- lib/relaton_bib/biblio_note.rb
|
@@ -217,22 +221,27 @@ files:
|
|
217
221
|
- lib/relaton_bib/document_relation.rb
|
218
222
|
- lib/relaton_bib/document_relation_collection.rb
|
219
223
|
- lib/relaton_bib/document_status.rb
|
224
|
+
- lib/relaton_bib/editorial_group.rb
|
220
225
|
- lib/relaton_bib/formatted_ref.rb
|
221
226
|
- lib/relaton_bib/formatted_string.rb
|
222
227
|
- lib/relaton_bib/hash_converter.rb
|
223
228
|
- lib/relaton_bib/hit.rb
|
224
229
|
- lib/relaton_bib/hit_collection.rb
|
230
|
+
- lib/relaton_bib/ics.rb
|
225
231
|
- lib/relaton_bib/localized_string.rb
|
226
232
|
- lib/relaton_bib/medium.rb
|
227
233
|
- lib/relaton_bib/organization.rb
|
228
234
|
- lib/relaton_bib/person.rb
|
229
235
|
- lib/relaton_bib/place.rb
|
230
236
|
- lib/relaton_bib/series.rb
|
237
|
+
- lib/relaton_bib/structured_identifier.rb
|
238
|
+
- lib/relaton_bib/technical_committee.rb
|
231
239
|
- lib/relaton_bib/typed_title_string.rb
|
232
240
|
- lib/relaton_bib/typed_uri.rb
|
233
241
|
- lib/relaton_bib/validity.rb
|
234
242
|
- lib/relaton_bib/version.rb
|
235
243
|
- lib/relaton_bib/workers_pool.rb
|
244
|
+
- lib/relaton_bib/workgroup.rb
|
236
245
|
- lib/relaton_bib/xml_parser.rb
|
237
246
|
- relaton-bib.gemspec
|
238
247
|
homepage: https://github.com/relaton/relaton-bib
|