relaton-bib 1.20.8 → 2.0.0

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.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/.rubocop.yml +1 -1
  4. data/CLAUDE.md +96 -0
  5. data/Gemfile +1 -4
  6. data/README.adoc +195 -154
  7. data/bin/console +1 -1
  8. data/grammars/basicdoc.rng +1572 -671
  9. data/grammars/biblio-standoc.rng +107 -46
  10. data/grammars/biblio.rng +1012 -377
  11. data/grammars/versions.json +26 -26
  12. data/lib/relaton/bib/converter/asciibib/to_asciibib.rb +663 -0
  13. data/lib/relaton/bib/converter/asciibib.rb +13 -0
  14. data/lib/relaton/bib/converter/bibtex/from_bibtex.rb +245 -0
  15. data/lib/relaton/bib/converter/bibtex/to_bibtex.rb +341 -0
  16. data/lib/relaton/bib/converter/bibtex.rb +23 -0
  17. data/lib/relaton/bib/converter/bibxml/from_rfcxml.rb +383 -0
  18. data/lib/relaton/bib/converter/bibxml/from_rfcxml_referencegroup.rb +71 -0
  19. data/lib/relaton/bib/converter/bibxml/to_rfcxml.rb +305 -0
  20. data/lib/relaton/bib/converter/bibxml/to_rfcxml_referencegroup.rb +52 -0
  21. data/lib/relaton/bib/converter/bibxml.rb +51 -0
  22. data/lib/relaton/bib/hash_parser_v1.rb +754 -0
  23. data/lib/relaton/bib/item_data.rb +229 -0
  24. data/lib/relaton/bib/model/abstract.rb +16 -0
  25. data/lib/relaton/bib/model/address.rb +22 -0
  26. data/lib/relaton/bib/model/affiliation.rb +16 -0
  27. data/lib/relaton/bib/model/bibdata.rb +24 -0
  28. data/lib/relaton/bib/model/bibitem.rb +23 -0
  29. data/lib/relaton/bib/model/contact.rb +18 -0
  30. data/lib/relaton/bib/model/contribution_info.rb +16 -0
  31. data/lib/relaton/bib/model/contributor.rb +71 -0
  32. data/lib/relaton/bib/model/copyright.rb +27 -0
  33. data/lib/relaton/bib/model/date.rb +31 -0
  34. data/lib/relaton/bib/model/depiction.rb +16 -0
  35. data/lib/relaton/bib/model/docidentifier.rb +33 -0
  36. data/lib/relaton/bib/model/doctype.rb +14 -0
  37. data/lib/relaton/bib/model/edition.rb +14 -0
  38. data/lib/relaton/bib/model/ext.rb +26 -0
  39. data/lib/relaton/bib/model/extent.rb +16 -0
  40. data/lib/relaton/bib/model/formattedref.rb +43 -0
  41. data/lib/relaton/bib/model/full_name_type.rb +64 -0
  42. data/lib/relaton/bib/model/fullname.rb +11 -0
  43. data/lib/relaton/bib/model/ics.rb +23 -0
  44. data/lib/relaton/bib/model/image.rb +28 -0
  45. data/lib/relaton/bib/model/item.rb +137 -0
  46. data/lib/relaton/bib/model/item_base.rb +27 -0
  47. data/lib/relaton/bib/model/keyword.rb +30 -0
  48. data/lib/relaton/bib/model/locality.rb +18 -0
  49. data/lib/relaton/bib/model/locality_stack.rb +14 -0
  50. data/lib/relaton/bib/model/localized_string.rb +57 -0
  51. data/lib/relaton/bib/model/localized_string_attrs.rb +24 -0
  52. data/lib/relaton/bib/model/logo.rb +14 -0
  53. data/lib/relaton/bib/model/medium.rb +22 -0
  54. data/lib/relaton/bib/model/note.rb +16 -0
  55. data/lib/relaton/bib/model/organization.rb +13 -0
  56. data/lib/relaton/bib/model/organization_type.rb +42 -0
  57. data/lib/relaton/bib/model/person.rb +36 -0
  58. data/lib/relaton/bib/model/phone.rb +14 -0
  59. data/lib/relaton/bib/model/place.rb +33 -0
  60. data/lib/relaton/bib/model/price.rb +14 -0
  61. data/lib/relaton/bib/model/relation.rb +43 -0
  62. data/lib/relaton/bib/model/series.rb +34 -0
  63. data/lib/relaton/bib/model/size.rb +23 -0
  64. data/lib/relaton/bib/model/source_locality_stack.rb +14 -0
  65. data/lib/relaton/bib/model/status.rb +27 -0
  66. data/lib/relaton/bib/model/structured_identifier.rb +48 -0
  67. data/lib/relaton/bib/model/subdivision.rb +16 -0
  68. data/lib/relaton/bib/model/title.rb +56 -0
  69. data/lib/relaton/bib/model/type/string_date.rb +48 -0
  70. data/lib/relaton/bib/model/uri.rb +18 -0
  71. data/lib/relaton/bib/model/validity.rb +16 -0
  72. data/lib/relaton/bib/model/version.rb +14 -0
  73. data/lib/relaton/bib/namespace_helper.rb +21 -0
  74. data/lib/relaton/bib/util.rb +18 -0
  75. data/lib/relaton/bib/version.rb +5 -0
  76. data/lib/relaton/bib.rb +45 -0
  77. data/relaton-bib.gemspec +11 -8
  78. metadata +125 -67
  79. data/lib/relaton_bib/bib_item_locality.rb +0 -175
  80. data/lib/relaton_bib/biblio_note.rb +0 -72
  81. data/lib/relaton_bib/biblio_version.rb +0 -46
  82. data/lib/relaton_bib/bibliographic_date.rb +0 -119
  83. data/lib/relaton_bib/bibliographic_item.rb +0 -668
  84. data/lib/relaton_bib/bibliographic_size.rb +0 -103
  85. data/lib/relaton_bib/bibtex_parser.rb +0 -246
  86. data/lib/relaton_bib/bibxml_parser.rb +0 -422
  87. data/lib/relaton_bib/classification.rb +0 -40
  88. data/lib/relaton_bib/config.rb +0 -16
  89. data/lib/relaton_bib/contribution_info.rb +0 -117
  90. data/lib/relaton_bib/contributor.rb +0 -277
  91. data/lib/relaton_bib/copyright_association.rb +0 -79
  92. data/lib/relaton_bib/deep_dup.rb +0 -30
  93. data/lib/relaton_bib/document_identifier.rb +0 -118
  94. data/lib/relaton_bib/document_relation.rb +0 -95
  95. data/lib/relaton_bib/document_relation_collection.rb +0 -57
  96. data/lib/relaton_bib/document_status.rb +0 -92
  97. data/lib/relaton_bib/document_type.rb +0 -52
  98. data/lib/relaton_bib/edition.rb +0 -55
  99. data/lib/relaton_bib/editorial_group.rb +0 -41
  100. data/lib/relaton_bib/extent.rb +0 -39
  101. data/lib/relaton_bib/forename.rb +0 -65
  102. data/lib/relaton_bib/formatted_ref.rb +0 -17
  103. data/lib/relaton_bib/formatted_string.rb +0 -133
  104. data/lib/relaton_bib/full_name.rb +0 -108
  105. data/lib/relaton_bib/hash_converter.rb +0 -568
  106. data/lib/relaton_bib/hit.rb +0 -52
  107. data/lib/relaton_bib/hit_collection.rb +0 -105
  108. data/lib/relaton_bib/ics.rb +0 -42
  109. data/lib/relaton_bib/image.rb +0 -95
  110. data/lib/relaton_bib/localized_string.rb +0 -149
  111. data/lib/relaton_bib/medium.rb +0 -76
  112. data/lib/relaton_bib/organization.rb +0 -165
  113. data/lib/relaton_bib/person.rb +0 -129
  114. data/lib/relaton_bib/place.rb +0 -203
  115. data/lib/relaton_bib/renderer/bibtex_builder.rb +0 -312
  116. data/lib/relaton_bib/renderer/bibxml.rb +0 -296
  117. data/lib/relaton_bib/series.rb +0 -119
  118. data/lib/relaton_bib/structured_identifier.rb +0 -173
  119. data/lib/relaton_bib/technical_committee.rb +0 -34
  120. data/lib/relaton_bib/typed_title_string.rb +0 -191
  121. data/lib/relaton_bib/typed_uri.rb +0 -57
  122. data/lib/relaton_bib/util.rb +0 -16
  123. data/lib/relaton_bib/validity.rb +0 -52
  124. data/lib/relaton_bib/version.rb +0 -3
  125. data/lib/relaton_bib/workers_pool.rb +0 -43
  126. data/lib/relaton_bib/workgroup.rb +0 -58
  127. data/lib/relaton_bib/xml_parser.rb +0 -718
  128. data/lib/relaton_bib.rb +0 -111
