relaton-bib 1.1.0 → 1.1.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/.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 +4 -1
- data/lib/relaton_bib/bibliographic_item.rb +119 -15
- data/lib/relaton_bib/document_relation_collection.rb +2 -2
- data/lib/relaton_bib/editorial_group.rb +27 -0
- data/lib/relaton_bib/hash_converter.rb +64 -21
- 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 +36 -0
- data/lib/relaton_bib/version.rb +1 -1
- data/lib/relaton_bib/workgroup.rb +36 -0
- data/lib/relaton_bib/xml_parser.rb +54 -2
- metadata +11 -2
data/grammars/reqt.rng
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
|
3
|
+
<!--
|
4
|
+
Presupposes isodoc.rnc, is included in it
|
5
|
+
include "isodoc.rnc" { }
|
6
|
+
-->
|
7
|
+
<define name="requirement">
|
8
|
+
<element name="requirement">
|
9
|
+
<ref name="RequirementType"/>
|
10
|
+
</element>
|
11
|
+
</define>
|
12
|
+
<define name="recommendation">
|
13
|
+
<element name="recommendation">
|
14
|
+
<ref name="RequirementType"/>
|
15
|
+
</element>
|
16
|
+
</define>
|
17
|
+
<define name="permission">
|
18
|
+
<element name="permission">
|
19
|
+
<ref name="RequirementType"/>
|
20
|
+
</element>
|
21
|
+
</define>
|
22
|
+
<define name="RequirementType">
|
23
|
+
<optional>
|
24
|
+
<attribute name="obligation">
|
25
|
+
<ref name="ObligationType"/>
|
26
|
+
</attribute>
|
27
|
+
</optional>
|
28
|
+
<optional>
|
29
|
+
<attribute name="unnumbered">
|
30
|
+
<data type="boolean"/>
|
31
|
+
</attribute>
|
32
|
+
</optional>
|
33
|
+
<optional>
|
34
|
+
<attribute name="subsequence"/>
|
35
|
+
</optional>
|
36
|
+
<attribute name="id">
|
37
|
+
<data type="ID"/>
|
38
|
+
</attribute>
|
39
|
+
<optional>
|
40
|
+
<attribute name="filename"/>
|
41
|
+
</optional>
|
42
|
+
<optional>
|
43
|
+
<attribute name="model"/>
|
44
|
+
</optional>
|
45
|
+
<optional>
|
46
|
+
<attribute name="type"/>
|
47
|
+
</optional>
|
48
|
+
<optional>
|
49
|
+
<ref name="reqtitle"/>
|
50
|
+
</optional>
|
51
|
+
<optional>
|
52
|
+
<ref name="label"/>
|
53
|
+
</optional>
|
54
|
+
<optional>
|
55
|
+
<ref name="subject"/>
|
56
|
+
</optional>
|
57
|
+
<zeroOrMore>
|
58
|
+
<ref name="reqinherit"/>
|
59
|
+
</zeroOrMore>
|
60
|
+
<zeroOrMore>
|
61
|
+
<ref name="classification"/>
|
62
|
+
</zeroOrMore>
|
63
|
+
<zeroOrMore>
|
64
|
+
<choice>
|
65
|
+
<ref name="measurementtarget"/>
|
66
|
+
<ref name="specification"/>
|
67
|
+
<ref name="verification"/>
|
68
|
+
<ref name="import"/>
|
69
|
+
<ref name="description"/>
|
70
|
+
</choice>
|
71
|
+
</zeroOrMore>
|
72
|
+
<optional>
|
73
|
+
<ref name="reqt_references"/>
|
74
|
+
</optional>
|
75
|
+
<zeroOrMore>
|
76
|
+
<choice>
|
77
|
+
<ref name="requirement"/>
|
78
|
+
<ref name="recommendation"/>
|
79
|
+
<ref name="permission"/>
|
80
|
+
</choice>
|
81
|
+
</zeroOrMore>
|
82
|
+
</define>
|
83
|
+
<define name="reqtitle">
|
84
|
+
<element name="title">
|
85
|
+
<ref name="FormattedString"/>
|
86
|
+
</element>
|
87
|
+
</define>
|
88
|
+
<define name="label">
|
89
|
+
<element name="label">
|
90
|
+
<text/>
|
91
|
+
</element>
|
92
|
+
</define>
|
93
|
+
<define name="subject">
|
94
|
+
<element name="subject">
|
95
|
+
<text/>
|
96
|
+
</element>
|
97
|
+
</define>
|
98
|
+
<define name="reqinherit">
|
99
|
+
<element name="inherit">
|
100
|
+
<text/>
|
101
|
+
</element>
|
102
|
+
</define>
|
103
|
+
<define name="measurementtarget">
|
104
|
+
<element name="measurement-target">
|
105
|
+
<ref name="RequirementSubpart"/>
|
106
|
+
</element>
|
107
|
+
</define>
|
108
|
+
<define name="specification">
|
109
|
+
<element name="specification">
|
110
|
+
<ref name="RequirementSubpart"/>
|
111
|
+
</element>
|
112
|
+
</define>
|
113
|
+
<define name="verification">
|
114
|
+
<element name="verification">
|
115
|
+
<ref name="RequirementSubpart"/>
|
116
|
+
</element>
|
117
|
+
</define>
|
118
|
+
<define name="import">
|
119
|
+
<element name="import">
|
120
|
+
<ref name="RequirementSubpart"/>
|
121
|
+
</element>
|
122
|
+
</define>
|
123
|
+
<define name="description">
|
124
|
+
<element name="description">
|
125
|
+
<ref name="RequirementSubpart"/>
|
126
|
+
</element>
|
127
|
+
</define>
|
128
|
+
<define name="reqt_references">
|
129
|
+
<element name="references">
|
130
|
+
<oneOrMore>
|
131
|
+
<ref name="bibitem"/>
|
132
|
+
</oneOrMore>
|
133
|
+
</element>
|
134
|
+
</define>
|
135
|
+
<define name="RequirementSubpart">
|
136
|
+
<optional>
|
137
|
+
<attribute name="type"/>
|
138
|
+
</optional>
|
139
|
+
<optional>
|
140
|
+
<attribute name="exclude">
|
141
|
+
<data type="boolean"/>
|
142
|
+
</attribute>
|
143
|
+
</optional>
|
144
|
+
<oneOrMore>
|
145
|
+
<ref name="BasicBlock"/>
|
146
|
+
</oneOrMore>
|
147
|
+
</define>
|
148
|
+
<define name="ObligationType">
|
149
|
+
<choice>
|
150
|
+
<value>requirement</value>
|
151
|
+
<value>recommendation</value>
|
152
|
+
<value>permission</value>
|
153
|
+
</choice>
|
154
|
+
</define>
|
155
|
+
<define name="classification">
|
156
|
+
<element name="classification">
|
157
|
+
<ref name="classification_tag"/>
|
158
|
+
<ref name="classification_value"/>
|
159
|
+
</element>
|
160
|
+
</define>
|
161
|
+
<define name="classification_tag">
|
162
|
+
<element name="tag">
|
163
|
+
<text/>
|
164
|
+
</element>
|
165
|
+
</define>
|
166
|
+
<define name="classification_value">
|
167
|
+
<element name="value">
|
168
|
+
<text/>
|
169
|
+
</element>
|
170
|
+
</define>
|
171
|
+
</grammar>
|
data/lib/relaton_bib.rb
CHANGED
@@ -10,6 +10,8 @@ module RelatonBib
|
|
10
10
|
class RequestError < StandardError; end
|
11
11
|
|
12
12
|
class << self
|
13
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
14
|
+
|
13
15
|
# @param date [String]
|
14
16
|
# @return [Date, NilClass]
|
15
17
|
def parse_date(sdate)
|
@@ -25,6 +27,7 @@ module RelatonBib
|
|
25
27
|
elsif /(?<date>\d{4})/ =~ sdate then Date.strptime date, "%Y" # 2012
|
26
28
|
end
|
27
29
|
end
|
30
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
28
31
|
end
|
29
32
|
|
30
33
|
private
|
@@ -35,7 +38,7 @@ module RelatonBib
|
|
35
38
|
if array.size > 1
|
36
39
|
array.map { |e| e.is_a?(String) ? e : e.to_hash }
|
37
40
|
else
|
38
|
-
array
|
41
|
+
array.first&.is_a?(String) ? array[0] : array.first&.to_hash
|
39
42
|
end
|
40
43
|
end
|
41
44
|
end
|
@@ -24,6 +24,9 @@ require "relaton_bib/biblio_version"
|
|
24
24
|
require "relaton_bib/workers_pool"
|
25
25
|
require "relaton_bib/hash_converter"
|
26
26
|
require "relaton_bib/place"
|
27
|
+
require "relaton_bib/structured_identifier"
|
28
|
+
require "relaton_bib/editorial_group"
|
29
|
+
require "relaton_bib/ics"
|
27
30
|
|
28
31
|
module RelatonBib
|
29
32
|
# Bibliographic item
|
@@ -35,33 +38,27 @@ module RelatonBib
|
|
35
38
|
audiovisual film video broadcast graphic_work music patent
|
36
39
|
inbook incollection inproceedings journal].freeze
|
37
40
|
|
41
|
+
# @return [TrueClass, FalseClass, NilClass]
|
42
|
+
attr_accessor :all_parts
|
43
|
+
|
38
44
|
# @return [String, NilClass]
|
39
|
-
attr_reader :id
|
45
|
+
attr_reader :id, :type, :docnumber, :edition, :doctype
|
40
46
|
|
47
|
+
# @!attribute [r] title
|
41
48
|
# @return [Array<RelatonBib::TypedTitleString>]
|
42
|
-
attr_reader :title
|
43
49
|
|
44
50
|
# @return [Array<RelatonBib::TypedUri>]
|
45
51
|
attr_reader :link
|
46
52
|
|
47
|
-
# @return [String, NilClass]
|
48
|
-
attr_reader :type
|
49
|
-
|
50
53
|
# @return [Array<RelatonBib::DocumentIdentifier>]
|
51
54
|
attr_reader :docidentifier
|
52
55
|
|
53
|
-
# @return [String, NilClass] docnumber
|
54
|
-
attr_reader :docnumber
|
55
|
-
|
56
56
|
# @return [Array<RelatonBib::BibliographicDate>]
|
57
57
|
attr_accessor :date
|
58
58
|
|
59
59
|
# @return [Array<RelatonBib::ContributionInfo>]
|
60
60
|
attr_reader :contributor
|
61
61
|
|
62
|
-
# @return [String, NillClass]
|
63
|
-
attr_reader :edition
|
64
|
-
|
65
62
|
# @return [RelatonBib::BibliongraphicItem::Version, NilClass]
|
66
63
|
attr_reader :version
|
67
64
|
|
@@ -116,6 +113,15 @@ module RelatonBib
|
|
116
113
|
# @return [Array<RelatonBib::LocalizedString>]
|
117
114
|
attr_reader :keyword
|
118
115
|
|
116
|
+
# @return [RelatonBib::EditorialGroup, nil]
|
117
|
+
attr_reader :editorialgroup
|
118
|
+
|
119
|
+
# @return [Array<RelatonBib:ICS>]
|
120
|
+
attr_reader :ics
|
121
|
+
|
122
|
+
# @return [RelatonBib::StructuredIdentifierCollection]
|
123
|
+
attr_reader :structuredidentifier
|
124
|
+
|
119
125
|
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
120
126
|
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
121
127
|
|
@@ -140,6 +146,10 @@ module RelatonBib
|
|
140
146
|
# @param validity [RelatonBib:Validity, NilClass]
|
141
147
|
# @param fetched [Date, NilClass] default nil
|
142
148
|
# @param keyword [Array<String>]
|
149
|
+
# @param doctype [String]
|
150
|
+
# @param editorialgroup [RelatonBib::EditorialGroup, nil]
|
151
|
+
# @param ics [Array<RelatonBib::ICS>]
|
152
|
+
# @param structuredidentifier [RelatonBib::StructuredIdentifierCollection]
|
143
153
|
#
|
144
154
|
# @param copyright [Array<Hash, RelatonBib::CopyrightAssociation>]
|
145
155
|
# @option copyright [Array<Hash, RelatonBib::ContributionInfo>] :owner
|
@@ -235,6 +245,10 @@ module RelatonBib
|
|
235
245
|
@fetched = args.fetch :fetched, nil # , Date.today # we should pass the fetched arg from scrappers
|
236
246
|
@keyword = (args[:keyword] || []).map { |kw| LocalizedString.new(kw) }
|
237
247
|
@license = args.fetch :license, []
|
248
|
+
@doctype = args[:doctype]
|
249
|
+
@editorialgroup = args[:editorialgroup]
|
250
|
+
@ics = args.fetch :ics, []
|
251
|
+
@structuredidentifier = args[:structuredidentifier]
|
238
252
|
end
|
239
253
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
240
254
|
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
@@ -286,6 +300,8 @@ module RelatonBib
|
|
286
300
|
end
|
287
301
|
end
|
288
302
|
|
303
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
304
|
+
|
289
305
|
# @return [Hash]
|
290
306
|
def to_hash
|
291
307
|
hash = {}
|
@@ -318,8 +334,15 @@ module RelatonBib
|
|
318
334
|
hash["fetched"] = fetched.to_s if fetched
|
319
335
|
hash["keyword"] = single_element_array(keyword) if keyword&.any?
|
320
336
|
hash["license"] = single_element_array(license) if license&.any?
|
337
|
+
hash["doctype"] = doctype if doctype
|
338
|
+
hash["editorialgroup"] = editorialgroup.to_hash if editorialgroup
|
339
|
+
hash["ics"] = single_element_array ics if ics.any?
|
340
|
+
if structuredidentifier&.presence?
|
341
|
+
hash["structuredidentifier"] = structuredidentifier.to_hash
|
342
|
+
end
|
321
343
|
hash
|
322
344
|
end
|
345
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
323
346
|
|
324
347
|
# @param bibtex [BibTeX::Bibliography, NilClass]
|
325
348
|
# @return [String]
|
@@ -346,6 +369,74 @@ module RelatonBib
|
|
346
369
|
bibtex << item
|
347
370
|
bibtex.to_s
|
348
371
|
end
|
372
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
373
|
+
|
374
|
+
# @param lang [String] language code Iso639
|
375
|
+
# @return [Array<RelatonIsoBib::TypedTitleString>]
|
376
|
+
def title(lang: nil)
|
377
|
+
if lang then @title.select { |t| t.title.language&.include? lang }
|
378
|
+
else @title
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
# @param type [Symbol] type of url, can be :src/:obp/:rss
|
383
|
+
# @return [String]
|
384
|
+
def url(type = :src)
|
385
|
+
@link.detect { |s| s.type == type.to_s }.content.to_s
|
386
|
+
end
|
387
|
+
|
388
|
+
def abstract=(value)
|
389
|
+
@abstract = value
|
390
|
+
end
|
391
|
+
|
392
|
+
def deep_clone
|
393
|
+
dump = Marshal.dump self
|
394
|
+
Marshal.load dump
|
395
|
+
end
|
396
|
+
|
397
|
+
def disable_id_attribute
|
398
|
+
@id_attribute = false
|
399
|
+
end
|
400
|
+
|
401
|
+
# remove title part components and abstract
|
402
|
+
def to_all_parts
|
403
|
+
me = deep_clone
|
404
|
+
me.disable_id_attribute
|
405
|
+
me.relation << RelatonBib::DocumentRelation.new(
|
406
|
+
type: "instance", bibitem: self,
|
407
|
+
)
|
408
|
+
me.language.each do |l|
|
409
|
+
me.title.delete_if { |t| t.type == "title-part" }
|
410
|
+
ttl = me.title.select { |t| t.type != "main" && t.title.language&.include?(l) }
|
411
|
+
tm_en = ttl.map { |t| t.title.content }.join " – "
|
412
|
+
me.title.detect { |t| t.type == "main" && t.title.language&.include?(l) }&.title&.content = tm_en
|
413
|
+
end
|
414
|
+
me.abstract = []
|
415
|
+
me.docidentifier.each(&:remove_part)
|
416
|
+
me.docidentifier.each(&:all_parts)
|
417
|
+
me.structuredidentifier.remove_part
|
418
|
+
me.structuredidentifier.all_parts
|
419
|
+
me.docidentifier.each &:remove_date
|
420
|
+
me.structuredidentifier&.remove_date
|
421
|
+
me.all_parts = true
|
422
|
+
me
|
423
|
+
end
|
424
|
+
|
425
|
+
# convert ISO:yyyy reference to reference to most recent
|
426
|
+
# instance of reference, removing date-specific infomration:
|
427
|
+
# date of publication, abstracts. Make dated reference Instance relation
|
428
|
+
# of the redacated document
|
429
|
+
def to_most_recent_reference
|
430
|
+
me = deep_clone
|
431
|
+
disable_id_attribute
|
432
|
+
me.relation << DocumentRelation.new(type: "instance", bibitem: self)
|
433
|
+
me.abstract = []
|
434
|
+
me.date = []
|
435
|
+
me.docidentifier.each &:remove_date
|
436
|
+
me.structuredidentifier&.remove_date
|
437
|
+
me.id&.sub! /-[12]\d\d\d/, ""
|
438
|
+
me
|
439
|
+
end
|
349
440
|
|
350
441
|
# If revision_date exists then returns it else returns published date or nil
|
351
442
|
# @return [String, NilClass]
|
@@ -376,6 +467,8 @@ module RelatonBib
|
|
376
467
|
end
|
377
468
|
end
|
378
469
|
|
470
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
471
|
+
|
379
472
|
# @param [BibTeX::Entry]
|
380
473
|
def bibtex_author(item)
|
381
474
|
authors = contributor.select do |c|
|
@@ -386,7 +479,7 @@ module RelatonBib
|
|
386
479
|
|
387
480
|
item.author = authors.map do |a|
|
388
481
|
if a.name.surname
|
389
|
-
"#{a.name.surname}, #{a.name.forename.map(&:to_s).join(
|
482
|
+
"#{a.name.surname}, #{a.name.forename.map(&:to_s).join(' ')}"
|
390
483
|
else
|
391
484
|
a.name.completename.to_s
|
392
485
|
end
|
@@ -408,6 +501,7 @@ module RelatonBib
|
|
408
501
|
end
|
409
502
|
end
|
410
503
|
end
|
504
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
411
505
|
|
412
506
|
# @param [BibTeX::Entry]
|
413
507
|
def bibtex_note(item)
|
@@ -425,7 +519,10 @@ module RelatonBib
|
|
425
519
|
# @param [BibTeX::Entry]
|
426
520
|
def bibtex_relation(item)
|
427
521
|
rel = relation.detect { |r| r.type == "partOf" }
|
428
|
-
|
522
|
+
if rel
|
523
|
+
title_main = rel.bibitem.title.detect { |t| t.type == "main" }
|
524
|
+
item.booktitle = title_main.title.content
|
525
|
+
end
|
429
526
|
end
|
430
527
|
|
431
528
|
# @param [BibTeX::Entry]
|
@@ -539,8 +636,15 @@ module RelatonBib
|
|
539
636
|
classification.each { |cls| cls.to_xml builder }
|
540
637
|
keyword.each { |kw| builder.keyword { kw.to_xml(builder) } }
|
541
638
|
validity&.to_xml builder
|
542
|
-
if block_given?
|
543
|
-
|
639
|
+
if block_given? then yield builder
|
640
|
+
elsif opts[:bibdata] && (doctype || editorialgroup || ics&.any? ||
|
641
|
+
structuredidentifier&.presence?)
|
642
|
+
builder.ext do |b|
|
643
|
+
b.doctype doctype if doctype
|
644
|
+
editorialgroup&.to_xml b
|
645
|
+
ics.each { |i| i.to_xml b }
|
646
|
+
structuredidentifier&.to_xml b
|
647
|
+
end
|
544
648
|
end
|
545
649
|
end
|
546
650
|
xml[:id] = id if id && !opts[:bibdata] && !opts[:embedded]
|
@@ -8,7 +8,7 @@ module RelatonBib
|
|
8
8
|
extend Forwardable
|
9
9
|
|
10
10
|
def_delegators :@array, :<<, :[], :first, :last, :empty?, :any?, :size,
|
11
|
-
|
11
|
+
:each, :detect, :map, :length
|
12
12
|
|
13
13
|
# @param relation [Array<RelatonBib::DocumentRelation, Hash>]
|
14
14
|
# @option relation [String] :type
|
@@ -20,7 +20,7 @@ module RelatonBib
|
|
20
20
|
# RelatonBib::SourceLocalityStack>] :source_locality
|
21
21
|
# @option relation [RelatonBib::BibliographicItem, NillClass] :bibitem (nil)
|
22
22
|
def initialize(relation)
|
23
|
-
@array =
|
23
|
+
@array = relation.map { |r| r.is_a?(Hash) ? DocumentRelation.new(r) : r }
|
24
24
|
end
|
25
25
|
|
26
26
|
# @todo We don't have replace type anymore. Suppose we should update this
|