relaton-gb 1.20.2 → 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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/README.adoc +80 -75
  4. data/grammars/basicdoc.rng +1559 -671
  5. data/grammars/biblio-standoc.rng +107 -46
  6. data/grammars/biblio.rng +1000 -375
  7. data/grammars/relaton-gb.rng +0 -93
  8. data/lib/relaton/gb/bibdata.rb +7 -0
  9. data/lib/relaton/gb/bibitem.rb +7 -0
  10. data/lib/relaton/gb/bibliography.rb +145 -0
  11. data/lib/relaton/gb/ccs.rb +17 -0
  12. data/lib/relaton/gb/committee.rb +13 -0
  13. data/lib/relaton/gb/docidentifier.rb +23 -0
  14. data/lib/relaton/gb/doctype.rb +9 -0
  15. data/lib/relaton/gb/ext.rb +40 -0
  16. data/lib/relaton/gb/gb_scraper.rb +59 -0
  17. data/lib/relaton/gb/gb_type.rb +20 -0
  18. data/lib/relaton/gb/hit.rb +48 -0
  19. data/lib/relaton/gb/hit_collection.rb +19 -0
  20. data/lib/relaton/gb/item.rb +13 -0
  21. data/lib/relaton/gb/item_data.rb +6 -0
  22. data/lib/relaton/gb/processor.rb +45 -0
  23. data/lib/relaton/gb/project_number.rb +38 -0
  24. data/lib/relaton/gb/scraper.rb +203 -0
  25. data/lib/relaton/gb/sec_scraper.rb +98 -0
  26. data/lib/relaton/gb/stage_name.rb +13 -0
  27. data/lib/relaton/gb/structured_identifier.rb +26 -0
  28. data/lib/relaton/gb/t_scraper.rb +126 -0
  29. data/lib/relaton/gb/util.rb +8 -0
  30. data/lib/relaton/gb/version.rb +5 -0
  31. data/lib/relaton/gb.rb +33 -0
  32. data/relaton_gb.gemspec +7 -7
  33. metadata +43 -41
  34. data/CLAUDE.md +0 -74
  35. data/lib/relaton_gb/ccs.rb +0 -20
  36. data/lib/relaton_gb/document_type.rb +0 -16
  37. data/lib/relaton_gb/gb_bibliographic_item.rb +0 -139
  38. data/lib/relaton_gb/gb_bibliography.rb +0 -147
  39. data/lib/relaton_gb/gb_scrapper.rb +0 -59
  40. data/lib/relaton_gb/gb_standard_type.rb +0 -32
  41. data/lib/relaton_gb/gb_technical_committee.rb +0 -28
  42. data/lib/relaton_gb/hash_converter.rb +0 -45
  43. data/lib/relaton_gb/hit.rb +0 -46
  44. data/lib/relaton_gb/hit_collection.rb +0 -15
  45. data/lib/relaton_gb/processor.rb +0 -40
  46. data/lib/relaton_gb/scrapper.rb +0 -187
  47. data/lib/relaton_gb/sec_scrapper.rb +0 -96
  48. data/lib/relaton_gb/t_scrapper.rb +0 -125
  49. data/lib/relaton_gb/util.rb +0 -6
  50. data/lib/relaton_gb/version.rb +0 -5
  51. data/lib/relaton_gb/xml_parser.rb +0 -50
  52. data/lib/relaton_gb.rb +0 -27
  53. /data/lib/{relaton_gb → relaton/gb}/yaml/prefixes.yaml +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 545e535b0db62ecab737c3067cd5b3f8f2104560e104b1dc2cbc7c920ab7238b
4
- data.tar.gz: 3672fda5a7bb420fb5cc1086b60d46ce3b94f0ae4d9cf7759101f9b67cce2aac
3
+ metadata.gz: bc45456d59ae3857a4161bcf3ecff02c96a35e6919b53f1a7d2b4d7d386ddcd1
4
+ data.tar.gz: df75a3aa8d81d04a4a1f8f80f38346202eb38bf4b5b5ea1a0681b896e66571e3
5
5
  SHA512:
6
- metadata.gz: 74581dbf698e664f97cdfa66c1d4f948f2a14713eeb772ce20838a03f01fba1eb864afe5b6a4153f8fc80a32b30d3893bdbfa713667edd83c193f6bada37e533
7
- data.tar.gz: 3141ac12e00f11a00a44d4563a48e7aa16b7b762514dc63ca828f104191614c55ec75ab6cf2df7ccc0e860ab50ccc4d42665ce61e98fd49ae51e81d2fcee55e2
6
+ metadata.gz: 9c54eb6f16e435a14f387714c5bfc048a929e859c31f915dde57318cb7c49887dd2340d0646051f51ef2df97281530550c1863ddb4b5eefa838e216a5cf3edf7
7
+ data.tar.gz: 0f529d1464a0317358c5e4c632b6f5f7517e8667110b6102992ebb83d3908c6f521fe6cb7eaabefa165695890ecacf85fc1250f08cd02f39ef038ce9d6c7d5bf
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/README.adoc CHANGED
@@ -1,4 +1,4 @@
1
- = RelatonGb
1
+ = Relaton::Gb
2
2
 
