relaton-un 1.20.1 → 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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +1 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +1 -1
  5. data/CLAUDE.md +77 -0
  6. data/README.adoc +51 -39
  7. data/grammars/basicdoc.rng +1559 -671
  8. data/grammars/biblio-standoc.rng +107 -46
  9. data/grammars/biblio.rng +1010 -375
  10. data/grammars/relaton-un.rng +0 -15
  11. data/lib/relaton/un/bibdata.rb +7 -0
  12. data/lib/relaton/un/bibitem.rb +7 -0
  13. data/lib/relaton/un/bibliography.rb +48 -0
  14. data/lib/relaton/un/doctype.rb +10 -0
  15. data/lib/relaton/un/ext.rb +30 -0
  16. data/lib/relaton/un/hit.rb +56 -0
  17. data/lib/relaton/un/hit_collection.rb +61 -0
  18. data/lib/relaton/un/item.rb +11 -0
  19. data/lib/relaton/un/item_data.rb +6 -0
  20. data/lib/relaton/un/parser.rb +108 -0
  21. data/lib/relaton/un/processor.rb +38 -0
  22. data/lib/relaton/un/session.rb +25 -0
  23. data/lib/relaton/un/token_generator.rb +159 -0
  24. data/lib/relaton/un/util.rb +8 -0
  25. data/lib/relaton/un/version.rb +5 -0
  26. data/lib/relaton/un/wasm_v_bg.wasm +0 -0
  27. data/lib/relaton/un.rb +28 -0
  28. data/relaton_un.gemspec +9 -9
  29. data/resp.html +10 -10
  30. metadata +46 -30
  31. data/lib/relaton_un/document_type.rb +0 -19
  32. data/lib/relaton_un/editorialgroup.rb +0 -38
  33. data/lib/relaton_un/hash_converter.rb +0 -50
  34. data/lib/relaton_un/hit.rb +0 -150
  35. data/lib/relaton_un/hit_collection.rb +0 -203
  36. data/lib/relaton_un/processor.rb +0 -41
  37. data/lib/relaton_un/session.rb +0 -87
  38. data/lib/relaton_un/un_bibliographic_item.rb +0 -96
  39. data/lib/relaton_un/un_bibliography.rb +0 -48
  40. data/lib/relaton_un/util.rb +0 -6
  41. data/lib/relaton_un/version.rb +0 -3
  42. data/lib/relaton_un/xml_parser.rb +0 -66
  43. data/lib/relaton_un.rb +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6560e3649781f334dc28f9c4e5d7e7781bead476afe352e82e2c3b4585559cff
4
- data.tar.gz: ee9a9eb72db2871de51ef08bde79314c927360c5cd52f368341f2f966ea651f2
3
+ metadata.gz: d329d6b49f77f6a2fd2a1ed6b1ccc1204074e5f9415d948de9352361af97cb7b
4
+ data.tar.gz: 64946c2287d40673e5fbd186c542f9a7e47cf53c0082c0a62f6f150e7af63e80
5
5
  SHA512:
6
- metadata.gz: f23749670c7895c400f9a26d53820f47b0c557a40865936085d41baef7c98564c019e4c9a89a5a25b96e03cac2510798d4a6c6ca03ce56f9571ca07696202b02
7
- data.tar.gz: 5501430f6b938e2dbb824e83f7d678200ba0c91c97bcd94335932060b43edf32d5febfc4c8fe62b9b861a21dd3a400fc4501a01de8ed619a765f999a3b08a91e
6
+ metadata.gz: 485f49c382375e5b4b91775562d62e456b5a9066eb4d728eb8c018b9121fd94c768cfa8f8f4bc7cdfb315f1e78a9d7eafa610f29ecec1f1b711258603dd1ad18
7
+ data.tar.gz: dbb0cb1629ab456306d0746602e687c3d977b20eadb55331c523ccc7207ee72ed2af4bbe803bf413b39e79b053c7ccccdcb4c203d061d2c57731d99f0880a18a
@@ -7,6 +7,7 @@ on:
7
7
  branches: [ master, main ]
8
8
  tags: [ v* ]
9
9
  pull_request:
10
+ workflow_dispatch:
10
11
 
11
12
  jobs:
12
13
  rake:
