relaton-bib 1.20.7 → 2.0.0.pre.alpha.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/.rubocop.yml +1 -1
- data/README.adoc +183 -154
- data/bin/console +1 -1
- data/grammars/basicdoc.rng +1516 -645
- data/grammars/biblio-standoc.rng +100 -20
- data/grammars/biblio.rng +959 -356
- data/grammars/versions.json +10 -10
- data/lib/relaton/bib/hash_parser_v1.rb +711 -0
- data/lib/relaton/bib/item_data.rb +168 -0
- data/lib/relaton/bib/model/address.rb +22 -0
- data/lib/relaton/bib/model/affiliation.rb +16 -0
- data/lib/relaton/bib/model/bibdata.rb +24 -0
- data/lib/relaton/bib/model/bibitem.rb +23 -0
- data/lib/relaton/bib/model/contact.rb +18 -0
- data/lib/relaton/bib/model/contribution_info.rb +16 -0
- data/lib/relaton/bib/model/contributor.rb +71 -0
- data/lib/relaton/bib/model/copyright.rb +27 -0
- data/lib/relaton/bib/model/date.rb +29 -0
- data/lib/relaton/bib/model/depiction.rb +14 -0
- data/lib/relaton/bib/model/docidentifier.rb +33 -0
- data/lib/relaton/bib/model/doctype.rb +14 -0
- data/lib/relaton/bib/model/edition.rb +14 -0
- data/lib/relaton/bib/model/editorial_group.rb +14 -0
- data/lib/relaton/bib/model/ext.rb +29 -0
- data/lib/relaton/bib/model/extent.rb +16 -0
- data/lib/relaton/bib/model/full_name_type.rb +64 -0
- data/lib/relaton/bib/model/fullname.rb +11 -0
- data/lib/relaton/bib/model/ics.rb +14 -0
- data/lib/relaton/bib/model/image.rb +28 -0
- data/lib/relaton/bib/model/item.rb +129 -0
- data/lib/relaton/bib/model/item_base.rb +19 -0
- data/lib/relaton/bib/model/keyword.rb +30 -0
- data/lib/relaton/bib/model/locality.rb +18 -0
- data/lib/relaton/bib/model/locality_stack.rb +14 -0
- data/lib/relaton/bib/model/localized_string.rb +57 -0
- data/lib/relaton/bib/model/localized_string_attrs.rb +24 -0
- data/lib/relaton/bib/model/logo.rb +12 -0
- data/lib/relaton/bib/model/medium.rb +22 -0
- data/lib/relaton/bib/model/note.rb +16 -0
- data/lib/relaton/bib/model/organization.rb +13 -0
- data/lib/relaton/bib/model/organization_type.rb +42 -0
- data/lib/relaton/bib/model/person.rb +36 -0
- data/lib/relaton/bib/model/phone.rb +14 -0
- data/lib/relaton/bib/model/place.rb +33 -0
- data/lib/relaton/bib/model/price.rb +14 -0
- data/lib/relaton/bib/model/relation.rb +43 -0
- data/lib/relaton/bib/model/series.rb +32 -0
- data/lib/relaton/bib/model/size.rb +23 -0
- data/lib/relaton/bib/model/source_locality_stack.rb +14 -0
- data/lib/relaton/bib/model/status.rb +27 -0
- data/lib/relaton/bib/model/structured_identifier.rb +48 -0
- data/lib/relaton/bib/model/subdivision.rb +14 -0
- data/lib/relaton/bib/model/technical_committee.rb +14 -0
- data/lib/relaton/bib/model/title.rb +18 -0
- data/lib/relaton/bib/model/uri.rb +18 -0
- data/lib/relaton/bib/model/validity.rb +16 -0
- data/lib/relaton/bib/model/version.rb +14 -0
- data/lib/relaton/bib/model/workgroup.rb +20 -0
- data/lib/relaton/bib/parser/rfc_address.rb +60 -0
- data/lib/relaton/bib/parser/rfc_contacts.rb +35 -0
- data/lib/relaton/bib/parser/rfc_docidentifier.rb +70 -0
- data/lib/relaton/bib/parser/rfc_organization.rb +31 -0
- data/lib/relaton/bib/parser/rfc_person.rb +42 -0
- data/lib/relaton/bib/parser/rfc_reference.rb +143 -0
- data/lib/relaton/bib/parser/rfc_referencegroup.rb +45 -0
- data/lib/relaton/bib/parser/rfc_shared.rb +23 -0
- data/lib/relaton/bib/renderer/bibtex_builder.rb +348 -0
- data/lib/relaton/bib/renderer/rfc.rb +297 -0
- data/lib/relaton/bib/util.rb +18 -0
- data/lib/relaton/bib/version.rb +5 -0
- data/lib/{relaton_bib.rb → relaton/bib.rb} +47 -36
- data/lib/{relaton_bib → relaton}/bibtex_parser.rb +24 -27
- data/lib/{relaton_bib → relaton}/bibxml_parser.rb +43 -46
- data/lib/{relaton_bib → relaton}/hit.rb +3 -3
- data/lib/{relaton_bib → relaton}/hit_collection.rb +2 -2
- data/lib/{relaton_bib → relaton}/workers_pool.rb +1 -1
- data/lib/{relaton_bib → relaton}/xml_parser.rb +49 -51
- data/relaton-bib.gemspec +8 -8
- metadata +95 -74
- data/lib/relaton_bib/bib_item_locality.rb +0 -175
- data/lib/relaton_bib/biblio_note.rb +0 -72
- data/lib/relaton_bib/biblio_version.rb +0 -46
- data/lib/relaton_bib/bibliographic_date.rb +0 -119
- data/lib/relaton_bib/bibliographic_item.rb +0 -668
- data/lib/relaton_bib/bibliographic_size.rb +0 -103
- data/lib/relaton_bib/classification.rb +0 -40
- data/lib/relaton_bib/config.rb +0 -16
- data/lib/relaton_bib/contribution_info.rb +0 -117
- data/lib/relaton_bib/contributor.rb +0 -277
- data/lib/relaton_bib/copyright_association.rb +0 -79
- data/lib/relaton_bib/document_identifier.rb +0 -118
- data/lib/relaton_bib/document_relation.rb +0 -95
- data/lib/relaton_bib/document_relation_collection.rb +0 -57
- data/lib/relaton_bib/document_status.rb +0 -92
- data/lib/relaton_bib/document_type.rb +0 -52
- data/lib/relaton_bib/edition.rb +0 -55
- data/lib/relaton_bib/editorial_group.rb +0 -41
- data/lib/relaton_bib/extent.rb +0 -39
- data/lib/relaton_bib/forename.rb +0 -65
- data/lib/relaton_bib/formatted_ref.rb +0 -17
- data/lib/relaton_bib/formatted_string.rb +0 -133
- data/lib/relaton_bib/full_name.rb +0 -108
- data/lib/relaton_bib/hash_converter.rb +0 -568
- data/lib/relaton_bib/ics.rb +0 -42
- data/lib/relaton_bib/image.rb +0 -95
- data/lib/relaton_bib/localized_string.rb +0 -149
- data/lib/relaton_bib/medium.rb +0 -76
- data/lib/relaton_bib/organization.rb +0 -165
- data/lib/relaton_bib/person.rb +0 -129
- data/lib/relaton_bib/place.rb +0 -203
- data/lib/relaton_bib/renderer/bibtex_builder.rb +0 -312
- data/lib/relaton_bib/renderer/bibxml.rb +0 -296
- data/lib/relaton_bib/series.rb +0 -119
- data/lib/relaton_bib/structured_identifier.rb +0 -173
- data/lib/relaton_bib/technical_committee.rb +0 -34
- data/lib/relaton_bib/typed_title_string.rb +0 -191
- data/lib/relaton_bib/typed_uri.rb +0 -57
- data/lib/relaton_bib/util.rb +0 -16
- data/lib/relaton_bib/validity.rb +0 -52
- data/lib/relaton_bib/version.rb +0 -3
- data/lib/relaton_bib/workgroup.rb +0 -58
- /data/lib/{relaton_bib → relaton}/deep_dup.rb +0 -0
@@ -1,668 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "relaton_bib/typed_uri"
|
4
|
-
require "relaton_bib/document_identifier"
|
5
|
-
require "relaton_bib/copyright_association"
|
6
|
-
require "relaton_bib/formatted_string"
|
7
|
-
require "relaton_bib/contribution_info"
|
8
|
-
require "relaton_bib/bibliographic_date"
|
9
|
-
require "relaton_bib/series"
|
10
|
-
require "relaton_bib/document_status"
|
11
|
-
require "relaton_bib/organization"
|
12
|
-
require "relaton_bib/document_relation_collection"
|
13
|
-
require "relaton_bib/typed_title_string"
|
14
|
-
require "relaton_bib/formatted_ref"
|
15
|
-
require "relaton_bib/medium"
|
16
|
-
require "relaton_bib/classification"
|
17
|
-
require "relaton_bib/validity"
|
18
|
-
require "relaton_bib/document_relation"
|
19
|
-
require "relaton_bib/bib_item_locality"
|
20
|
-
require_relative "extent"
|
21
|
-
require "relaton_bib/xml_parser"
|
22
|
-
require "relaton_bib/bibtex_parser"
|
23
|
-
require "relaton_bib/biblio_note"
|
24
|
-
require "relaton_bib/biblio_version"
|
25
|
-
require "relaton_bib/workers_pool"
|
26
|
-
require "relaton_bib/hash_converter"
|
27
|
-
require "relaton_bib/place"
|
28
|
-
require "relaton_bib/structured_identifier"
|
29
|
-
require "relaton_bib/editorial_group"
|
30
|
-
require "relaton_bib/ics"
|
31
|
-
require "relaton_bib/bibliographic_size"
|
32
|
-
require "relaton_bib/edition"
|
33
|
-
|
34
|
-
module RelatonBib
|
35
|
-
# Bibliographic item
|
36
|
-
class BibliographicItem
|
37
|
-
include RelatonBib
|
38
|
-
|
39
|
-
TYPES = %W[article book booklet manual proceedings presentation
|
40
|
-
thesis techreport standard unpublished map electronic\sresource
|
41
|
-
audiovisual film video broadcast software graphic_work music
|
42
|
-
patent inbook incollection inproceedings journal website
|
43
|
-
webresource dataset archival social_media alert message
|
44
|
-
conversation collection misc internal].freeze # internal is defined in isodoc grammar
|
45
|
-
|
46
|
-
# @return [Boolean, nil]
|
47
|
-
attr_accessor :all_parts
|
48
|
-
|
49
|
-
# @return [String, nil]
|
50
|
-
attr_reader :id, :type, :docnumber, :subdoctype
|
51
|
-
|
52
|
-
# @return [RelatonBib::DocumentType] document type
|
53
|
-
attr_reader :doctype
|
54
|
-
|
55
|
-
# @return [RelatonBib::Edition, nil] edition
|
56
|
-
attr_reader :edition
|
57
|
-
|
58
|
-
# @!attribute [r] title
|
59
|
-
# @return [RelatonBib::TypedTitleStringCollection]
|
60
|
-
|
61
|
-
# @return [Array<RelatonBib::TypedUri>]
|
62
|
-
attr_reader :link
|
63
|
-
|
64
|
-
# @return [Array<RelatonBib::DocumentIdentifier>]
|
65
|
-
attr_reader :docidentifier
|
66
|
-
|
67
|
-
# @return [Array<RelatonBib::BibliographicDate>]
|
68
|
-
attr_writer :date
|
69
|
-
|
70
|
-
# @return [Array<RelatonBib::ContributionInfo>]
|
71
|
-
attr_reader :contributor
|
72
|
-
|
73
|
-
# @return [Array<RelatonBib::BibliographicItem::Version>]
|
74
|
-
attr_reader :version
|
75
|
-
|
76
|
-
# @return [RelatonBib::BiblioNoteCollection]
|
77
|
-
attr_reader :biblionote
|
78
|
-
|
79
|
-
# @return [Array<String>] language Iso639 code
|
80
|
-
attr_reader :language
|
81
|
-
|
82
|
-
# @return [Array<String>] script Iso15924 code
|
83
|
-
attr_reader :script
|
84
|
-
|
85
|
-
# @return [RelatonBib::FormattedRef, nil]
|
86
|
-
attr_reader :formattedref
|
87
|
-
|
88
|
-
# @!attribute [r] abstract
|
89
|
-
# @return [Array<RelatonBib::FormattedString>]
|
90
|
-
|
91
|
-
# @return [RelatonBib::DocumentStatus, nil]
|
92
|
-
attr_reader :status
|
93
|
-
|
94
|
-
# @return [Array<RelatonBib::CopyrightAssociation>]
|
95
|
-
attr_reader :copyright
|
96
|
-
|
97
|
-
# @return [RelatonBib::DocRelationCollection]
|
98
|
-
attr_reader :relation
|
99
|
-
|
100
|
-
# @return [Array<RelatonBib::Series>]
|
101
|
-
attr_reader :series
|
102
|
-
|
103
|
-
# @return [RelatonBib::Medium, nil]
|
104
|
-
attr_reader :medium
|
105
|
-
|
106
|
-
# @return [Array<RelatonBib::Place>]
|
107
|
-
attr_reader :place
|
108
|
-
|
109
|
-
# @return [Array<RelatonBib::Extent>]
|
110
|
-
attr_reader :extent
|
111
|
-
|
112
|
-
# @return [Array<Strig>]
|
113
|
-
attr_reader :accesslocation, :license
|
114
|
-
|
115
|
-
# @return [Array<Relaton::Classification>]
|
116
|
-
attr_reader :classification
|
117
|
-
|
118
|
-
# @return [RelatonBib:Validity, nil]
|
119
|
-
attr_reader :validity
|
120
|
-
|
121
|
-
# @return [Date]
|
122
|
-
attr_accessor :fetched
|
123
|
-
|
124
|
-
# @return [Array<RelatonBib::LocalizedString>]
|
125
|
-
attr_reader :keyword
|
126
|
-
|
127
|
-
# @return [RelatonBib::EditorialGroup, nil]
|
128
|
-
attr_reader :editorialgroup
|
129
|
-
|
130
|
-
# @return [Array<RelatonBib:ICS>]
|
131
|
-
attr_reader :ics
|
132
|
-
|
133
|
-
# @return [RelatonBib::StructuredIdentifierCollection]
|
134
|
-
attr_reader :structuredidentifier
|
135
|
-
|
136
|
-
# @return [RelatonBib::BibliographicSize, nil]
|
137
|
-
attr_reader :size
|
138
|
-
|
139
|
-
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
140
|
-
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
141
|
-
|
142
|
-
# @param id [String, nil]
|
143
|
-
# @param title [RelatonBib::TypedTitleStringCollection,
|
144
|
-
# Array<Hash, RelatonBib::TypedTitleString>]
|
145
|
-
# @param formattedref [RelatonBib::FormattedRef, nil]
|
146
|
-
# @param type [String, nil]
|
147
|
-
# @param docid [Array<RelatonBib::DocumentIdentifier>]
|
148
|
-
# @param docnumber [String, nil]
|
149
|
-
# @param language [Arra<String>]
|
150
|
-
# @param script [Array<String>]
|
151
|
-
# @param docstatus [RelatonBib::DocumentStatus, nil]
|
152
|
-
# @param edition [RelatonBib::Edition, String, Integer, Float, nil]
|
153
|
-
# @param version [Array<RelatonBib::BibliographicItem::Version>]
|
154
|
-
# @param biblionote [RelatonBib::BiblioNoteCollection]
|
155
|
-
# @param series [Array<RelatonBib::Series>]
|
156
|
-
# @param medium [RelatonBib::Medium, nil]
|
157
|
-
# @param place [Array<String, RelatonBib::Place>]
|
158
|
-
# @param extent [Array<RelatonBib::Extent>]
|
159
|
-
# @param accesslocation [Array<String>]
|
160
|
-
# @param classification [Array<RelatonBib::Classification>]
|
161
|
-
# @param validity [RelatonBib:Validity, nil]
|
162
|
-
# @param fetched [Date, nil] default nil
|
163
|
-
# @param keyword [Array<String>]
|
164
|
-
# @param doctype [RelatonBib::DocumentType]
|
165
|
-
# @param subdoctype [String]
|
166
|
-
# @param editorialgroup [RelatonBib::EditorialGroup, nil]
|
167
|
-
# @param ics [Array<RelatonBib::ICS>]
|
168
|
-
# @param structuredidentifier [RelatonBib::StructuredIdentifierCollection]
|
169
|
-
# @param size [RelatonBib::BibliographicSize, nil]
|
170
|
-
#
|
171
|
-
# @param copyright [Array<Hash, RelatonBib::CopyrightAssociation>]
|
172
|
-
# @option copyright [Array<Hash, RelatonBib::ContributionInfo>] :owner
|
173
|
-
# @option copyright [String] :from
|
174
|
-
# @option copyright [String, nil] :to
|
175
|
-
# @option copyright [String, nil] :scope
|
176
|
-
#
|
177
|
-
# @param date [Array<Hash, RelatonBib::BibliographicDate>]
|
178
|
-
# @option date [String] :type
|
179
|
-
# @option date [String, nil] :from required if :on is nil
|
180
|
-
# @option date [String, nil] :to
|
181
|
-
# @option date [String, nil] :on required if :from is nil
|
182
|
-
#
|
183
|
-
# @param contributor [Array<Hash, RelatonBib::ContributionInfo>]
|
184
|
-
# @option contributor [RealtonBib::Organization, RelatonBib::Person] :entity
|
185
|
-
# @option contributor [String] :type
|
186
|
-
# @option contributor [String] :from
|
187
|
-
# @option contributor [String] :to
|
188
|
-
# @option contributor [String] :abbreviation
|
189
|
-
# @option contributor [Array<Array<String,Array<String>>>] :role
|
190
|
-
#
|
191
|
-
# @param abstract [Array<Hash, RelatonBib::FormattedString>]
|
192
|
-
# @option abstract [String] :content
|
193
|
-
# @option abstract [String] :language
|
194
|
-
# @option abstract [String] :script
|
195
|
-
# @option abstract [String] :format
|
196
|
-
#
|
197
|
-
# @param relation [Array<Hash>]
|
198
|
-
# @option relation [String] :type
|
199
|
-
# @option relation [RelatonBib::BibliographicItem,
|
200
|
-
# RelatonIso::IsoBibliographicItem] :bibitem
|
201
|
-
# @option relation [Array<RelatonBib::Locality,
|
202
|
-
# RelatonBib::LocalityStack>] :locality
|
203
|
-
# @option relation [Array<RelatonBib::SourceLocality,
|
204
|
-
# RelatonBib::SourceLocalityStack>] :source_locality
|
205
|
-
#
|
206
|
-
# @param link [Array<Hash, RelatonBib::TypedUri>]
|
207
|
-
# @option link [String] :type
|
208
|
-
# @option link [String] :content
|
209
|
-
def initialize(**args)
|
210
|
-
if args[:type] && !TYPES.include?(args[:type])
|
211
|
-
Util.warn %{Type `#{args[:type]}` is invalid.}
|
212
|
-
end
|
213
|
-
|
214
|
-
@title = if args[:title].is_a?(TypedTitleStringCollection)
|
215
|
-
args[:title]
|
216
|
-
else
|
217
|
-
TypedTitleStringCollection.new(args[:title])
|
218
|
-
end
|
219
|
-
|
220
|
-
@date = (args[:date] || []).map do |d|
|
221
|
-
d.is_a?(Hash) ? BibliographicDate.new(**d) : d
|
222
|
-
end
|
223
|
-
|
224
|
-
@contributor = (args[:contributor] || []).map do |c|
|
225
|
-
if c.is_a? Hash
|
226
|
-
e = c[:entity].is_a?(Hash) ? Organization.new(**c[:entity]) : c[:entity]
|
227
|
-
ContributionInfo.new(entity: e, role: c[:role])
|
228
|
-
else c
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
@abstract = (args[:abstract] || []).map do |a|
|
233
|
-
a.is_a?(Hash) ? FormattedString.new(**a) : a
|
234
|
-
end
|
235
|
-
|
236
|
-
@copyright = (args[:copyright] || []).map do |c|
|
237
|
-
c.is_a?(Hash) ? CopyrightAssociation.new(**c) : c
|
238
|
-
end
|
239
|
-
|
240
|
-
@docidentifier = args[:docid] || []
|
241
|
-
@formattedref = args[:formattedref] if title.empty?
|
242
|
-
@id = args[:id] || makeid(nil, false)
|
243
|
-
@type = args[:type]
|
244
|
-
@docnumber = args[:docnumber]
|
245
|
-
@edition = case args[:edition]
|
246
|
-
when Hash then Edition.new(**args[:edition])
|
247
|
-
when String, Integer, Float
|
248
|
-
Edition.new(content: args[:edition].to_s)
|
249
|
-
when Edition then args[:edition]
|
250
|
-
end
|
251
|
-
@version = args[:version] || []
|
252
|
-
@biblionote = args[:biblionote] || BiblioNoteCollection.new([])
|
253
|
-
@language = args[:language] || []
|
254
|
-
@script = args[:script] || []
|
255
|
-
@status = args[:docstatus]
|
256
|
-
@relation = DocRelationCollection.new(args[:relation] || [])
|
257
|
-
@link = (args[:link] || []).map do |s|
|
258
|
-
case s
|
259
|
-
when Hash then TypedUri.new(**s)
|
260
|
-
when String then TypedUri.new(content: s)
|
261
|
-
else s
|
262
|
-
end
|
263
|
-
end
|
264
|
-
@series = args[:series] || []
|
265
|
-
@medium = args[:medium]
|
266
|
-
@place = (args[:place] || []).map do |pl|
|
267
|
-
pl.is_a?(String) ? Place.new(name: pl) : pl
|
268
|
-
end
|
269
|
-
@extent = args[:extent] || []
|
270
|
-
@size = args[:size]
|
271
|
-
@accesslocation = args[:accesslocation] || []
|
272
|
-
@classification = args[:classification] || []
|
273
|
-
@validity = args[:validity]
|
274
|
-
# we should pass the fetched arg from scrappers
|
275
|
-
@fetched = args[:fetched]
|
276
|
-
@keyword = (args[:keyword] || []).map do |kw|
|
277
|
-
case kw
|
278
|
-
when Hash then LocalizedString.new(kw[:content], kw[:language], kw[:script])
|
279
|
-
when String then LocalizedString.new(kw)
|
280
|
-
else kw
|
281
|
-
end
|
282
|
-
end
|
283
|
-
@license = args[:license] || []
|
284
|
-
@doctype = args[:doctype]
|
285
|
-
@subdoctype = args[:subdoctype]
|
286
|
-
@editorialgroup = args[:editorialgroup]
|
287
|
-
@ics = args[:ics] || []
|
288
|
-
@structuredidentifier = args[:structuredidentifier]
|
289
|
-
end
|
290
|
-
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
291
|
-
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
292
|
-
|
293
|
-
#
|
294
|
-
# Fetch schema version
|
295
|
-
#
|
296
|
-
# @return [String] schema version
|
297
|
-
#
|
298
|
-
def schema
|
299
|
-
@schema ||= schema_versions["relaton-models"]
|
300
|
-
end
|
301
|
-
|
302
|
-
#
|
303
|
-
# Read schema versions from file
|
304
|
-
#
|
305
|
-
# @return [Hash{String=>String}] schema versions
|
306
|
-
#
|
307
|
-
def schema_versions
|
308
|
-
JSON.parse File.read(File.join(__dir__, "../../grammars/versions.json"))
|
309
|
-
end
|
310
|
-
|
311
|
-
# @param hash [Hash]
|
312
|
-
# @return [RelatonBipm::BipmBibliographicItem]
|
313
|
-
def self.from_hash(hash)
|
314
|
-
item_hash = Object.const_get(name.split("::")[0])::HashConverter.hash_to_bib(hash)
|
315
|
-
new(**item_hash)
|
316
|
-
end
|
317
|
-
|
318
|
-
#
|
319
|
-
# @param [String, nil] type if nil return all dates else return dates with type
|
320
|
-
#
|
321
|
-
# @return [Array<RelatonBib::BibliographicDate>]
|
322
|
-
#
|
323
|
-
def date(type: nil)
|
324
|
-
type ? @date.select { |d| d.type == type } : @date
|
325
|
-
end
|
326
|
-
|
327
|
-
# @param lang [String] language code Iso639
|
328
|
-
# @return [RelatonBib::FormattedString, Array<RelatonBib::FormattedString>]
|
329
|
-
def abstract(lang: nil)
|
330
|
-
if lang
|
331
|
-
@abstract.detect { |a| a.language&.include? lang }
|
332
|
-
else
|
333
|
-
@abstract
|
334
|
-
end
|
335
|
-
end
|
336
|
-
|
337
|
-
# @param identifier [RelatonBib::DocumentIdentifier, nil]
|
338
|
-
# @param attribute [Boolean, nil]
|
339
|
-
# @return [String]
|
340
|
-
def makeid(identifier, attribute)
|
341
|
-
return nil if attribute && !@id_attribute
|
342
|
-
|
343
|
-
identifier ||= @docidentifier.reject { |i| i.type == "DOI" }[0]
|
344
|
-
return unless identifier
|
345
|
-
|
346
|
-
idstr = identifier.id.gsub(/[:\/]/, "-").gsub(/[\s\(\)]/, "")
|
347
|
-
idstr.strip
|
348
|
-
end
|
349
|
-
|
350
|
-
# @param identifier [RelatonBib::DocumentIdentifier]
|
351
|
-
# @param options [Hash]
|
352
|
-
# @option options [boolean, nil] :no_year
|
353
|
-
# @option options [boolean, nil] :all_parts
|
354
|
-
# @return [String]
|
355
|
-
def shortref(identifier, **opts) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize,Metrics/PerceivedComplexity
|
356
|
-
pubdate = date.select { |d| d.type == "published" || d.type == "issued" }
|
357
|
-
year = if opts[:no_year] || pubdate.empty? then ""
|
358
|
-
else ":#{pubdate&.first&.on(:year)}"
|
359
|
-
end
|
360
|
-
year += ": All Parts" if opts[:all_parts] || @all_parts
|
361
|
-
|
362
|
-
"#{makeid(identifier, false)}#{year}"
|
363
|
-
end
|
364
|
-
|
365
|
-
# @param opts [Hash]
|
366
|
-
# @option opts [Nokogiri::XML::Builder] :builder XML builder
|
367
|
-
# @option opts [Boolean] :bibdata
|
368
|
-
# @option opts [Symbol, nil] :date_format (:short), :full
|
369
|
-
# @option opts [String, Symbol] :lang language
|
370
|
-
# @return [String] XML
|
371
|
-
def to_xml(**opts, &block)
|
372
|
-
if opts[:builder]
|
373
|
-
render_xml(**opts, &block)
|
374
|
-
else
|
375
|
-
Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
|
376
|
-
render_xml builder: xml, **opts, &block
|
377
|
-
end.doc.root.to_xml
|
378
|
-
end
|
379
|
-
end
|
380
|
-
|
381
|
-
#
|
382
|
-
# Render BibXML (RFC)
|
383
|
-
#
|
384
|
-
# @param [Nokogiri::XML::Builder, nil] builder
|
385
|
-
# @param [Boolean] include_keywords (false)
|
386
|
-
#
|
387
|
-
# @return [String, Nokogiri::XML::Builder::NodeBuilder] XML
|
388
|
-
#
|
389
|
-
def to_bibxml(builder = nil, include_keywords: false)
|
390
|
-
Renderer::BibXML.new(self).render builder: builder, include_keywords: include_keywords
|
391
|
-
end
|
392
|
-
|
393
|
-
# @return [Hash]
|
394
|
-
def to_hash(embedded: false) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
395
|
-
hash = {}
|
396
|
-
hash["schema-version"] = schema unless embedded
|
397
|
-
hash["id"] = id if id
|
398
|
-
hash["title"] = title.to_hash if title&.any?
|
399
|
-
hash["link"] = single_element_array(link) if link&.any?
|
400
|
-
hash["type"] = type if type
|
401
|
-
hash["docid"] = single_element_array(docidentifier) if docidentifier&.any?
|
402
|
-
hash["docnumber"] = docnumber if docnumber
|
403
|
-
hash["date"] = single_element_array(date) if date&.any?
|
404
|
-
if contributor&.any?
|
405
|
-
hash["contributor"] = single_element_array(contributor)
|
406
|
-
end
|
407
|
-
hash["edition"] = edition.to_hash if edition
|
408
|
-
hash["version"] = version.map &:to_hash if version.any?
|
409
|
-
hash["revdate"] = revdate if revdate
|
410
|
-
hash["biblionote"] = single_element_array(biblionote) if biblionote&.any?
|
411
|
-
hash["language"] = single_element_array(language) if language&.any?
|
412
|
-
hash["script"] = single_element_array(script) if script&.any?
|
413
|
-
hash["formattedref"] = formattedref.to_hash if formattedref
|
414
|
-
hash["abstract"] = single_element_array(abstract) if abstract&.any?
|
415
|
-
hash["docstatus"] = status.to_hash if status
|
416
|
-
hash["copyright"] = single_element_array(copyright) if copyright&.any?
|
417
|
-
hash["relation"] = single_element_array(relation) if relation&.any?
|
418
|
-
hash["series"] = single_element_array(series) if series&.any?
|
419
|
-
hash["medium"] = medium.to_hash if medium
|
420
|
-
hash["place"] = single_element_array(place) if place&.any?
|
421
|
-
hash["extent"] = extent.map(&:to_hash) if extent&.any?
|
422
|
-
hash["size"] = size.to_hash if size&.any?
|
423
|
-
if accesslocation&.any?
|
424
|
-
hash["accesslocation"] = single_element_array(accesslocation)
|
425
|
-
end
|
426
|
-
if classification&.any?
|
427
|
-
hash["classification"] = single_element_array(classification)
|
428
|
-
end
|
429
|
-
hash["validity"] = validity.to_hash if validity
|
430
|
-
hash["fetched"] = fetched.to_s if fetched
|
431
|
-
hash["keyword"] = single_element_array(keyword) if keyword&.any?
|
432
|
-
hash["license"] = single_element_array(license) if license&.any?
|
433
|
-
if has_ext?
|
434
|
-
hash["ext"] = {}
|
435
|
-
hash["ext"]["schema-version"] = ext_schema if !embedded && respond_to?(:ext_schema) && ext_schema
|
436
|
-
hash["ext"]["doctype"] = doctype.to_hash if doctype
|
437
|
-
hash["ext"]["subdoctype"] = subdoctype if subdoctype
|
438
|
-
hash["ext"]["editorialgroup"] = editorialgroup.to_hash if editorialgroup&.presence?
|
439
|
-
hash["ext"]["ics"] = single_element_array ics if ics.any?
|
440
|
-
hash["ext"]["structuredidentifier"] = structuredidentifier.to_hash if structuredidentifier&.presence?
|
441
|
-
end
|
442
|
-
hash
|
443
|
-
end
|
444
|
-
|
445
|
-
#
|
446
|
-
# Reander BibTeX
|
447
|
-
#
|
448
|
-
# @param bibtex [BibTeX::Bibliography, nil]
|
449
|
-
#
|
450
|
-
# @return [String]
|
451
|
-
#
|
452
|
-
def to_bibtex(bibtex = nil)
|
453
|
-
Renderer::BibtexBuilder.build(self, bibtex).to_s
|
454
|
-
end
|
455
|
-
|
456
|
-
#
|
457
|
-
# Render citeproc
|
458
|
-
#
|
459
|
-
# @param bibtex [BibTeX::Bibliography, nil]
|
460
|
-
#
|
461
|
-
# @return [Hash] citeproc
|
462
|
-
#
|
463
|
-
def to_citeproc(bibtex = nil)
|
464
|
-
Renderer::BibtexBuilder.build(self, bibtex).to_citeproc.map do |cp|
|
465
|
-
cp.transform_keys(&:to_s)
|
466
|
-
end
|
467
|
-
end
|
468
|
-
|
469
|
-
# @param lang [String, nil] language code Iso639
|
470
|
-
# @return [RelatonIsoBib::TypedTitleStringCollection]
|
471
|
-
def title(lang: nil)
|
472
|
-
@title.lang lang
|
473
|
-
end
|
474
|
-
|
475
|
-
# @param type [Symbol] type of url, can be :src/:obp/:rss
|
476
|
-
# @return [String, nil]
|
477
|
-
def url(type = :src)
|
478
|
-
@link.detect { |s| s.type == type.to_s }&.content&.to_s
|
479
|
-
end
|
480
|
-
|
481
|
-
def abstract=(value)
|
482
|
-
@abstract = value
|
483
|
-
end
|
484
|
-
|
485
|
-
def deep_clone
|
486
|
-
dump = Marshal.dump self
|
487
|
-
Marshal.load dump # rubocop:disable Security/MarshalLoad
|
488
|
-
end
|
489
|
-
|
490
|
-
def disable_id_attribute
|
491
|
-
@id_attribute = false
|
492
|
-
end
|
493
|
-
|
494
|
-
# remove title part components and abstract
|
495
|
-
def to_all_parts # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
|
496
|
-
me = deep_clone
|
497
|
-
me.disable_id_attribute
|
498
|
-
me.relation << DocumentRelation.new(type: "instanceOf", bibitem: self)
|
499
|
-
me.language.each do |l|
|
500
|
-
me.title.delete_title_part!
|
501
|
-
ttl = me.title.select do |t|
|
502
|
-
t.type != "main" && t.title.language&.include?(l)
|
503
|
-
end
|
504
|
-
next if ttl.empty?
|
505
|
-
|
506
|
-
tm_en = ttl.map { |t| t.title.content }.join " – "
|
507
|
-
me.title.detect do |t|
|
508
|
-
t.type == "main" && t.title.language&.include?(l)
|
509
|
-
end&.title&.content = tm_en
|
510
|
-
end
|
511
|
-
me.abstract = []
|
512
|
-
me.docidentifier.each(&:remove_part)
|
513
|
-
me.docidentifier.each(&:all_parts)
|
514
|
-
me.structuredidentifier.remove_part
|
515
|
-
me.structuredidentifier.all_parts
|
516
|
-
me.docidentifier.each &:remove_date
|
517
|
-
me.structuredidentifier&.remove_date
|
518
|
-
me.all_parts = true
|
519
|
-
me
|
520
|
-
end
|
521
|
-
|
522
|
-
# convert ISO:yyyy reference to reference to most recent
|
523
|
-
# instance of reference, removing date-specific infomration:
|
524
|
-
# date of publication, abstracts. Make dated reference Instance relation
|
525
|
-
# of the redacated document
|
526
|
-
def to_most_recent_reference
|
527
|
-
me = deep_clone
|
528
|
-
disable_id_attribute
|
529
|
-
me.relation << DocumentRelation.new(type: "instanceOf", bibitem: self)
|
530
|
-
me.abstract = []
|
531
|
-
me.date = []
|
532
|
-
me.docidentifier.each &:remove_date
|
533
|
-
me.structuredidentifier&.remove_date
|
534
|
-
me.id&.sub!(/-[12]\d\d\d/, "")
|
535
|
-
me
|
536
|
-
end
|
537
|
-
|
538
|
-
# If revision_date exists then returns it else returns published date or nil
|
539
|
-
# @return [String, nil]
|
540
|
-
def revdate # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
541
|
-
@revdate ||= if (v = version.detect &:revision_date)
|
542
|
-
v.revision_date
|
543
|
-
else
|
544
|
-
date.detect { |d| d.type == "published" }&.on&.to_s
|
545
|
-
end
|
546
|
-
end
|
547
|
-
|
548
|
-
# @param prefix [String]
|
549
|
-
# @return [String]
|
550
|
-
def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
551
|
-
pref = prefix.empty? ? prefix : "#{prefix}."
|
552
|
-
out = prefix.empty? ? "[%bibitem]\n== {blank}\n" : ""
|
553
|
-
out += "#{pref}id:: #{id}\n" if id
|
554
|
-
out += "#{pref}fetched:: #{fetched}\n" if fetched
|
555
|
-
title.each { |t| out += t.to_asciibib(prefix, title.size) }
|
556
|
-
out += "#{pref}type:: #{type}\n" if type
|
557
|
-
docidentifier.each do |di|
|
558
|
-
out += di.to_asciibib prefix, docidentifier.size
|
559
|
-
end
|
560
|
-
out += "#{pref}docnumber:: #{docnumber}\n" if docnumber
|
561
|
-
out += edition.to_asciibib(prefix) if edition
|
562
|
-
language.each { |l| out += "#{pref}language:: #{l}\n" }
|
563
|
-
script.each { |s| out += "#{pref}script:: #{s}\n" }
|
564
|
-
version.each { |v| out += v.to_asciibib prefix, version.size }
|
565
|
-
biblionote&.each { |b| out += b.to_asciibib prefix, biblionote.size }
|
566
|
-
out += status.to_asciibib prefix if status
|
567
|
-
date.each { |d| out += d.to_asciibib prefix, date.size }
|
568
|
-
abstract.each do |a|
|
569
|
-
out += a.to_asciibib "#{pref}abstract", abstract.size
|
570
|
-
end
|
571
|
-
copyright.each { |c| out += c.to_asciibib prefix, copyright.size }
|
572
|
-
link.each { |l| out += l.to_asciibib prefix, link.size }
|
573
|
-
out += medium.to_asciibib prefix if medium
|
574
|
-
place.each { |pl| out += pl.to_asciibib prefix, place.size }
|
575
|
-
extent.each { |ex| out += ex.to_asciibib prefix, extent.size }
|
576
|
-
out += size.to_asciibib pref if size
|
577
|
-
accesslocation.each { |al| out += "#{pref}accesslocation:: #{al}\n" }
|
578
|
-
classification.each do |cl|
|
579
|
-
out += cl.to_asciibib prefix, classification.size
|
580
|
-
end
|
581
|
-
out += validity.to_asciibib prefix if validity
|
582
|
-
contributor.each do |c|
|
583
|
-
out += c.to_asciibib "contributor.*", contributor.size
|
584
|
-
end
|
585
|
-
out += relation.to_asciibib prefix if relation
|
586
|
-
series.each { |s| out += s.to_asciibib prefix, series.size }
|
587
|
-
out += doctype.to_asciibib prefix if doctype
|
588
|
-
out += "#{pref}subdoctype:: #{subdoctype}\n" if subdoctype
|
589
|
-
out += "#{pref}formattedref:: #{formattedref}\n" if formattedref
|
590
|
-
keyword.each { |kw| out += kw.to_asciibib "#{pref}keyword", keyword.size }
|
591
|
-
out += editorialgroup.to_asciibib prefix if editorialgroup
|
592
|
-
ics.each { |i| out += i.to_asciibib prefix, ics.size }
|
593
|
-
out += structuredidentifier.to_asciibib prefix if structuredidentifier
|
594
|
-
out
|
595
|
-
end
|
596
|
-
|
597
|
-
private
|
598
|
-
|
599
|
-
# @param opts [Hash]
|
600
|
-
# @option opts [Nokogiri::XML::Builder] :builder XML builder
|
601
|
-
# @option opts [Boolean] bibdata
|
602
|
-
# @option opts [Symbol, nil] :date_format (:short), :full
|
603
|
-
# @option opts [String] :lang language
|
604
|
-
def render_xml(**opts) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
605
|
-
root = opts[:bibdata] ? :bibdata : :bibitem
|
606
|
-
xml = opts[:builder].send(root) do |builder| # rubocop:disable Metrics/BlockLength
|
607
|
-
builder.fetched fetched if fetched
|
608
|
-
title.to_xml(**opts)
|
609
|
-
formattedref&.to_xml builder
|
610
|
-
link.each { |s| s.to_xml builder }
|
611
|
-
docidentifier.each { |di| di.to_xml(**opts) }
|
612
|
-
builder.docnumber docnumber if docnumber
|
613
|
-
date.each { |d| d.to_xml builder, **opts }
|
614
|
-
contributor.each do |c|
|
615
|
-
builder.contributor do
|
616
|
-
c.role.each { |r| r.to_xml(**opts) }
|
617
|
-
c.to_xml(**opts)
|
618
|
-
end
|
619
|
-
end
|
620
|
-
edition&.to_xml builder
|
621
|
-
version.each { |v| v.to_xml builder }
|
622
|
-
biblionote.to_xml(**opts)
|
623
|
-
opts[:note]&.each do |n|
|
624
|
-
builder.note(n[:text], format: "text/plain", type: n[:type])
|
625
|
-
end
|
626
|
-
language.each { |l| builder.language l }
|
627
|
-
script.each { |s| builder.script s }
|
628
|
-
abstr = abstract.select { |ab| ab.language&.include? opts[:lang] }
|
629
|
-
abstr = abstract unless abstr.any?
|
630
|
-
abstr.each { |a| builder.abstract { a.to_xml(builder) } }
|
631
|
-
status&.to_xml builder
|
632
|
-
copyright&.each { |c| c.to_xml(**opts) }
|
633
|
-
relation.each { |r| r.to_xml builder, **opts }
|
634
|
-
series.each { |s| s.to_xml builder }
|
635
|
-
medium&.to_xml builder
|
636
|
-
place.each { |pl| pl.to_xml builder }
|
637
|
-
extent.each { |e| e.to_xml builder }
|
638
|
-
size&.to_xml builder
|
639
|
-
accesslocation.each { |al| builder.accesslocation al }
|
640
|
-
license.each { |l| builder.license l }
|
641
|
-
classification.each { |cls| cls.to_xml builder }
|
642
|
-
kwrd = keyword.select { |kw| kw.language&.include? opts[:lang] }
|
643
|
-
kwrd = keyword unless kwrd.any?
|
644
|
-
kwrd.each { |kw| builder.keyword { kw.to_xml(builder) } }
|
645
|
-
validity&.to_xml builder
|
646
|
-
if block_given? then yield builder
|
647
|
-
elsif opts[:bibdata] && has_ext?
|
648
|
-
ext = builder.ext do |b|
|
649
|
-
doctype&.to_xml b
|
650
|
-
b.subdoctype subdoctype if subdoctype
|
651
|
-
editorialgroup&.to_xml b
|
652
|
-
ics.each { |i| i.to_xml b }
|
653
|
-
structuredidentifier&.to_xml b
|
654
|
-
end
|
655
|
-
ext["schema-version"] = ext_schema if !opts[:embedded] && respond_to?(:ext_schema) && ext_schema
|
656
|
-
end
|
657
|
-
end
|
658
|
-
xml[:id] = id if id && !opts[:bibdata] && !opts[:embedded]
|
659
|
-
xml[:type] = type if type
|
660
|
-
xml["schema-version"] = schema unless opts[:embedded]
|
661
|
-
xml
|
662
|
-
end
|
663
|
-
|
664
|
-
def has_ext? # rubocop:disable Metrics/CyclomaticComplexity
|
665
|
-
doctype || subdoctype || editorialgroup || ics&.any? || structuredidentifier&.presence?
|
666
|
-
end
|
667
|
-
end
|
668
|
-
end
|