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.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +1 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +1 -1
- data/CLAUDE.md +77 -0
- data/README.adoc +51 -39
- data/grammars/basicdoc.rng +1559 -671
- data/grammars/biblio-standoc.rng +107 -46
- data/grammars/biblio.rng +1010 -375
- data/grammars/relaton-un.rng +0 -15
- data/lib/relaton/un/bibdata.rb +7 -0
- data/lib/relaton/un/bibitem.rb +7 -0
- data/lib/relaton/un/bibliography.rb +48 -0
- data/lib/relaton/un/doctype.rb +10 -0
- data/lib/relaton/un/ext.rb +30 -0
- data/lib/relaton/un/hit.rb +56 -0
- data/lib/relaton/un/hit_collection.rb +61 -0
- data/lib/relaton/un/item.rb +11 -0
- data/lib/relaton/un/item_data.rb +6 -0
- data/lib/relaton/un/parser.rb +108 -0
- data/lib/relaton/un/processor.rb +38 -0
- data/lib/relaton/un/session.rb +25 -0
- data/lib/relaton/un/token_generator.rb +159 -0
- data/lib/relaton/un/util.rb +8 -0
- data/lib/relaton/un/version.rb +5 -0
- data/lib/relaton/un/wasm_v_bg.wasm +0 -0
- data/lib/relaton/un.rb +28 -0
- data/relaton_un.gemspec +9 -9
- data/resp.html +10 -10
- metadata +46 -30
- data/lib/relaton_un/document_type.rb +0 -19
- data/lib/relaton_un/editorialgroup.rb +0 -38
- data/lib/relaton_un/hash_converter.rb +0 -50
- data/lib/relaton_un/hit.rb +0 -150
- data/lib/relaton_un/hit_collection.rb +0 -203
- data/lib/relaton_un/processor.rb +0 -41
- data/lib/relaton_un/session.rb +0 -87
- data/lib/relaton_un/un_bibliographic_item.rb +0 -96
- data/lib/relaton_un/un_bibliography.rb +0 -48
- data/lib/relaton_un/util.rb +0 -6
- data/lib/relaton_un/version.rb +0 -3
- data/lib/relaton_un/xml_parser.rb +0 -66
- data/lib/relaton_un.rb +0 -26
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d329d6b49f77f6a2fd2a1ed6b1ccc1204074e5f9415d948de9352361af97cb7b
|
|
4
|
+
data.tar.gz: 64946c2287d40673e5fbd186c542f9a7e47cf53c0082c0a62f6f150e7af63e80
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 485f49c382375e5b4b91775562d62e456b5a9066eb4d728eb8c018b9121fd94c768cfa8f8f4bc7cdfb315f1e78a9d7eafa610f29ecec1f1b711258603dd1ad18
|
|
7
|
+
data.tar.gz: dbb0cb1629ab456306d0746602e687c3d977b20eadb55331c523ccc7207ee72ed2af4bbe803bf413b39e79b053c7ccccdcb4c203d061d2c57731d99f0880a18a
|
data/.github/workflows/rake.yml
CHANGED
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
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
|
-
|
|
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
|
|
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 '
|
|
30
|
+
require 'relaton/un'
|
|
31
31
|
=> true
|
|
32
32
|
|
|
33
|
-
hits =
|
|
34
|
-
=> <
|
|
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].
|
|
37
|
-
=> #<
|
|
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="
|
|
47
|
-
<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&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.
|
|
56
|
-
<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&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
|
-
<
|
|
60
|
-
|
|
61
|
-
<
|
|
62
|
-
|
|
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
|
-
|
|
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
|
-
=> #<
|
|
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.
|
|
85
|
-
=>
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
94
|
-
=> #<
|
|
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
|
-
|
|
102
|
-
=>
|
|
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
|
|