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
@@ -0,0 +1,48 @@
|
|
1
|
+
module Relaton
|
2
|
+
module Bib
|
3
|
+
class StructuredIdentifier < Lutaml::Model::Serializable
|
4
|
+
attribute :type, :string
|
5
|
+
attribute :agency, :string, collection: (1..)
|
6
|
+
attribute :klass, :string
|
7
|
+
attribute :docnumber, :string
|
8
|
+
attribute :partnumber, :string
|
9
|
+
attribute :edition, :string
|
10
|
+
attribute :version, :string
|
11
|
+
attribute :supplementtype, :string
|
12
|
+
attribute :supplementnumber, :string
|
13
|
+
attribute :amendment, :string
|
14
|
+
attribute :corrigendum, :string
|
15
|
+
attribute :language, :string
|
16
|
+
attribute :year, :string
|
17
|
+
|
18
|
+
xml do
|
19
|
+
root "structuredidentifier"
|
20
|
+
map_attribute "type", to: :type
|
21
|
+
map_element "agency", to: :agency
|
22
|
+
map_element "class", to: :klass
|
23
|
+
map_element "docnumber", to: :docnumber
|
24
|
+
map_element "partnumber", to: :partnumber
|
25
|
+
map_element "edition", to: :edition
|
26
|
+
map_element "version", to: :version
|
27
|
+
map_element "supplementtype", to: :supplementtype
|
28
|
+
map_element "supplementnumber", to: :supplementnumber
|
29
|
+
map_element "amendment", to: :amendment
|
30
|
+
map_element "corrigendum", to: :corrigendum
|
31
|
+
map_element "language", to: :language
|
32
|
+
map_element "year", to: :year
|
33
|
+
end
|
34
|
+
|
35
|
+
def remove_part!
|
36
|
+
raise NotImplementedError, "`remove_part!` method not implemented in #{self.class}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_all_parts!
|
40
|
+
raise NotImplementedError, "`to_all_parts!` method not implemented in #{self.class}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def remove_date!
|
44
|
+
raise NotImplementedError, "`remove_date!` method not implemented in #{self.class}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Relaton
|
2
|
+
module Bib
|
3
|
+
class Title < LocalizedMarkedUpString
|
4
|
+
attribute :type, :string
|
5
|
+
attribute :format, :string # @DEPRECATED
|
6
|
+
|
7
|
+
xml do
|
8
|
+
map_attribute "type", to: :type
|
9
|
+
map_attribute "format", to: :format
|
10
|
+
end
|
11
|
+
|
12
|
+
key_value do
|
13
|
+
map "type", to: :type
|
14
|
+
map "format", to: :format
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Relaton
|
2
|
+
module Bib
|
3
|
+
class Uri < LocalizedStringAttrs
|
4
|
+
attribute :type, :string
|
5
|
+
attribute :content, :string
|
6
|
+
|
7
|
+
xml do
|
8
|
+
map_attribute "type", to: :type
|
9
|
+
map_content to: :content
|
10
|
+
end
|
11
|
+
|
12
|
+
key_value do
|
13
|
+
map "type", to: :type
|
14
|
+
map "content", to: :content
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Relaton
|
2
|
+
module Bib
|
3
|
+
class Validity < Lutaml::Model::Serializable
|
4
|
+
attribute :begins, :date
|
5
|
+
attribute :ends, :date
|
6
|
+
attribute :revision, :date
|
7
|
+
|
8
|
+
xml do
|
9
|
+
root "validity"
|
10
|
+
map_element "validityBegins", to: :begins
|
11
|
+
map_element "validityEnds", to: :ends
|
12
|
+
map_element "revision", to: :revision
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Relaton
|
2
|
+
module Bib
|
3
|
+
class Version < Lutaml::Model::Serializable
|
4
|
+
attribute :revision_date, :date
|
5
|
+
attribute :draft, :string
|
6
|
+
|
7
|
+
xml do
|
8
|
+
root "version"
|
9
|
+
map_element "revision-date", to: :revision_date
|
10
|
+
map_element "draft", to: :draft
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Relaton
|
2
|
+
module Bib
|
3
|
+
class WorkGroup < Lutaml::Model::Serializable
|
4
|
+
attribute :number, :integer
|
5
|
+
attribute :type, :string
|
6
|
+
attribute :identifier, :string
|
7
|
+
attribute :prefix, :string
|
8
|
+
attribute :content, :string
|
9
|
+
|
10
|
+
xml do
|
11
|
+
root "workgroup"
|
12
|
+
map_attribute "number", to: :number
|
13
|
+
map_attribute "type", to: :type
|
14
|
+
map_attribute "identifier", to: :identifier
|
15
|
+
map_attribute "prefix", to: :prefix
|
16
|
+
map_content to: :content
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Relaton
|
2
|
+
module Bib
|
3
|
+
module Parser
|
4
|
+
# Class for transforming RFC Postal to Relaton Address
|
5
|
+
class RfcAddress
|
6
|
+
def initialize(postal)
|
7
|
+
@postal = postal
|
8
|
+
end
|
9
|
+
|
10
|
+
#
|
11
|
+
# Transform address from RFC Postal to Relaton Address
|
12
|
+
#
|
13
|
+
# @param [Rfcxml::V3::Address] address RFC Address
|
14
|
+
#
|
15
|
+
# @return [Array<Relaton::Bib::Address>]
|
16
|
+
#
|
17
|
+
def self.transform(address)
|
18
|
+
return [] unless address&.postal
|
19
|
+
|
20
|
+
new(address.postal).transform
|
21
|
+
end
|
22
|
+
|
23
|
+
def transform # rubocop:disable Metrics/CyclomaticComplexity
|
24
|
+
street = @postal.street || []
|
25
|
+
city = @postal.city || []
|
26
|
+
region = @postal.region || []
|
27
|
+
country = @postal.country || []
|
28
|
+
code = @postal.code || []
|
29
|
+
postal_line = @postal.postal_line || []
|
30
|
+
transform_args(
|
31
|
+
street: street, city: city, region: region, country: country, code: code, postal_line: postal_line,
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def transform_args(**args)
|
36
|
+
i = 0
|
37
|
+
addrs = []
|
38
|
+
while args.values.any? { |v| v[i] }
|
39
|
+
addrs << create_address(**args.transform_values { |v| v[i] })
|
40
|
+
i += 1
|
41
|
+
end
|
42
|
+
addrs
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_address(**args) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize,Metrics/PerceivedComplexity
|
46
|
+
street = []
|
47
|
+
street << args[:street]&.content if args[:street]
|
48
|
+
Address.new(
|
49
|
+
street: street,
|
50
|
+
city: args[:city]&.content,
|
51
|
+
state: args[:region]&.content,
|
52
|
+
country: args[:country]&.content,
|
53
|
+
postcode: args[:code]&.content,
|
54
|
+
formatted_address: args[:postal_line]&.content,
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative "rfc_address"
|
2
|
+
|
3
|
+
module Relaton
|
4
|
+
module Bib
|
5
|
+
module Parser
|
6
|
+
module RfcContacts
|
7
|
+
def initialize(author)
|
8
|
+
@author = author
|
9
|
+
end
|
10
|
+
|
11
|
+
def address
|
12
|
+
RfcAddress.transform(@author.address)
|
13
|
+
end
|
14
|
+
|
15
|
+
def phone
|
16
|
+
return [] unless @author.address&.phone
|
17
|
+
|
18
|
+
[Phone.new(content: @author.address.phone.content)]
|
19
|
+
end
|
20
|
+
|
21
|
+
def email
|
22
|
+
return [] unless @author.address&.email
|
23
|
+
|
24
|
+
@author.address.email.map(&:content)
|
25
|
+
end
|
26
|
+
|
27
|
+
def uri
|
28
|
+
return [] unless @author.address&.uri
|
29
|
+
|
30
|
+
[Uri.new(content: @author.address.uri.content)]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Relaton
|
2
|
+
module Bib
|
3
|
+
module Parser
|
4
|
+
class RfcDocidentifier
|
5
|
+
RFCPREFIXES = %w[RFC BCP FYI STD].freeze
|
6
|
+
|
7
|
+
def initialize(reference)
|
8
|
+
@reference = reference
|
9
|
+
end
|
10
|
+
|
11
|
+
def transform
|
12
|
+
docids = [create_docid(@reference.anchor, primary: true)]
|
13
|
+
create_internet_draft_id { |id| docids << id }
|
14
|
+
docids + docid_from_sereies_info
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_docid(id, primary: false) # , ver) # rubocop:disable Metrics/MethodLength
|
18
|
+
pref, num = id_to_pref_num(id)
|
19
|
+
if RFCPREFIXES.include?(pref)
|
20
|
+
pid = "#{pref} #{num.sub(/^-?0+/, '')}"
|
21
|
+
type = pubid_type id
|
22
|
+
elsif %w[I-D draft].include?(pref)
|
23
|
+
pid = "draft-#{num}"
|
24
|
+
type = "Internet-Draft"
|
25
|
+
else
|
26
|
+
pid = pref ? "#{pref} #{num}" : id
|
27
|
+
type = pubid_type id
|
28
|
+
end
|
29
|
+
Docidentifier.new(type: type, content: pid, primary: primary)
|
30
|
+
end
|
31
|
+
|
32
|
+
def pubid_type(id)
|
33
|
+
id_to_pref_num(id)&.first
|
34
|
+
end
|
35
|
+
|
36
|
+
def id_to_pref_num(id)
|
37
|
+
tn = /^(?<pref>I-D|draft|3GPP|W3C|[A-Z]{2,})[._-]?(?<num>.+)/.match id
|
38
|
+
tn && tn.to_a[1..2]
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_internet_draft_id
|
42
|
+
return unless @reference.respond_to?(:front) && @reference.front
|
43
|
+
|
44
|
+
si = internet_draft_series_info(@reference.front) || internet_draft_series_info(@reference)
|
45
|
+
if si
|
46
|
+
content = si.value
|
47
|
+
yield Docidentifier.new(type: "Internet-Draft", content: content)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def internet_draft_series_info(parent)
|
52
|
+
(parent.series_info || []).find { |si| si.name == "Internet-Draft" }
|
53
|
+
end
|
54
|
+
|
55
|
+
def docid_from_sereies_info # rubocop:disable Metrics/CyclomaticComplexity
|
56
|
+
return [] unless @reference.respond_to?(:front) && @reference.front
|
57
|
+
|
58
|
+
si = (@reference.front.series_info || []) + (@reference.series_info || [])
|
59
|
+
si.reduce([]) do |acc, s|
|
60
|
+
next acc unless s.name.casecmp("doi").zero?
|
61
|
+
|
62
|
+
acc << Docidentifier.new(type: "DOI", content: s.value)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def create_docidentifier(**args) = Docidentifier.new(**args)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Relaton
|
2
|
+
module Bib
|
3
|
+
module Parser
|
4
|
+
class RfcOrganization
|
5
|
+
ORGNAMES = {
|
6
|
+
"IEEE" => "Institute of Electrical and Electronics Engineers",
|
7
|
+
"W3C" => "World Wide Web Consortium",
|
8
|
+
"3GPP" => "3rd Generation Partnership Project",
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
include RfcContacts
|
12
|
+
|
13
|
+
def self.transform(author)
|
14
|
+
org = author.organization
|
15
|
+
return if org.nil? || org.content.empty?
|
16
|
+
|
17
|
+
new(author).transform
|
18
|
+
end
|
19
|
+
|
20
|
+
def transform
|
21
|
+
name = ORGNAMES[@author.organization.content] || @author.organization.content
|
22
|
+
orgname = TypedLocalizedString.new(content: name, language: "en")
|
23
|
+
abbrev = LocalizedString.new(content: @author.organization.abbrev, language: "en")
|
24
|
+
Organization.new(
|
25
|
+
name: [orgname], abbreviation: abbrev, address: address, phone: phone, email: email, uri: uri,
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Relaton
|
2
|
+
module Bib
|
3
|
+
module Parser
|
4
|
+
class RfcPerson
|
5
|
+
include RfcContacts
|
6
|
+
|
7
|
+
def self.transform(author)
|
8
|
+
return unless author.fullname || author.surname
|
9
|
+
|
10
|
+
new(author).transform
|
11
|
+
end
|
12
|
+
|
13
|
+
def transform
|
14
|
+
Person.new(
|
15
|
+
name: name, affiliation: affiliation, address: address, phone: phone, email: email, uri: uri,
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
def name
|
20
|
+
FullName.new(
|
21
|
+
completename: LocalizedString.new(content: @author.fullname, language: "en"),
|
22
|
+
formatted_initials: initials,
|
23
|
+
surname: LocalizedString.new(content: @author.surname, language: "en"),
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def initials
|
28
|
+
return unless @author.initials
|
29
|
+
|
30
|
+
LocalizedString.new(content: @author.initials, language: "en")
|
31
|
+
end
|
32
|
+
|
33
|
+
def affiliation
|
34
|
+
org = RfcOrganization.transform(@author)
|
35
|
+
return [] unless org
|
36
|
+
|
37
|
+
[Affiliation.new(organization: org)]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require_relative "rfc_shared"
|
2
|
+
require_relative "rfc_contacts"
|
3
|
+
require_relative "rfc_person"
|
4
|
+
require_relative "rfc_organization"
|
5
|
+
require_relative "rfc_docidentifier"
|
6
|
+
|
7
|
+
module Relaton
|
8
|
+
module Bib
|
9
|
+
module Parser
|
10
|
+
class RfcReference
|
11
|
+
include RfcShared
|
12
|
+
|
13
|
+
def initialize(reference)
|
14
|
+
@reference = reference
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.from_xml(xml)
|
18
|
+
reference = Rfcxml::V3::Reference.from_xml xml
|
19
|
+
new(reference).transform
|
20
|
+
end
|
21
|
+
|
22
|
+
def transform # rubocop:disable Metrics/MethodLength
|
23
|
+
ItemData.new(
|
24
|
+
docnumber: @reference.anchor.sub(/^\w+\./, ""),
|
25
|
+
type: "standard",
|
26
|
+
docidentifier: RfcDocidentifier.new(@reference).transform,
|
27
|
+
status: status,
|
28
|
+
language: ["en"],
|
29
|
+
script: ["Latn"],
|
30
|
+
source: source,
|
31
|
+
title: title,
|
32
|
+
formattedref: formattedref,
|
33
|
+
abstract: abstract,
|
34
|
+
contributor: contributor,
|
35
|
+
date: date,
|
36
|
+
series: series,
|
37
|
+
keyword: keyword,
|
38
|
+
ext: ext,
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def status
|
43
|
+
si = @reference.front.series_info&.find(&:status) || @reference.series_info&.status
|
44
|
+
return unless si
|
45
|
+
|
46
|
+
stage = Status::Stage.new(content: si.status)
|
47
|
+
Status.new(stage: stage)
|
48
|
+
end
|
49
|
+
|
50
|
+
def title
|
51
|
+
[Title.new(content: @reference.front.title.content, language: "en", script: "Latn")]
|
52
|
+
end
|
53
|
+
|
54
|
+
def formattedref
|
55
|
+
return if @reference.front.title
|
56
|
+
|
57
|
+
@reference.anchor
|
58
|
+
end
|
59
|
+
|
60
|
+
def abstract
|
61
|
+
return [] unless @reference.front.abstract
|
62
|
+
|
63
|
+
@reference.front.abstract.t.map do |t|
|
64
|
+
LocalizedMarkedUpString.new(content: t.content, language: "en", script: "Latn")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def contributor
|
69
|
+
(@reference.front.author || []).reduce([]) do |acc, author|
|
70
|
+
p = person(author)
|
71
|
+
o = organization(author)
|
72
|
+
next acc unless p || o
|
73
|
+
|
74
|
+
acc << Contributor.new(person: p, organization: o, role: [contributor_role(author)])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def contributor_role(author)
|
79
|
+
type = author.role || "author"
|
80
|
+
Contributor::Role.new(type: type)
|
81
|
+
end
|
82
|
+
|
83
|
+
def person(author) = RfcPerson.transform(author)
|
84
|
+
def organization(author) = RfcOrganization.transform(author)
|
85
|
+
|
86
|
+
def date # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
87
|
+
dt = @reference.front&.date
|
88
|
+
return [] unless dt || dt.year || dt.month || dt.day
|
89
|
+
|
90
|
+
dparts = [dt.year, month_to_num(dt.month), dt.day].compact.reject(&:empty?)
|
91
|
+
at = dt.content.empty? ? dparts.join("-") : dt.content
|
92
|
+
[Date.new(type: "published", at: at)]
|
93
|
+
end
|
94
|
+
|
95
|
+
def month_to_num(month)
|
96
|
+
return unless month
|
97
|
+
|
98
|
+
::Date::MONTHNAMES.index(month.capitalize).to_s
|
99
|
+
end
|
100
|
+
|
101
|
+
def series # rubocop:disable Metrics/CyclomaticComplexity
|
102
|
+
((@reference.series_info || []) + (@reference.front.series_info || [])).map do |si|
|
103
|
+
next if si.name == "DOI" || si.stream || si.status
|
104
|
+
|
105
|
+
t = Title.new(content: si.name, language: "en", script: "Latn")
|
106
|
+
Series.new(title: [t], number: si.value, type: "main")
|
107
|
+
end.compact
|
108
|
+
end
|
109
|
+
|
110
|
+
def keyword
|
111
|
+
(@reference.front.keyword || []).map do |kw|
|
112
|
+
taxon = LocalizedString.new(content: kw.content, language: "en", script: "Latn")
|
113
|
+
Keyword.new(taxon: [taxon])
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def ext
|
118
|
+
eg = editorialgroup
|
119
|
+
dt = doctype
|
120
|
+
return unless eg || dt
|
121
|
+
|
122
|
+
Bib::Ext.new editorialgroup: eg, doctype: dt
|
123
|
+
end
|
124
|
+
|
125
|
+
def editorialgroup
|
126
|
+
return unless @reference.front.workgroup
|
127
|
+
|
128
|
+
tc = @reference.front.workgroup.map { |wg| WorkGroup.new content: wg.content }
|
129
|
+
EditorialGroup.new(technical_committee: tc) if tc.any?
|
130
|
+
end
|
131
|
+
|
132
|
+
def doctype
|
133
|
+
type = case @reference.anchor
|
134
|
+
when /I-D/ then "internet-draft"
|
135
|
+
when /IEEE/ then "ieee"
|
136
|
+
else "rfc"
|
137
|
+
end
|
138
|
+
Doctype.new content: type
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative "rfc_shared"
|
2
|
+
|
3
|
+
module Relaton
|
4
|
+
module Bib
|
5
|
+
module Parser
|
6
|
+
# Class for transforming RFC ReferenceGroup to Relaton ReferenceGroup
|
7
|
+
class RfcReferencegroup
|
8
|
+
include RfcShared
|
9
|
+
|
10
|
+
def initialize(reference)
|
11
|
+
@reference = reference
|
12
|
+
end
|
13
|
+
|
14
|
+
#
|
15
|
+
# Transform reference group from RFC ReferenceGroup to Relaton ReferenceGroup
|
16
|
+
#
|
17
|
+
# @param [Rfcxml::V3::ReferenceGroup] reference_group RFC ReferenceGroup
|
18
|
+
#
|
19
|
+
# @return [Relaton::Bib::ReferenceGroup]
|
20
|
+
#
|
21
|
+
def self.from_xml(xml) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
22
|
+
reference = Rfcxml::V3::Referencegroup.from_xml xml
|
23
|
+
new(reference).transform
|
24
|
+
end
|
25
|
+
|
26
|
+
def transform
|
27
|
+
ItemData.new(
|
28
|
+
docnumber: @reference.anchor.sub(/^\w+\./, ""),
|
29
|
+
type: "standard",
|
30
|
+
docidentifier: RfcDocidentifier.new(@reference).transform,
|
31
|
+
source: source,
|
32
|
+
relation: relation,
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def relation
|
37
|
+
(@reference.reference || []).map do |ref|
|
38
|
+
item = RfcReference.new(ref).transform
|
39
|
+
Relation.new(type: "includes", bibitem: item)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Relaton
|
2
|
+
module Bib
|
3
|
+
module Parser
|
4
|
+
module RfcShared
|
5
|
+
def source # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
6
|
+
s = []
|
7
|
+
s << Uri.new(type: "src", content: @reference.target) if @reference.target
|
8
|
+
# if /^I-D/.match? @reference.anchor
|
9
|
+
# @reference.format.each do |f|
|
10
|
+
# s << Uri.new(type: f.type, content: f.target)
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
return s unless @reference.respond_to?(:front) && @reference.front
|
14
|
+
|
15
|
+
(@reference.format || []).each do |fr|
|
16
|
+
s << Uri.new(type: fr.type, content: fr.target)
|
17
|
+
end
|
18
|
+
s
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|