3
3
  image:https://img.shields.io/gem/v/relaton-gb.svg["Gem Version", link="https://rubygems.org/gems/relaton-gb"]
4
4
  image:https://github.com/relaton/relaton-gb/workflows/macos/badge.svg["Build Status (macOS)", link="https://github.com/relaton/relaton-gb/actions?workflow=macos"]
@@ -9,7 +9,7 @@ image:https://img.shields.io/github/issues-pr-raw/relaton/relaton-gb.svg["Pull R
9
9
  image:https://img.shields.io/github/commits-since/relaton/relaton-gb/latest.svg["Commits since latest",link="https://github.com/relaton/relaton-gb/releases"]
10
10
 
11
11
 
12
- RelatonGb is a Ruby gem that searches and fetches Chinese GB standards.
12
+ Relaton::Gb is a Ruby gem that searches and fetches Chinese GB standards.
13
13
  The standards scraped form:
14
14
 
15
15
  * GB standards - http://www.std.gov.cn/gb/search
@@ -43,101 +43,99 @@ Or install it yourself as:
43
43
 
44
44
  [source,ruby]
45
45
  ----
46
- require 'relaton_gb'
46
+ require 'relaton/gb'
47
47
  => true
48
48
 
49
- hit_collection = RelatonGb::GbBibliography.search "GB/T 20223-2006"
50
- [relaton-gb] (GB/T 20223-2006) Fetching from openstd.samr.gov.cn ...
51
- => <RelatonGb::HitCollection:0x007fc8d8a26d10 @ref= @fetched=false>
49
+ hit_collection = Relaton::Gb::Bibliography.search "GB/T 20223-2006"
50
+ [relaton-gb] INFO: (GB/T 20223-2006) Fetching from openstd.samr.gov.cn ...
51
+ => <Relaton::Gb::HitCollection:0x00000000001350 @ref= @fetched=false>
52
52
 
53
53
  hit_collection.first
54
- => <RelatonGb::Hit:0x007fc8d8a27c88 @fullIdentifier="" @docref="GB/T 20223-2006">
54
+ => <Relaton::Gb::Hit:0x00000000001850 @fullIdentifier="" @docref="GB/T 20223-2006">
55
55
  ----
56
56
 
57
57
  === Scrape document form collection
58
58
 
59
59
  [source,ruby]
60
60
  ----
