relaton-cli 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bfce91270bd957a41eb9ef66a7ece0eb1ba02b1f
4
- data.tar.gz: e9d98aca4fae3ab0f7c190e3b34c3203ba6f2f9f
3
+ metadata.gz: '080ef2cfe08edfba51c903c9ce1d11bdf888257f'
4
+ data.tar.gz: 338339afba81aee2d161fa677708a0cff46abe68
5
5
  SHA512:
6
- metadata.gz: 9750ec75dc8064f8e003973c577ebe4ed3515f4e1069acb9fd09779a019f2fa68e32282403a00318bf823a799af6e717b45737bf3ba8d8ccf04ec87c6a99b4bd
7
- data.tar.gz: e662791c6045d76b62e818790fe98fdf98df4374eddd8861c94c6c4313288970a02aa722388121c2819c428a35f9c65e94d498acf4c2eff6bc927517ad48cbc7
6
+ metadata.gz: aa6ff088313b823a22ee62c19c0906f718af15f0202ae9785c2b9eaa63d2303c113e0158abe208daa0bb59c68bcd785318bcb253ec2ed9ec28866a08dc915723
7
+ data.tar.gz: 1b03e8509251c6893c778fb134effc0221bdd0f3c103a5bc06b6064fb9dfd9c8fa0749383657e4a0a088854b6cb89aff7bcc3de14aba542bad2092953efc13da
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- relaton-cli (0.3.5)
4
+ relaton-cli (0.3.6)
5
5
  liquid
6
6
  relaton (~> 0.5)
7
7
  thor
@@ -38,7 +38,7 @@ GEM
38
38
  method_source (~> 0.9.0)
39
39
  public_suffix (4.0.1)
40
40
  rake (12.3.3)
41
- relaton (0.5.4)
41
+ relaton (0.5.5)
42
42
  relaton-gb (~> 0.6.0)
43
43
  relaton-iec (~> 0.4.0)
44
44
  relaton-ietf (~> 0.6.0)
@@ -46,31 +46,31 @@ GEM
46
46
  relaton-itu (~> 0.3.0)
47
47
  relaton-nist (~> 0.3.0)
48
48
  relaton-ogc (~> 0.1.0)
49
- relaton-bib (0.3.6)
49
+ relaton-bib (0.3.8)
50
50
  addressable
51
51
  nokogiri
52
- relaton-gb (0.6.3)
52
+ relaton-gb (0.6.4)
53
53
  cnccs (~> 0.1.1)
54
54
  gb-agencies (~> 0.0.1)
55
55
  relaton-iso-bib (~> 0.3.0)
56
- relaton-iec (0.4.4)
56
+ relaton-iec (0.4.6)
57
57
  addressable
58
58
  relaton-iso-bib (~> 0.3.0)
59
- relaton-ietf (0.6.4)
59
+ relaton-ietf (0.6.5)
60
60
  relaton-bib (~> 0.3.0)
61
- relaton-iso (0.6.5)
61
+ relaton-iso (0.6.6)
62
62
  relaton-iec (~> 0.4.0)
63
63
  relaton-iso-bib (~> 0.3.0)
64
- relaton-iso-bib (0.3.5)
64
+ relaton-iso-bib (0.3.7)
65
65
  isoics (~> 0.1.6)
66
66
  relaton-bib (~> 0.3.0)
67
67
  ruby_deep_clone (~> 0.8.0)
68
- relaton-itu (0.3.3)
68
+ relaton-itu (0.3.4)
69
69
  relaton-iso-bib (~> 0.3.0)
70
- relaton-nist (0.3.4)
70
+ relaton-nist (0.3.5)
71
71
  relaton-bib (~> 0.3.0)
72
72
  rubyzip
73
- relaton-ogc (0.1.0)
73
+ relaton-ogc (0.1.1)
74
74
  faraday
75
75
  relaton-iso-bib (~> 0.3.0)
76
76
  rspec (3.8.0)
@@ -96,7 +96,7 @@ GEM
96
96
  ruby-debug-ide (0.7.0)
97
97
  rake (>= 0.8.1)