data/.gitignore CHANGED
@@ -14,3 +14,4 @@
14
14
  .vscode/
15
15
  .byebug_history
16
16
  Gemfile.lock
17
+ .claude/
data/.rubocop.yml CHANGED
@@ -7,6 +7,6 @@ require: rubocop-rails
7
7
  inherit_from:
8
8
  - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
9
9
  AllCops:
10
- TargetRubyVersion: 2.7
10
+ TargetRubyVersion: 3.2
11
11
  Rails:
12
12
  Enabled: false
data/CLAUDE.md ADDED
@@ -0,0 +1,77 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ relaton-un is a Ruby gem that provides bibliographic data models for UN documents, part of the Relaton family of gems. It extends `relaton-bib` with UN-specific metadata using the LutaML-Model serialization framework. Currently on the `lutaml-integration` branch undergoing a major migration from the old `RelatonUn` namespace to `Relaton::Un`.
8
+
9
+ ## Commands
10
+
11
+ ```bash
12
+ # Install dependencies
13
+ bundle install
14
+
15
+ # Run all tests (also the default rake task)
16
+ bundle exec rake spec
17
+
18
+ # Run a specific test file
19
+ bundle exec rspec spec/relaton/un/bibitem_spec.rb
20
+
21
+ # Run a specific test by line number
22
+ bundle exec rspec spec/relaton/un/bibitem_spec.rb:7
23
+
24
+ # Lint
25
+ bundle exec rubocop
26
+
27
+ # Interactive console with gem loaded
28
+ bin/console
29
+ ```
30
+
31
+ ## Architecture
32
+
33
+ ### Flavor Model Pattern
34
+
35
+ The gem follows the Relaton flavor pattern: base classes from `relaton-bib` (`Bib::Item`) are extended with a flavor-specific `Ext` class containing UN-specific metadata.
36
+
37
+ ```
38
+ Bib::ItemData (from relaton-bib)
39
+ └── Relaton::Un::ItemData # UN flavor identity, enables NamespaceHelper#namespace → Relaton::Un
40
+
41
+ Bib::Item (from relaton-bib)
42
+ └── Relaton::Un::Item # model ItemData; adds Ext attribute
43
+ ├── Relaton::Un::Bibitem # includes Bib::BibitemShared (for <bibitem> XML)
44
+ └── Relaton::Un::Bibdata # includes Bib::BibdataShared (for <bibdata> XML)
45
+ ```
46
+
47
+ ### Key Classes (all in `lib/relaton/un/`)
48
+
49
+ - **ItemData** — extends `Bib::ItemData`; the UN-specific data container used by `Item` via `model ItemData`
50
+ - **Item** — extends `Bib::Item`, adds `ext` attribute of type `Ext`
51
+ - **Bibitem / Bibdata** — extend Item with shared mixins for two XML serialization formats
52
+ - **Ext** — UN-specific metadata: `doctype`, `distribution`, `session`, `submissionlanguage`, `job_number`; extends `Bib::Ext`
53
+ - **Session** — session metadata (number, date, item numbers/names, collaborator, agenda_id)
54
+ - **Doctype** — restricts document types to: recommendation, plenary, addendum, communication, corrigendum, reissue, agenda, budgetary, sec-gen-notes, expert-report, resolution
55
+
56
+ ### LutaML-Model Serialization
57
+
58
+ All model classes use `Lutaml::Model::Serializable`. XML mappings are defined in `xml do` blocks:
59
+ - `map_attribute` for XML attributes (e.g., `schema-version` → `schema_version`)
60
+ - `map_element` for XML elements (e.g., `session-date` → `session_date`)
61
+ - `collection: true` for array attributes
62
+ - `values: [...]` for restricted string values
63
+
64
+ ### Schema Validation
65
+
66
+ RelaxNG grammars in `grammars/` validate XML output. The compiled schema is `grammars/relaton-un-compile.rng`. Tests use `ruby-jing` for validation.
67
+
68
+ ### Testing Approach
69
+
70
+ Tests are round-trip serialization tests: load a fixture, serialize to XML/YAML, compare against the original fixture. Bibitem and Bibdata specs also validate XML against the RelaxNG schema. Fixtures live in `spec/fixtures/`.
71
+
72
+ ## Dependencies
73
+
74
+ - **relaton-bib** (~> 2.0.0-alpha.1) — base bibliographic model with LutaML-Model integration
75
+ - **faraday** — HTTP client
76
+ - **ruby-jing** (dev) — RelaxNG schema validation in tests
77
+ - **equivalent-xml** (dev) — XML comparison in tests
data/README.adoc CHANGED
@@ -1,8 +1,8 @@
1
1
  = Relaton for UN documents
