relaton-bib 1.0.1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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>
@@ -10,10 +10,13 @@ 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)
16
- if /(?<date>\w+\s\d{4})/ =~ sdate # February 2012
18
+ if sdate.is_a?(Date) then sdate
19
+ elsif /(?<date>\w+\s\d{4})/ =~ sdate # February 2012
17
20
  Date.strptime(date, "%B %Y")
18
21
  elsif /(?<date>\w+\s\d{1,2},\s\d{4})/ =~ sdate # February 11, 2012
19
22
  Date.strptime(date, "%B %d, %Y")
@@ -21,10 +24,10 @@ module RelatonBib
21
24
  Date.parse(date)
22
25
  elsif /(?<date>\d{4}-\d{2})/ =~ sdate # 2012-02
23
26
  Date.strptime date, "%Y-%m"
24
- elsif /(?<date>\d{4})/ =~ sdate # 2012
25
- Date.strptime date, "%Y"
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[0].is_a?(String) ? array[0] : array[0].to_hash
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
 
@@ -83,7 +80,7 @@ module RelatonBib
83
80
  # @return [RelatonBib::DocumentStatus, NilClass]
84
81
  attr_reader :status
85
82
 
86
- # @return [RelatonBib::CopyrightAssociation, NilClass]
83
+ # @return [Array<RelatonBib::CopyrightAssociation>]
87
84
  attr_reader :copyright
88
85
 
89
86
  # @return [RelatonBib::DocRelationCollection]
@@ -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,11 +146,16 @@ 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
- # @param copyright [Hash, RelatonBib::CopyrightAssociation, NilClass]
145
- # @option copyright [Hash, RelatonBib::ContributionInfo] :owner
146
- # @option copyright [String] :form
154
+ # @param copyright [Array<Hash, RelatonBib::CopyrightAssociation>]
155
+ # @option copyright [Array<Hash, RelatonBib::ContributionInfo>] :owner
156
+ # @option copyright [String] :from
147
157
  # @option copyright [String, NilClass] :to
158
+ # @option copyright [String, NilClass] :scope
148
159
  #
149
160
  # @param date [Array<Hash>]
150
161
  # @option date [String] :type
@@ -202,11 +213,8 @@ module RelatonBib
202
213
  a.is_a?(Hash) ? FormattedString.new(a) : a
203
214
  end
204
215
 
205
- if args[:copyright]
206
- @copyright = if args[:copyright].is_a?(Hash)
207
- CopyrightAssociation.new args[:copyright]
208
- else args[:copyright]
209
- end
216
+ @copyright = args.fetch(:copyright, []).map do |c|
217
+ c.is_a?(Hash) ? CopyrightAssociation.new(c) : c
210
218
  end
211
219
 
212
220
  @docidentifier = args[:docid] || []
@@ -237,6 +245,10 @@ module RelatonBib
237
245
  @fetched = args.fetch :fetched, nil # , Date.today # we should pass the fetched arg from scrappers
238
246
  @keyword = (args[:keyword] || []).map { |kw| LocalizedString.new(kw) }
239
247
  @license = args.fetch :license, []
248
+ @doctype = args[:doctype]
249
+ @editorialgroup = args[:editorialgroup]
250
+ @ics = args.fetch :ics, []
251
+ @structuredidentifier = args[:structuredidentifier]
240
252
  end
241
253
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
242
254
  # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
@@ -288,6 +300,8 @@ module RelatonBib
288
300
  end
289
301
  end
290
302
 
303
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
304
+
291
305
  # @return [Hash]
292
306
  def to_hash
293
307
  hash = {}
@@ -308,7 +322,7 @@ module RelatonBib
308
322
  hash["formattedref"] = formattedref.to_hash if formattedref
309
323
  hash["abstract"] = single_element_array(abstract) if abstract&.any?
310
324
  hash["docstatus"] = status.to_hash if status
311
- hash["copyright"] = copyright.to_hash if copyright
325
+ hash["copyright"] = single_element_array(copyright) if copyright&.any?
312
326
  hash["relation"] = single_element_array(relation) if relation&.any?
313
327
  hash["series"] = single_element_array(series) if series&.any?
314
328
  hash["medium"] = medium.to_hash if medium
@@ -320,8 +334,15 @@ module RelatonBib
320
334
  hash["fetched"] = fetched.to_s if fetched
321
335
  hash["keyword"] = single_element_array(keyword) if keyword&.any?
322
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
323
343
  hash
324
344
  end
345
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
325
346
 
326
347
  # @param bibtex [BibTeX::Bibliography, NilClass]
327
348
  # @return [String]
@@ -348,6 +369,74 @@ module RelatonBib
348
369
  bibtex << item
349
370
  bibtex.to_s
350
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
351
440
 
352
441
  # If revision_date exists then returns it else returns published date or nil
353
442
  # @return [String, NilClass]
@@ -378,6 +467,8 @@ module RelatonBib
378
467
  end
379
468
  end
380
469
 
470
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
471
+
381
472
  # @param [BibTeX::Entry]
382
473
  def bibtex_author(item)
383
474
  authors = contributor.select do |c|
@@ -388,7 +479,7 @@ module RelatonBib
388
479
 
389
480
  item.author = authors.map do |a|
390
481
  if a.name.surname
391
- "#{a.name.surname}, #{a.name.forename.map(&:to_s).join(" ")}"
482
+ "#{a.name.surname}, #{a.name.forename.map(&:to_s).join(' ')}"
392
483
  else
393
484
  a.name.completename.to_s
394
485
  end
@@ -410,6 +501,7 @@ module RelatonBib
410
501
  end
411
502
  end
412
503
  end
504
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
413
505
 
414
506
  # @param [BibTeX::Entry]
415
507
  def bibtex_note(item)
@@ -427,7 +519,10 @@ module RelatonBib
427
519
  # @param [BibTeX::Entry]
428
520
  def bibtex_relation(item)
429
521
  rel = relation.detect { |r| r.type == "partOf" }
430
- item.booktitle = rel.bibitem.title.detect { |t| t.type == "main" }.title.content if rel
522
+ if rel
523
+ title_main = rel.bibitem.title.detect { |t| t.type == "main" }
524
+ item.booktitle = title_main.title.content
525
+ end
431
526
  end
432
527
 
433
528
  # @param [BibTeX::Entry]
@@ -530,7 +625,7 @@ module RelatonBib
530
625
  script.each { |s| builder.script s }
531
626
  abstract.each { |a| builder.abstract { a.to_xml(builder) } }
532
627
  status&.to_xml builder
533
- copyright&.to_xml builder
628
+ copyright&.each { |c| c.to_xml builder }
534
629
  relation.each { |r| r.to_xml builder, **opts }
535
630
  series.each { |s| s.to_xml builder }
536
631
  medium&.to_xml builder
@@ -541,8 +636,15 @@ module RelatonBib
541
636
  classification.each { |cls| cls.to_xml builder }
542
637
  keyword.each { |kw| builder.keyword { kw.to_xml(builder) } }
543
638
  validity&.to_xml builder
544
- if block_given?
545
- yield builder
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
546
648
  end
547
649
  end
548
650
  xml[:id] = id if id && !opts[:bibdata] && !opts[:embedded]