98
98
  ruby_deep_clone (0.8.0)
99
- rubyzip (1.2.4)
99
+ rubyzip (2.0.0)
100
100
  simplecov (0.17.0)
101
101
  docile (~> 1.1)
102
102
  json (>= 1.8, < 3)
data/docs/README.adoc CHANGED
@@ -201,7 +201,269 @@ Convert a Relaton XML file (`filename.xml` or `filename.rxl`) into a Relaton YAM
201
201
 
202
202
  [source,console]
203
203
  ----
204
- $ relaton yaml2xml Relaton-YAML [<stylesheet>] [<liquid-template-dir>]
204
+ $ relaton yaml2xml <filename.yaml> [<stylesheet>] [<liquid-template-dir>]
205
205
  ----
206
206
 
207
- Render a Relaton YAML file as an HTML file. The stylesheet and liquid-template-dir directories are as for <<relaton-xml2html,relaton xml2html>>.
207
+ Render a Relaton YAML file (`filename.yaml`) as an HTML file. The stylesheet and liquid-template-dir directories are as for <<relaton-xml2html,relaton xml2html>>.
208
+
209
+ === relaton yaml2xmlnew
210
+
211
+ [source,console]
212
+ ----
213
+ $ relaton yaml2xmlnew <filename.yaml> -o OUTPUT-DIRECTORY -x RELATON_EXTENSION -p PREFIX -r LIBRARY
214
+ ----
215
+
216
+ Convert a Relaton YAML file (`filename.yaml`) in a new format into a Relaton XML file (`filename.xml`). If the Relaton YAML file specifies multiple bibliograph items, and `OUTPUT-DIRECTORY` is nominated, also convert the file into a list of Relaton XML files for each entry, stored in that directory. The document identifier is used as the name of each Relaton XML file; the Relaton XML filename is suffixed with `RELATON_EXTENSION` (default `.rxl`) and prefixed with `PREFIX` (default empty). Any libraries that need to be required for the conversion are specified in `LIBRARY` as a space-delimited list.
217
+
218
+ A Relaton Colleciton YAML file contains some initial metadata, and a list of metadata about each bibliographic entry:
219
+
220
+ [source,yaml]
221
+ ----
222
+ root:
223
+ author: The Calendaring and Scheduling Consortium
224
+ title: CalConnect Standards Registry
225
+ items:
226
+ - technical_committee: PUBLISH
227
+ docid:
228
+ type: CC
229
+ id: CC 36000
230
+ type: standard
231
+ title:
232
+ type: main
233
+ content: Standardization documents -- Vocabulary
234
+ docstatus:
235
+ stage: proposal
236
+ date:
237
+ type: issued
238
+ value: 2018-10-25
239
+ - technical_committee: DATETIME
240
+ docid:
241
+ type: CC
242
+ id: CC 34000
243
+ type: standard
244
+ title:
245
+ type: main
246
+ content: Date and time -- Concepts and vocabulary
247
+ docstatus:
248
+ stage: proposal
249
+ date:
250
+ type: issued
251
+ value: 2018-10-25
252
+ ----
253
+
254
+ A Relaton YAML file describing an individual bibliographic entry is limited to metadata specific to that entry. Flavor gems have aditional fields. The following illustrates the common fields supported by all flavor gems (see link:https://github.com/relaton/relaton-bib/blob/master/docs/hash.adoc#yaml[Relaton YAML]):
255
+
256
+ [source,yaml]
257
+ ----
258
+ ---
259
+ id: ISO/TC211
260
+ title:
261
+ - type: main
262
+ content: Geographic information
263
+ language: en
264
+ script: Latn
265
+ format: text/plain
266
+ - content: Information géographique
267
+ language: fr
268
+ script: Latn
269
+ format: text/plain
270
+ link:
271
+ - type: src
272
+ content: https://www.iso.org/standard/53798.html
273
+ - type: obp
274
+ content: https://www.iso.org/obp/ui/#!iso:std:53798:en
275
+ - type: rss
276
+ content: https://www.iso.org/contents/data/standard/05/37/53798.detail.rss
277
+ type: standard
278
+ docid:
279
+ id: TC211
280
+ type: ISO
281
+ docnumber: '123456'
282
+ date:
283
+ - type: issued
284
+ value: '2014-01-01'
285
+ - type: published
286
+ value: '2014-04-01'
287
+ - type: accessed
288
+ value: '2015-05-20'
289
+ contributor:
290
+ - organization:
291
+ name: International Organization for Standardization
292
+ abbreviation: ISO
293
+ subdivision: division
294
+ url: www.iso.org
295
+ role:
296
+ description: Publisher role
297
+ type: publisher
298
+ - person:
299
+ name:
300
+ completename:
301
+ content: A. Bierman
302
+ language: en
303
+ affiliation:
304
+ organization:
305
+ name: IETF
306
+ abbreviation: IETF
307
+ identifier:
308
+ type: uri
309
+ id: www.ietf.org
310
+ contact:
311
+ - street:
312
+ - Street
313
+ city: City
314
+ state: State
315
+ country: Country
316
+ postcode: '123456'
317
+ - type: phone
318
+ value: '223322'
319
+ role: author
320
+ - organization:
321
+ name: IETF
322
+ abbreviation: IETF
323
+ identifier:
324
+ type: uri
325
+ id: www.ietf.org
326
+ role: publisher
327
+ - person:
328
+ name:
329
+ forename:
330
+ content: Forename
331
+ language: en
332
+ initial:
333
+ content: A.
334
+ language: en
335
+ surname:
336
+ content: Bierman
337
+ language: en
338
+ addition:
339
+ content: Addition
340
+ language: en
341
+ prefix:
342
+ content: Prefix
343
+ language: en
344
+ affiliation:
345
+ organization:
346
+ name: IETF
347
+ abbreviation: IETF
348
+ description:
349
+ content: Description
350
+ language: en
351
+ identifier:
352
+ type: uri
353
+ id: www.person.com
354
+ contact:
355
+ - street:
356
+ - Street
357
+ city: City
358
+ state: State
359
+ country: Country
360
+ postcode: '123456'
361
+ - type: phone
362
+ value: '223322'
363
+ role: author
364
+ edition: '1'
365
+ version:
366
+ revision_date: '2019-04-01'
367
+ draft: draft
368
+ biblionote:
369
+ content: note
370
+ type: bibnote
371
+ language:
372
+ - en
373
+ - fr
374
+ script: Latn
375
+ abstract:
376
+ - content: ISO 19115-1:2014 defines the schema required for ...
377
+ language: en
378
+ script: Latn
379
+ format: text/plain
380
+ - content: L'ISO 19115-1:2014 définit le schéma requis pour ...
381
+ language: fr
382
+ script: Latn
383
+ format: text/plain
384
+ docstatus:
385
+ stage: stage
386
+ substage: substage
387
+ iteration: final
388
+ copyright:
389
+ owner:
390
+ name: International Organization for Standardization
391
+ abbreviation: ISO
392
+ url: www.iso.org
393
+ from: '2014'
394
+ to: '2020'
395
+ relation:
396
+ - type: updates
397
+ bibitem:
398
+ formattedref:
399
+ content: ISO 19115:2003
400
+ format: text/plain
401
+ bib_locality:
402
+ type: updates
403
+ reference_from: Reference form
404
+ - type: updates
405
+ bibitem:
406
+ type: standard
407
+ formattedref:
408
+ content: ISO 19115:2003/Cor 1:2006
409
+ format: text/plain
410
+ series:
411
+ - type: main
412
+ title:
413
+ type: original
414
+ content: ISO/IEC FDIS 10118-3
415
+ language: en
416
+ script: Latn
417
+ format: text/plain
418
+ place: Serie's place
419
+ organization: Serie's organization
420
+ abbreviation: ABVR
421
+ from: '2009-02-01'
422
+ to: '2010-12-20'
423
+ number: serie1234
424
+ partnumber: part5678
425
+ - type: alt
426
+ formattedref:
427
+ content: serieref
428
+ language: en
429
+ script: Latn
430
+ format: text/plain
431
+ medium:
432
+ form: medium form
433
+ size: medium size
434
+ scale: medium scale
435
+ place: bib place
436
+ extent:
437
+ type: section
438
+ reference_from: Reference from
439
+ reference_to: Reference to
440
+ accesslocation:
441
+ - accesslocation1
442
+ - accesslocation2
443
+ classification:
444
+ value: value
445
+ type: type
446
+ validity:
447
+ begins: 2010-10-10 12:21
448
+ ends: 2011-02-03 18:30
449
+ revision: 2011-03-04 09:00
450
+ fetched: '2019-08-16'
451
+ ----
452
+
453
+ === relaton xml2yamlnew
454
+
455
+ [source,console]
456
+ ----
457
+ $ relaton xml2yamlnew <filename.xml> -o OUTPUT-DIRECTORY -x RELATON_EXTENSION -p PREFIX -r LIBRARY
458
+ ----
459
+
460
+ Convert a Relaton XML file (`filename.xml` or `filename.rxl`) into a Relaton YAML file (`filename.yaml`) in a new format. If the Relaton XML file is a collection, and `OUTPUT-DIRECTORY` is nominated, also convert the file into a list of Relaton YAML files for each entry, stored in that directory. The document identifier is used as the name of each Relaton XML file; the Relaton XML filename is suffixed with `RELATON_EXTENSION` (default `.yaml`) and prefixed with `PREFIX` (default empty). Any libraries that need to be required for the conversion are specified in `LIBRARY` as a space-delimited list.
461
+
462
+ === relaton yaml2htmlnew
463
+
464
+ [source,console]
465
+ ----
466
+ $ relaton yaml2xmlnew <filename.yaml> [<stylesheet>] [<liquid-template-dir>]
467
+ ----
468
+
469
+ Render a Relaton YAML file in a new format (`filename.yaml`) as an HTML file. The `stylesheet` and `liquid-template-dir` directories are as for <<relaton xml2html,relaton xml2html>>.
@@ -1,5 +1,6 @@
1
1
  require "relaton/cli/relaton_file"
2
2
  require "relaton/cli/xml_convertor"
3
+ require "relaton/cli/xml_convertor_new"
3
4
  require "relaton/cli/yaml_convertor"
4
5
  require "relaton/cli/yaml_convertor_new"
5
6
  require "fcntl"
@@ -72,6 +73,17 @@ module Relaton
72
73
  Relaton::Cli::XMLConvertor.to_yaml(filename, options)
73
74
  end
74
75
 
76
+ desc "xml2yamlnew XML", "Convert Relaton XML into Relaton Bibdata / Bibcollection YAML (and separate files)"
77
+ option :extension, aliases: :x, desc: "File extension of Relaton YAML files, defaults to 'yaml'"
78
+ option :prefix, aliases: :p, desc: "Filename prefix of Relaton XML files, defaults to empty"
79
+ option :outdir, aliases: :o, desc: "Output to the specified directory with individual Relaton Bibdata YAML files"
80
+ option :require, aliases: :r, type: :array, desc: "Require LIBRARY prior to execution"
81
+ option :overwrite, aliases: :f, type: :boolean, default: false, desc: "Overwrite the existing file"
82
+
83
+ def xml2yamlnew(filename)
84
+ Relaton::Cli::XMLConvertorNew.to_yaml(filename, options)
85
+ end
86
+
75
87
  desc "xml2html RELATON-INDEX-XML", "Convert Relaton Collection XML into HTML"
76
88
  option :stylesheet, aliases: :s, desc: "Stylesheet file path for rendering HTML index"
77
89
  option :templatedir, aliases: :t, desc: "Liquid template directory for rendering Relaton items and collection"
@@ -1,5 +1,5 @@
1
1
  module Relaton
2
2
  module Cli
3
- VERSION = "0.3.5".freeze
3
+ VERSION = "0.3.6".freeze
4
4
  end
5
5
  end
@@ -0,0 +1,76 @@
1
+ require "nokogiri"
2
+ require "relaton/cli/base_convertor"
3
+
4
+ module Relaton
5
+ module Cli
6
+ class XMLConvertorNew < Relaton::Cli::BaseConvertor
7
+ def to_yaml
8
+ convert_and_write(file_content, :to_yaml)
9
+ end
10
+
11
+ # Convert to YAML
12
+ #
13
+ # This interface allow us to convert any XML file to YAML.
14
+ # It only require us to provide a valid XML file and it can
15
+ # do converstion using default attributes, but it also allow
16
+ # us to provide custom options to customize this converstion
17
+ # process.
18
+ #
19
+ # @param file [File] The complete path to a XML file
20
+ # @param options [Hash] Options as hash key, value pairs.
21
+ #
22
+ def self.to_yaml(file, options = {})
23
+ new(file, options).to_yaml
24
+ end
25
+
26
+ private
27
+
28
+ def default_ext
29
+ "yaml"
30
+ end
31
+
32
+ # @param content [Nokogiri::XML::Document]
33
+ # @return [Hash]
34
+ def convert_content(content)
35
+ if content.root.name == "bibdata"
36
+ # Bibdata.from_xml(content.to_s)
37
+ convert_bibdata content
38
+ else
39
+ # Bibcollection.from_xml(content)
40
+ title = content.at("relaton-collection/title").text
41
+ author = content.at("relaton-collection/contributor/organization/name").text
42
+ collection = { "root" => { "title" => title, "author" => author } }
43
+
44
+ collection["root"]["items"] = content.xpath("//bibdata").map do |bib|
45
+ convert_bibdata bib
46
+ end
47
+
48
+ collection
49
+ end
50
+ end
51
+
52
+ # @param content [Nokogiri::XML::Document]
53
+ # @return [Hash]
54
+ def convert_bibdata(doc)
55
+ if (processor = Relaton::Registry.instance.by_type(doctype(doc)))
56
+ processor.from_xml(doc.to_s).to_hash
57
+ else
58
+ RelatonBib::XMLParser.from_xml(doc.to_s).to_hash
59
+ end
60
+ end
61
+
62
+ # @param content [Nokogiri::XML::Document]
63
+ # @return [String]
64
+ def doctype(doc)
65
+ docid = doc.at "//docidentifier"
66
+ return docid[:type] if docid && docid[:type]
67
+
68
+ docid.text.match(/^\w+/).to_s
69
+ end
70
+
71
+ def file_content
72
+ Nokogiri::XML(File.read(file, encoding: "utf-8")).remove_namespaces!
73
+ end
74
+ end
75
+ end
76
+ end
@@ -47,14 +47,22 @@ module Relaton
47
47
  end
48
48
 
49
49
  def convert_single_file(content)
50
- docid = content["docid"].is_a?(Array) ? content["docid"][0] : content["docid"]
51
- if (processor = Relaton::Registry.instance.by_type(docid["type"]))
50
+ if (processor = Relaton::Registry.instance.by_type(doctype(content["docid"])))
52
51
  processor.hash_to_bib content
53
52
  else
54
53
  RelatonBib::BibliographicItem.new(RelatonBib::HashConverter::hash_to_bib(content))
55
54
  end
56
55
  end
57
56
 
57
+ # @param content [Nokogiri::XML::Document]
58
+ # @return [String]
59
+ def doctype(docid)
60
+ did = docid.is_a?(Array) ? docid.fetch(0) : docid
61
+ return did["type"] if did && did["type"]
62
+
63
+ did&.fetch("id")&.match(/^\w+/)&.to_s
64
+ end
65
+
58
66
  def convert_collection(content)
59
67
  if content.has_key?("root")
60
68
  content["root"]["items"] = content["root"]["items"].map do |i|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-12 00:00:00.000000000 Z
11
+ date: 2019-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -230,6 +230,7 @@ files:
230
230
  - lib/relaton/cli/relaton_file.rb
231
231
  - lib/relaton/cli/version.rb
232
232
  - lib/relaton/cli/xml_convertor.rb
233
+ - lib/relaton/cli/xml_convertor_new.rb
233
234
  - lib/relaton/cli/xml_to_html_renderer.rb
234
235
  - lib/relaton/cli/yaml_convertor.rb
235
236
  - lib/relaton/cli/yaml_convertor_new.rb