2
2
 
3
- RelatonCalconnect is a Ruby gem that implements the https://github.com/metanorma/metanorma-model-iso#iso-bibliographic-item[IsoBibliographicItem model].
3
+ RelatonUn is a Ruby gem that implements the https://github.com/metanorma/metanorma-model-iso#iso-bibliographic-item[IsoBibliographicItem model].
4
4
 
5
- You can use it to retrieve metadata of Calconnect Standards from https://standards.calconnect.org, and access such metadata through the `CcBibliographicItem` object.
5
+ You can use it to retrieve metadata of UN documents from https://documents.un.org, and access such metadata through the `Relaton::Un::Item` object.
6
6
 
7
7
  == Installation
8
8
 
@@ -27,14 +27,14 @@ Or install it yourself as:
27
27
 
28
28
  [source,ruby]
29
29
  ----
30
- require 'relaton_un'
30
+ require 'relaton/un'
31
31
  => true
32
32
 
33
- hits = RelatonUn::UnBibliography.search("TRADE/CEFACT/2004/32")
34
- => <RelatonUn::HitCollection:0x007fc4e6ec2018 @ref=TRADE/CEFACT/2004/32 @fetched=false>
33
+ hits = Relaton::Un::Bibliography.search("TRADE/CEFACT/2004/32")
34
+ => <Relaton::Un::HitCollection:0x00000000001660 @ref=TRADE/CEFACT/2004/32 @fetched=false>
35
35
 
36
- item = hits[0].fetch
37
- => #<RelatonUn::UnBibliographicItem:0x007fc4e6ac3138
36
+ item = hits[0].item
37
+ => #<Relaton::Un::Item:0x000000012385aa60
38
38
  ...
39
39
  ----
40
40
 
@@ -43,24 +43,43 @@ item = hits[0].fetch
43
43
  [source,ruby]
44
44
  ----
45
45
  item.to_xml
46
- => "<bibitem id="TRADE-CEFACT-2004-32" type="standard" schema-version="v1.2.1">
47
- <fetched>2022-12-05</fetched>
48
- ...
46
+ => "<bibitem id="TRADECEFACT200432" type="standard" schema-version="v1.4.1">
47
+ <fetched>2026-03-03</fetched>
48
+ <title language="en" script="Latn" type="title-main"/>
49
+ <title language="en" script="Latn" type="main"/>
50
+ <uri type="pdf">https://documents.un.org/api/symbol/access?j=G0430683&amp;t=pdf</uri>
51
+ <docidentifier type="UN" primary="true">TRADE/CEFACT/2004/32</docidentifier>
52
+ <docnumber>TRADE/CEFACT/2004/32</docnumber>
53
+ <date type="published">
54
+ <on>2004-03-18</on>
55
+ </date>
56
+ <language>en</language>
57
+ <script>Latn</script>
49
58
  </bibitem>"
50
59
  ----
51
60
  With argument `bibdata: true` it outputs XML wrapped by `bibdata` element and adds flavor `ext` element.
52
61
  [source,ruby]
53
62
  ----
54
63
  item.to_xml bibdata: true
55
- => "<bibdata type="standard" schema-version="v1.2.1">
56
- <fetched>2022-12-05</fetched>
57
- ...
64
+ => "<bibdata type="standard" schema-version="v1.4.1">
65
+ <fetched>2026-03-03</fetched>
66
+ <title language="en" script="Latn" type="title-main"/>
67
+ <title language="en" script="Latn" type="main"/>
68
+ <uri type="pdf">https://documents.un.org/api/symbol/access?j=G0430683&amp;t=pdf</uri>
69
+ <docidentifier type="UN" primary="true">TRADE/CEFACT/2004/32</docidentifier>
70
+ <docnumber>TRADE/CEFACT/2004/32</docnumber>
71
+ <date type="published">
72
+ <on>2004-03-18</on>
73
+ </date>
74
+ <language>en</language>
75
+ <script>Latn</script>
58
76
  <ext schema-version="v1.0.0">