@@ -1,103 +0,0 @@
1
- module RelatonBib
2
- class BibliographicSize
3
- extend Forwardable
4
-
5
- def_delegators :@size, :any?
6
-
7
- # @return [Array<RelatonBib::BibliographicSize::Value>]
8
- attr_reader :size
9
-
10
- #
11
- # Initialize a BibliographicSize object.
12
- #
13
- # @param [<Type>] size <description>
14
- #
15
- def initialize(size)
16
- @size = size
17
- end
18
-
19
- #
20
- # Render BibliographicSize object to XML.
21
- #
22
- # @param [Nokogiri::XML::Builder] builder the XML builder
23
- #
24
- def to_xml(builder)
25
- return if size.empty?
26
-
27
- builder.size do
28
- size.each { |s| s.to_xml builder }
29
- end
30
- end
31
-
32
- #
33
- # Render BibliographicSize object to AsciiBib.
34
- #
35
- # @param [String] prefix prefix for the size
36
- #
37
- # @return [String] AsciiBib string
38
- #
39
- def to_asciibib(prefix = "")
40
- pref = prefix.empty? ? "size" : "#{prefix}.size"
41
- size.map { |s| s.to_asciibib pref, size.size }.join
42
- end
43
-
44
- #
45
- # Render BibliographicSize object to hash.
46
- #
47
- # @return [<Type>] <description>
48
- #
49
- def to_hash
50
- size.map &:to_hash
51
- end
52
-
53
- class Value
54
- # @return [String]
55
- attr_reader :type, :value
56
-
57
- #
58
- # Initialize a BibliographicSize::Value object.
59
- #
60
- # @param [String] type the type of the size
61
- # @param [String] value size value
62
- #
63
- def initialize(type:, value:)
64
- @type = type
65
- @value = value
66
- end
67
-
68
- #
69
- # Render BibliographicSize::Value object to XML.
70
- #
71
- # @param [Nokogiri::XML::Builder] builder the XML builder
72
- #
73
- def to_xml(builder)
74
- builder.value value, type: type
75
- end
76
-
77
- #
78
- # Render BibliographicSize::Value object to hash.
79
- #
80
- # @return [<Type>] <description>
81
- #
82
- def to_hash
83
- { type: type, value: value }
84
- end
85
-
86
- #
87
- # Render BibliographicSize::Value object to AsciiBib.
88
- #
89
- # @param [String] prefix prefix for the size
90
- # @param [Integer] size size of the array
91
- #
92
- # @return [String] AsciiBib string
93
- #
94
- def to_asciibib(prefix, size)
95
- pref = prefix.empty? ? "" : "#{prefix}."
96
- out = ""
97
- out << "#{prefix}::\n" if size.size > 1
98
- out << "#{pref}type:: #{type}\n"
99
- out << "#{pref}value:: #{value}\n"
100
- end
101
- end
102
- end
103
- end
@@ -1,246 +0,0 @@
1
- require "bibtex"
2
- require "iso639"
3
-
4
- module RelatonBib
5
- # @todo: move this class to the RelatonBib::Bibtex module
6
- class BibtexParser
7
- class << self
8
- # @param bibtex [String]
9
- # @return [Hash{String=>RelatonBib::BibliographicItem}]
10
- def from_bibtex(bibtex) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
11
- BibTeX.parse(bibtex).reduce({}) do |h, bt|
12
- h[bt.key] = BibliographicItem.new(
13
- id: bt.key,
14
- docid: fetch_docid(bt),
15
- fetched: fetch_fetched(bt),
16
- type: fetch_type(bt),
17
- title: fetch_title(bt),
18
- contributor: fetch_contributor(bt),
19
- date: fetch_date(bt),
20
- place: fetch_place(bt),
21
- biblionote: fetch_note(bt),
22
- relation: fetch_relation(bt),
23
- extent: fetch_extent(bt),
24
- edition: bt["edition"]&.to_s,
25
- series: fetch_series(bt),
26
- link: fetch_link(bt),
27
- language: fetch_language(bt),
28
- classification: fetch_classification(bt),
29
- keyword: fetch_keyword(bt),
30
- )
31
- h
32
- end
33
- end
34
-
35
- private
36
-
37
- # @param bibtex [BibTeX::Entry]
38
- # @return [Array<RelatonBib::DocumentIdentifier>]
39
- def fetch_docid(bibtex) # rubocop:disable Metrics/AbcSize
40
- docid = []
41
- docid << DocumentIdentifier.new(id: bibtex.isbn.to_s, type: "isbn") if bibtex["isbn"]
42
- docid << DocumentIdentifier.new(id: bibtex.lccn.to_s, type: "lccn") if bibtex["lccn"]
43
- docid << DocumentIdentifier.new(id: bibtex.issn.to_s, type: "issn") if bibtex["issn"]
44
- docid
45
- end
46
-
47
- # @param bibtex [BibTeX::Entry]
48
- # @return [String, nil]
49
- def fetch_fetched(bibtex)
50
- Date.parse(bibtex.timestamp.to_s) if bibtex["timestamp"]
51
- end
52
-
53
- # @param bibtex [BibTeX::Entry]
54
- # @return [String]
55
- def fetch_type(bibtex)
56
- case bibtex.type
57
- when :mastersthesis, :phdthesis then "thesis"
58
- when :conference then "inproceedings"
59
- when :misc then "standard"
60
- else bibtex.type.to_s
61
- end
62
- end
63
-
64
- # @param bibtex [BibTeX::Entry]
65
- # @return [Array<Hash>]
66
- def fetch_place(bibtex)
67
- bibtex["address"] ? [bibtex.address.to_s] : []
68
- end
69
-
70
- # @param bibtex [BibTeX::Entry]
71
- # @return [RelatonBib::TypedTitleStringCollection]
72
- def fetch_title(bibtex)
73
- title = []
74
- title << { type: "main", content: bibtex.convert(:latex).title.to_s } if bibtex["title"]
75
- title << { type: "main", content: bibtex.convert(:latex).subtitle.to_s } if bibtex["subtitle"]
76
- TypedTitleStringCollection.new title
77
- end
78
-
79
- # @param bibtex [BibTeX::Entry]
80
- # @return [Array<Hash>]
81
- def fetch_contributor(bibtex) # rubocop:disable Metrics/AbcSize
82
- contribs = []
83
- fetch_person(bibtex, "author") { |author| contribs << author }
84
- fetch_person(bibtex, "editor") { |editor| contribs << editor }
85
-
86
- fetch_org(bibtex["publisher"], "publisher") { |pub| contribs << pub }
87
- fetch_org(bibtex["institution"], "distributor", "sponsor") { |distr| contribs << distr }
88
- fetch_org(bibtex["organization"], "distributor", "sponsor") { |org| contribs << org }
89
- fetch_org(bibtex["school"], "distributor", "sponsor") { |school| contribs << school }
90
-
91
- fetch_howpublished(bibtex) { |pub| contribs << pub }
92
-
93
- contribs
94
- end
95
-
96
- def fetch_howpublished(bibtex, &_)
97
- return unless bibtex["howpublished"]
98
-
99
- /\\publisher\{(?<name>.+)\},\\url\{(?<url>.+)\}/ =~ bibtex.howpublished.to_s
100
- return unless name && url
101
-
102
- name.gsub!(/\{\\?([^\\]+)\}/, '\1')
103
- org = Organization.new(name: name, url: url)
104
- yield entity: org, role: [{ type: "publisher" }]
105
- end
106
-
107
- def fetch_org(org, type, desc = nil, &_)
108
- return unless org
109
-
110
- role = { type: type }
111
- role[:description] = [desc] if desc
112
- yield entity: Organization.new(name: org.to_s), role: [role]
113
- end
114
-
115
- # @param bibtex [BibTeX::Entry]
116
- # @return [Array<RelatonBib::Person>]
117
- def fetch_person(bibtex, role, &_) # rubocop:disable Metrics/AbcSize
118
- bibtex[role]&.each do |name|
119
- parts = name.split ", "
120
- surname = LocalizedString.new parts.first
121
- fname = parts.size > 1 ? parts[1].split : []
122
- forename = fname.map { |fn| Forename.new content: fn }
123
- name = FullName.new(surname: surname, forename: forename)
124
- yield entity: Person.new(name: name), role: [{ type: role }]
125
- end
126
- end
127
-
128
- # @param bibtex [BibTeX::Entry]
129
- # @return [Array<Hash>]
130
- def fetch_date(bibtex)
131
- date = []
132
- if bibtex["year"]
133
- on = Date.new(bibtex.year.to_i, bibtex["month_numeric"]&.to_i || 1).to_s
134
- date << { type: "published", on: on }
135
- end
136
-
137
- if bibtex["urldate"]
138
- date << { type: "accessed", on: Date.parse(bibtex.urldate.to_s).to_s }
139
- end
140
-
141
- date
142
- end
143
-
144
- # @param bibtex [BibTeX::Entry]
145
- # @return [RelatonBib::BiblioNoteCollection]
146
- def fetch_note(bibtex) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
147
- bibtex.select do |k, _v|
148
- %i[annote howpublished comment note content].include? k
149
- end.reduce(BiblioNoteCollection.new([])) do |mem, note|
150
- type = case note[0]
151
- when :note then nil
152
- when :content then "tableOfContents"
153
- else note[0].to_s
154
- end
155
- next mem if type == "howpublished" && note[1].to_s.match?(/^\\publisher\{.+\},\\url\{.+\}$/)
156
-
157
- mem << BiblioNote.new(type: type, content: note[1].to_s)
158
- end
159
- end
160
-
161
- # @param bibtex [BibTeX::Entry]
162
- # @return [Array<Hash>]
163
- def fetch_relation(bibtex)
164
- return [] unless bibtex["booktitle"]
165
-
166
- ttl = TypedTitleString.new(type: "main", content: bibtex.booktitle.to_s)
167
- title = TypedTitleStringCollection.new [ttl]
168
- [{ type: "partOf", bibitem: BibliographicItem.new(title: title) }]
169
- end
170
-
171
- # @param bibtex [BibTeX::Entry]
172
- # @return [Array<RelatonBib::Extent>]
173
- def fetch_extent(bibtex) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
174
- locs = bibtex.select do |k, _v|
175
- %i[chapter pages volume].include? k
176
- end.reduce([]) do |mem, loc|
177
- if loc[0] == :pages
178
- type = "page"
179
- from, to = loc[1].to_s.split "-"
180
- else
181
- type = loc[0].to_s
182
- from = loc[1].to_s
183
- to = nil
184
- end
185
- mem << Locality.new(type, from, to)
186
- end
187
- [RelatonBib::Extent.new(locs)]
188
- end
189
-
190
- # @param bibtex [BibTeX::Entry]
191
- # @return [Array<RelatonBib::Series>]
192
- def fetch_series(bibtex) # rubocop:disable Metrics/MethodLength
193
- series = []
194
- if bibtex["journal"]
195
- series << Series.new(
196
- type: "journal",
197
- title: TypedTitleString.new(content: bibtex.journal.to_s),
198
- number: bibtex["number"]&.to_s
199
- )
200
- end
201
-
202
- if bibtex["series"]
203
- title = TypedTitleString.new content: bibtex.series.to_s
204
- series << Series.new(title: title)
205
- end
206
- series
207
- end
208
-
209
- # @param bibtex [BibTeX::Entry]
210
- # @return [Array<RelatonBib::TypedUri>]
211
- def fetch_link(bibtex) # rubocop:disable Metrics/AbcSize
212
- link = []
213
- link << TypedUri.new(type: "src", content: bibtex.url.to_s) if bibtex["url"]
214
- link << TypedUri.new(type: "doi", content: bibtex.doi.to_s) if bibtex["doi"]
215
- link << TypedUri.new(type: "file", content: bibtex.file2.to_s) if bibtex["file2"]
216
- link
217
- end
218
-
219
- # @param bibtex [BibTeX::Entry]
220
- # @return [Array<String>]
221
- def fetch_language(bibtex)
222
- return [] unless bibtex["language"]
223
-
224
- [Iso639[bibtex.language.to_s].alpha2]
225
- end
226
-
227
- # @param bibtex [BibTeX::Entry]
228
- # @return [RelatonBib::Classification, nil]
229
- def fetch_classification(bibtex)
230
- cls = []
231
- cls << Classification.new(type: "type", value: bibtex["type"].to_s) if bibtex["type"]
232
- # cls << Classification.new(type: "keyword", value: bibtex.keywords.to_s) if bibtex["keywords"]
233
- if bibtex["mendeley-tags"]
234
- cls << Classification.new(type: "mendeley", value: bibtex["mendeley-tags"].to_s)
235
- end
236
- cls
237
- end
238
-
239
- # @param bibtex [BibTeX::Entry]
240
- # @return [Array<String>]
241
- def fetch_keyword(bibtex)
242
- bibtex["keywords"]&.split(/,\s?/) || []
243
- end
244
- end
245
- end
246
- end