61
- hit_collection.first.fetch
62
- => <RelatonGb::GbBibliographicItem:0x007f975a0219c8>
63
-
64
- hit_collection.first.fetch.committee
65
- => #<RelatonGb::GbTechnicalCommittee:0x007f975713c450 @name="中国纤维检验局", @type="technical">
66
-
67
- hit_collection.first.fetch.gbtype
68
- => #<RelatonGb::GbStandardType:0x0000000112957dc0 @mandate="recommended", @prefix="GB_national", @scope="national", @topic="other">
69
-
70
- hit_collection.first.fetch.ccs
71
- => [#<Cnccs::Ccs:0x007f975713c090
72
- @code="B32",
73
- @description="纤维作物与产品",
74
- @description_full="农业、林业; 经济作物; 纤维作物与产品",
75
- @fieldcode="B",
76
- @groupcode="30/39",
77
- @notes=[#<Cnccs::Note:0x007f975716edb0 @ccs_code="", @text="棉、麻等">],
78
- @subgroupcode="32">]
79
-
80
- hit_collection.first.fetch.title
81
- => #<RelatonBib::TypedTitleStringCollection:0x0000000112a1ac08
82
- @array=
83
- [#<RelatonBib::TypedTitleString:0x0000000112a1f438
84
- @title=#<RelatonBib::FormattedString:0x0000000112cd6050 @content="棉短绒", @format="text/plain", @language=["zh"], @script=["Hans"]>,
85
- @type="title-main">,
86
- #<RelatonBib::TypedTitleString:0x0000000112a1eb78
87
- @title=#<RelatonBib::FormattedString:0x0000000112cd6000 @content="棉短绒", @format="text/plain", @language=["zh"], @script=["Hans"]>,
88
- @type="main">,
89
- #<RelatonBib::TypedTitleString:0x0000000112a1c198
90
- @title=#<RelatonBib::FormattedString:0x0000000112cd5ce0 @content="Cotton linter", @format="text/plain", @language=["en"], @script=["Latn"]>,
91
- @type="title-main">,
92
- #<RelatonBib::TypedTitleString:0x0000000112a1bba8
93
- @title=#<RelatonBib::FormattedString:0x0000000112cd5c40 @content="Cotton linter", @format="text/plain", @language=["en"], @script=["Latn"]>,
94
- @type="main">]>
95
-
96
- hit_collection.first.fetch.date
97
- => [#<RelatonBib::BibliographicDate:0x000000011307f468 @from=nil, @on="2006-03-10", @to=nil, @type="published">]
61
+ hit_collection.first.item
62
+ => #<Relaton::Gb::ItemData:0x000000012913b968
63
+
64
+ hit_collection.first.item.title.first
65
+ => #<Relaton::Bib::Title:0x00000001290f2bc8
66
+ @content="棉短绒",
67
+ @format=nil,
68
+ @language="zh",
69
+ @locale=nil,
70
+ @script="Hans",
71
+ @type="title-main">
72
+
73
+ hit_collection.first.item.ext.gbtype
74
+ => #<Relaton::Gb::GbType:0x00000001259687c0
75
+ @mandate=["recommended"],
76
+ @prefix="GB_national",
77
+ @scope=["national"],
78
+ @topic=["other"]>
79
+
80
+ hit_collection.first.item.ext.ccs
81
+ => [#<Relaton::Gb::CCS:0x000000012913f608 @code="B32">]
82
+
83
+ hit_collection.first.item.date
84
+ => [#<Relaton::Bib::Date:0x0000000129111dc0
85
+ @at=#<Relaton::Bib::StringDate::Value:0x00000001291111e0 @value="2006-03-10">,
86
+ @from=nil,
87
+ @text=nil,
88
+ @to=nil,
89
+ @type=["published"]>]
90
+
91
+ hit_collection.first.item.date.first.at.to_s
92
+ => "2006-03-10"
93
+
94
+ hit_collection.first.item.date.first.at.to_date
95
+ => #<Date: 2006-03-10 ((2453805j,0s,0n),+0s,2299161j)>
98
96
  ----
99
97
 
100
98
  === Get document by identifier
101
99
 
102
100
  [source,ruby]
103
101
  ----
104
- RelatonGb::GbBibliography.get "GB/T 20223-2006"
105
- [relaton-gb] (GB/T 20223-2006) Fetching from openstd.samr.gov.cn ...
106
- [relaton-gb] (GB/T 20223-2006) Found: `GB/T 20223-2006`
107
- => <RelatonGb::GbBibliographicItem:0x000000000011f8>
102
+ Relaton::Gb::Bibliography.get "GB/T 20223-2006"
103
+ [relaton-gb] INFO: (GB/T 20223-2006) Fetching from openstd.samr.gov.cn ...
104
+ [relaton-gb] INFO: (GB/T 20223-2006) Found: `GB/T 20223-2006`
105
+ => #<Relaton::Gb::ItemData:0x0000000129dd16a0
108
106
  ----
109
107
 
110
108
  === Get document by identifier and year
111
109
 
112
110
  [source,ruby]
113
111
  ----
114
- RelatonGb::GbBibliography.get "GB/T 20223", "2006"
115
- [relaton-gb] (GB/T 20223-2006) Fetching from openstd.samr.gov.cn ...
116
- [relaton-gb] (GB/T 20223-2006) Found: `GB/T 20223-2006`
117
- => <RelatonGb::GbBibliographicItem:0x00000000001248>
112
+ Relaton::Gb::Bibliography.get "GB/T 20223", "2006"
113
+ [relaton-gb] INFO: (GB/T 20223-2006) Fetching from openstd.samr.gov.cn ...
114
+ [relaton-gb] INFO: (GB/T 20223-2006) Found: `GB/T 20223-2006`
115
+ => #<Relaton::Gb::ItemData:0x00000001299ffdd8
118
116
  ----
119
117
 
120
118
  === Create bibliographic item from YAML
121
119
  [source,ruby]
122
120
  ----
123
- hash = YAML.load_file 'spec/examples/gb_bib_item.yml'
124
- => {"id"=>"JB/T13368",
125
- ...
126
121
 
127
- RelatonGb::GbBibliographicItem.from_hash hash
128
- => <RelatonGb::GbBibliographicItem:0x007fc680802700>
122
+ Relaton::Gb::Item.from_yaml File.read('spec/fixtures/item.yaml')
123
+ => #<Relaton::Gb::ItemData:0x00000001292d85c8
129
124
  ----
130
125
 
131
126
  === Serialization
132
127
 
133
128
  [source,ruby]
134
129
  ----
135
- hit_collection.first.fetch.to_xml
136
- => "<bibitem id="GB/T20223-2006" type="standard" schema-version="v1.2.1">
137
- <fetched>2022-12-03</fetched>
138
- <title type="title-main" format="text/plain" language="zh" script="Hans">棉短绒</title>
139
- <title type="main" format="text/plain" language="zh" script="Hans">棉短绒</title>
140
- <title type="title-main" format="text/plain" language="en" script="Latn">Cotton linter</title>
130
+ hit_collection.first.item.to_xml
131
+ => "<bibitem id="GBT202232006" type="standard" schema-version="v1.4.1">
132
+ <fetched>2026-01-26</fetched>
133
+ <title language="zh" script="Hans" type="title-main">棉短绒</title>
134
+ <title language="zh" script="Hans" type="main">棉短绒</title>
135
+ <title language="en" script="Latn" type="title-main">Cotton linter</title>
136
+ <title language="en" script="Latn" type="main">Cotton linter</title>
137
+ <uri type="src">http://openstd.samr.gov.cn/bzgk/gb/newGbInfo?hcno=083B48FA72DBD3B9BDE74507BC31736A</uri>
138
+ <docidentifier type="Chinese Standard" primary="true">GB/T 20223-2006</docidentifier>
141
139
  ...
142
140
  </bibitem>"
143
141
  ----
@@ -146,13 +144,15 @@ With `bibdata: true` option XML output is wrapped with `bibdata` element and `ex
146
144
 
147
145
  [source,ruby]
148
146
  ----
149
- hit_collection.first.fetch.to_xml bibdata: true
150
- => "<bibdata type="standard" schema-version="v1.2.1">
151
- <fetched>2022-12-03</fetched>
152
- <title type="title-main" format="text/plain" language="zh" script="Hans">棉短绒</title>
153
- <title type="main" format="text/plain" language="zh" script="Hans">棉短绒</title>
154
- <title type="title-main" format="text/plain" language="en" script="Latn">Cotton linter</title>
155
- <title type="main" format="text/plain" language="en" script="Latn">Cotton linter</title>
147
+ hit_collection.first.item.to_xml bibdata: true
148
+ => "<bibdata type="standard" schema-version="v1.4.1">
149
+ <fetched>2026-01-26</fetched>
150
+ <title language="zh" script="Hans" type="title-main">棉短绒</title>
151
+ <title language="zh" script="Hans" type="main">棉短绒</title>
152
+ <title language="en" script="Latn" type="title-main">Cotton linter</title>
153
+ <title language="en" script="Latn" type="main">Cotton linter</title>
154
+ <uri type="src">http://openstd.samr.gov.cn/bzgk/gb/newGbInfo?hcno=083B48FA72DBD3B9BDE74507BC31736A</uri>
155
+ <docidentifier type="Chinese Standard" primary="true">GB/T 20223-2006</docidentifier>
156
156
  ...
157
157
  <ext schema-version="v1.0.0">
158
158
  <doctype>standard</doctype>
@@ -161,19 +161,24 @@ hit_collection.first.fetch.to_xml bibdata: true
161
161
  </bibdata>"
162
162
  ----
163
163
 
164
- === Typed links
164
+ === Typed source links
165
165
 
166
- Each GB document has `src` type link.
166
+ Each GB document has `src` type source link.
167
167
 
168
168
  [source,ruby]
169
169
  ----
170
- hit_collection.first.fetch.link
171
- => [#<RelatonBib::TypedUri:0x00007fee2c0257e8 @content=#<Addressable::URI:0x67c URI:http://openstd.samr.gov.cn/bzgk/gb/newGbInfo?hcno=083B48FA72DBD3B9BDE74507BC31736A>, @type="src">]
170
+ hit_collection.first.item.source
171
+ => #<Relaton::Bib::Uri:0x0000000129112bf8
172
+ @content="http://openstd.samr.gov.cn/bzgk/gb/newGbInfo?hcno=083B48FA72DBD3B9BDE74507BC31736A",
173
+ @language=nil,
174
+ @locale=nil,
175
+ @script=nil,
176
+ @type="src">
172
177
  ----
173
178
 
174
179
  === Logging
175
180
 
176
- RelatonGb uses the relaton-logger gem for logging. By default, it logs to STDOUT. To change the log levels and add other loggers, read the https://github.com/relaton/relaton-logger#usage[relaton-logger] documentation.
181
+ Relaton::Gb uses the relaton-logger gem for logging. By default, it logs to STDOUT. To change the log levels and add other loggers, read the https://github.com/relaton/relaton-logger#usage[relaton-logger] documentation.
177
182
 
178
183
  == Development
179
184