59
- <editorialgroup>
60
- <committee>Committee on Trade</committee>
61
- <committee>Centre for Trade Facilitation and Electronic Business</committee>
62
- </editorialgroup>
63
- ...
77
+ <distribution>general</distribution>
78
+ <session>
79
+ <number>10</number>
80
+ <agenda-id>12</agenda-id>
81
+ </session>
82
+ <job_number>G0430683</job_number>
64
83
  </ext>
65
84
  </bibdata>"
66
85
  ----
@@ -68,46 +87,39 @@ item.to_xml bibdata: true
68
87
  === Get code, and year
69
88
  [source,ruby]
70
89
  ----
71
- RelatonUn::UnBibliography.get "UN TRADE/CEFACT/2004/32"
72
- [relaton-un] (UN TRADE/CEFACT/2004/32) Fetching from documents.un.org ...
73
- [relaton-un] (UN TRADE/CEFACT/2004/32) Found: `TRADE/CEFACT/2004/32`
74
- => #<RelatonUn::UnBibliographicItem:0x007fdc5f1c3a20
90
+ Relaton::Un::Bibliography.get "UN TRADE/CEFACT/2004/32"
91
+ [relaton-un] INFO: (UN TRADE/CEFACT/2004/32) Fetching from documents.un.org ...
92
+ [relaton-un] INFO: (UN TRADE/CEFACT/2004/32) Found: `TRADE/CEFACT/2004/32`
93
+ => #<Relaton::Un::ItemData:0x0000000127d9c448
75
94
  ...
76
95
  ----
77
96
 
78
97
  === Typed links
79
98
 
80
- UN documens may have `pdf` and `word` link types.
99
+ UN documens may have `pdf` and `word` source link types.
81
100
 
82
101
  [source,ruby]
83
102
  ----
84
- item.link
85
- => [#<RelatonBib::TypedUri:0x00007f81af368250
86
- @content=#<Addressable::URI:0x9ec URI:https://documents-dds-ny.un.org/doc/UNDOC/GEN/G04/306/83/pdf/G0430683.pdf?OpenElement>, @type="pdf">,
87
- #<RelatonBib::TypedUri:0x00007f81af3630e8 @content=#<Addressable::URI:0xa00 URI:https://documents-dds-ny.un.org/doc/UNDOC/GEN/G04/306/83/doc/G0430683.DOC?OpenElement>, @type="word">]
103
+ item.source[0].type
104
+ => "pdf"
105
+
106
+ item.source[0].content
107
+ => "https://documents.un.org/api/symbol/access?j=G0430683&t=pdf"
88
108
  ----
89
109
 
90
110
  === Create bibliographic item from XML
91
111
  [source,ruby]
92
112
  ----
93
- RelatonUn::XMLParser.from_xml File.read('spec/fixtures/un_bib.xml')
94
- => #<RelatonUn::UnBibliographicItem:0x007fdc5e7ab678
113
+ Relaton::Un::Bibdata.from_xml File.read('spec/fixtures/bibdata.xml')
114
+ => #<Relaton::Bib::ItemData:0x000000012772a448
95
115
  ...
96
116
  ----
97
117
 
98
118
  === Create bibliographic item from YAML
99
119
  [source,ruby]
100
120
  ----
101
- hash = YAML.load_file 'spec/fixtures/un_bib.yaml'
102
- => {"id"=>"TRADE/CEFACT/2004/32",
103
- ...
104
-
105
- bib_hash = RelatonUn::HashConverter.hash_to_bib hash
106
- => {:id=>"TRADE/CEFACT/2004/32",
107
- ...
108
-
109
- RelatonUn::UnBibliographicItem.new **bib_hash
110
- => #<RelatonUn::UnBibliographicItem:0x007fdc5e061908
121
+ Relaton::Un::Item.from_yaml File.read('spec/fixtures/item.yaml')
122
+ => #<Relaton::Un::ItemData:0x0000000127d7a140
111
123
  ...
112
124
  ----
113
125