relaton-gb 1.12.1 → 1.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +0 -1
- data/.github/workflows/release.yml +22 -0
- data/README.adoc +24 -69
- data/grammars/basicdoc.rng +3 -27
- data/grammars/biblio-standoc.rng +164 -0
- data/grammars/biblio.rng +90 -24
- data/grammars/relaton-gb-compile.rng +11 -0
- data/grammars/relaton-gb.rng +297 -0
- data/lib/relaton_gb/gb_bibliographic_item.rb +10 -5
- data/lib/relaton_gb/t_scrapper.rb +4 -4
- data/lib/relaton_gb/version.rb +1 -1
- data/relaton_gb.gemspec +1 -1
- metadata +8 -8
- data/grammars/gbstandard.rng +0 -316
- data/grammars/isodoc.rng +0 -2781
- data/grammars/isostandard.rng +0 -514
- data/grammars/reqt.rng +0 -223
@@ -0,0 +1,297 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
|
3
|
+
<include href="biblio-standoc.rng">
|
4
|
+
<define name="BibDataExtensionType">
|
5
|
+
<optional>
|
6
|
+
<attribute name="schema-version"/>
|
7
|
+
</optional>
|
8
|
+
<optional>
|
9
|
+
<ref name="doctype"/>
|
10
|
+
</optional>
|
11
|
+
<optional>
|
12
|
+
<ref name="docsubtype"/>
|
13
|
+
</optional>
|
14
|
+
<zeroOrMore>
|
15
|
+
<ref name="gbcommittee"/>
|
16
|
+
</zeroOrMore>
|
17
|
+
<zeroOrMore>
|
18
|
+
<ref name="ics"/>
|
19
|
+
</zeroOrMore>
|
20
|
+
<ref name="structuredidentifier"/>
|
21
|
+
<optional>
|
22
|
+
<ref name="stagename"/>
|
23
|
+
</optional>
|
24
|
+
<ref name="gbtype"/>
|
25
|
+
<oneOrMore>
|
26
|
+
<ref name="gbccs"/>
|
27
|
+
</oneOrMore>
|
28
|
+
<optional>
|
29
|
+
<ref name="gbplannumber"/>
|
30
|
+
</optional>
|
31
|
+
</define>
|
32
|
+
<define name="bdate">
|
33
|
+
<element name="date">
|
34
|
+
<attribute name="type">
|
35
|
+
<choice>
|
36
|
+
<ref name="BibliographicDateType"/>
|
37
|
+
<text/>
|
38
|
+
</choice>
|
39
|
+
</attribute>
|
40
|
+
<choice>
|
41
|
+
<group>
|
42
|
+
<element name="from">
|
43
|
+
<ref name="ISO8601Date"/>
|
44
|
+
</element>
|
45
|
+
<optional>
|
46
|
+
<element name="to">
|
47
|
+
<ref name="ISO8601Date"/>
|
48
|
+
</element>
|
49
|
+
</optional>
|
50
|
+
</group>
|
51
|
+
<element name="on">
|
52
|
+
<choice>
|
53
|
+
<ref name="ISO8601Date"/>
|
54
|
+
<value>--</value>
|
55
|
+
<value>–</value>
|
56
|
+
</choice>
|
57
|
+
</element>
|
58
|
+
</choice>
|
59
|
+
</element>
|
60
|
+
</define>
|
61
|
+
<define name="organization">
|
62
|
+
<element name="organization">
|
63
|
+
<oneOrMore>
|
64
|
+
<ref name="orgname"/>
|
65
|
+
</oneOrMore>
|
66
|
+
<optional>
|
67
|
+
<ref name="abbreviation"/>
|
68
|
+
</optional>
|
69
|
+
<optional>
|
70
|
+
<ref name="uri"/>
|
71
|
+
</optional>
|
72
|
+
<zeroOrMore>
|
73
|
+
<ref name="org-identifier"/>
|
74
|
+
</zeroOrMore>
|
75
|
+
<zeroOrMore>
|
76
|
+
<ref name="contact"/>
|
77
|
+
</zeroOrMore>
|
78
|
+
<optional>
|
79
|
+
<ref name="technical-committee"/>
|
80
|
+
</optional>
|
81
|
+
<optional>
|
82
|
+
<ref name="subcommittee"/>
|
83
|
+
</optional>
|
84
|
+
<optional>
|
85
|
+
<ref name="workgroup"/>
|
86
|
+
</optional>
|
87
|
+
<optional>
|
88
|
+
<ref name="secretariat"/>
|
89
|
+
</optional>
|
90
|
+
</element>
|
91
|
+
</define>
|
92
|
+
<define name="DocumentType">
|
93
|
+
<choice>
|
94
|
+
<value>standard</value>
|
95
|
+
<value>recommendation</value>
|
96
|
+
</choice>
|
97
|
+
</define>
|
98
|
+
<define name="DocumentSubtype">
|
99
|
+
<choice>
|
100
|
+
<value>specification</value>
|
101
|
+
<value>method-of-test</value>
|
102
|
+
<value>vocabulary</value>
|
103
|
+
<value>code-of-practice</value>
|
104
|
+
</choice>
|
105
|
+
</define>
|
106
|
+
<define name="structuredidentifier">
|
107
|
+
<element name="structuredidentifier">
|
108
|
+
<optional>
|
109
|
+
<attribute name="type"/>
|
110
|
+
</optional>
|
111
|
+
<group>
|
112
|
+
<ref name="documentnumber"/>
|
113
|
+
<optional>
|
114
|
+
<ref name="tc-documentnumber"/>
|
115
|
+
</optional>
|
116
|
+
</group>
|
117
|
+
</element>
|
118
|
+
</define>
|
119
|
+
<define name="editorialgroup">
|
120
|
+
<element name="editorialgroup">
|
121
|
+
<ref name="ISOProjectGroup"/>
|
122
|
+
</element>
|
123
|
+
</define>
|
124
|
+
</include>
|
125
|
+
<define name="updates_document_type">
|
126
|
+
<element name="updates-document-type">
|
127
|
+
<ref name="DocumentType"/>
|
128
|
+
</element>
|
129
|
+
</define>
|
130
|
+
<define name="ISOProjectGroup">
|
131
|
+
<zeroOrMore>
|
132
|
+
<ref name="agency"/>
|
133
|
+
</zeroOrMore>
|
134
|
+
<oneOrMore>
|
135
|
+
<ref name="technical-committee"/>
|
136
|
+
</oneOrMore>
|
137
|
+
<zeroOrMore>
|
138
|
+
<ref name="subcommittee"/>
|
139
|
+
</zeroOrMore>
|
140
|
+
<zeroOrMore>
|
141
|
+
<ref name="workgroup"/>
|
142
|
+
</zeroOrMore>
|
143
|
+
<optional>
|
144
|
+
<ref name="secretariat"/>
|
145
|
+
</optional>
|
146
|
+
</define>
|
147
|
+
<define name="approvalgroup">
|
148
|
+
<element name="approvalgroup">
|
149
|
+
<ref name="ISOProjectGroup"/>
|
150
|
+
</element>
|
151
|
+
</define>
|
152
|
+
<define name="agency">
|
153
|
+
<element name="agency">
|
154
|
+
<text/>
|
155
|
+
</element>
|
156
|
+
</define>
|
157
|
+
<define name="horizontal">
|
158
|
+
<element name="horizontal">
|
159
|
+
<data type="boolean"/>
|
160
|
+
</element>
|
161
|
+
</define>
|
162
|
+
<define name="documentnumber">
|
163
|
+
<element name="project-number">
|
164
|
+
<optional>
|
165
|
+
<attribute name="part">
|
166
|
+
<data type="int"/>
|
167
|
+
</attribute>
|
168
|
+
</optional>
|
169
|
+
<optional>
|
170
|
+
<attribute name="subpart">
|
171
|
+
<data type="int"/>
|
172
|
+
</attribute>
|
173
|
+
</optional>
|
174
|
+
<optional>
|
175
|
+
<attribute name="amendment">
|
176
|
+
<data type="int"/>
|
177
|
+
</attribute>
|
178
|
+
</optional>
|
179
|
+
<optional>
|
180
|
+
<attribute name="corrigendum">
|
181
|
+
<data type="int"/>
|
182
|
+
</attribute>
|
183
|
+
</optional>
|
184
|
+
<optional>
|
185
|
+
<attribute name="origyr">
|
186
|
+
<ref name="ISO8601Date"/>
|
187
|
+
</attribute>
|
188
|
+
</optional>
|
189
|
+
<text/>
|
190
|
+
</element>
|
191
|
+
</define>
|
192
|
+
<define name="tc-documentnumber">
|
193
|
+
<element name="tc-document-number">
|
194
|
+
<data type="int"/>
|
195
|
+
</element>
|
196
|
+
</define>
|
197
|
+
<define name="subcommittee">
|
198
|
+
<element name="subcommittee">
|
199
|
+
<ref name="IsoWorkgroup"/>
|
200
|
+
</element>
|
201
|
+
</define>
|
202
|
+
<define name="workgroup">
|
203
|
+
<element name="workgroup">
|
204
|
+
<ref name="IsoWorkgroup"/>
|
205
|
+
</element>
|
206
|
+
</define>
|
207
|
+
<define name="secretariat">
|
208
|
+
<element name="secretariat">
|
209
|
+
<text/>
|
210
|
+
</element>
|
211
|
+
</define>
|
212
|
+
<define name="stagename">
|
213
|
+
<element name="stagename">
|
214
|
+
<optional>
|
215
|
+
<attribute name="abbreviation"/>
|
216
|
+
</optional>
|
217
|
+
<text/>
|
218
|
+
</element>
|
219
|
+
</define>
|
220
|
+
<define name="gbccs">
|
221
|
+
<element name="ccs">
|
222
|
+
<element name="code">
|
223
|
+
<text/>
|
224
|
+
</element>
|
225
|
+
<optional>
|
226
|
+
<element name="text">
|
227
|
+
<text/>
|
228
|
+
</element>
|
229
|
+
</optional>
|
230
|
+
</element>
|
231
|
+
</define>
|
232
|
+
<define name="gbplannumber">
|
233
|
+
<element name="plannumber">
|
234
|
+
<text/>
|
235
|
+
</element>
|
236
|
+
</define>
|
237
|
+
<define name="gbcommittee">
|
238
|
+
<element name="gbcommittee">
|
239
|
+
<attribute name="type">
|
240
|
+
<choice>
|
241
|
+
<value>technical</value>
|
242
|
+
<value>provisional</value>
|
243
|
+
<value>drafting</value>
|
244
|
+
</choice>
|
245
|
+
</attribute>
|
246
|
+
<text/>
|
247
|
+
</element>
|
248
|
+
</define>
|
249
|
+
<define name="gbtype">
|
250
|
+
<element name="gbtype">
|
251
|
+
<ref name="gbscope"/>
|
252
|
+
<ref name="gbprefix"/>
|
253
|
+
<ref name="gbmandate"/>
|
254
|
+
<ref name="gbtopic"/>
|
255
|
+
</element>
|
256
|
+
</define>
|
257
|
+
<define name="gbscope">
|
258
|
+
<element name="gbscope">
|
259
|
+
<choice>
|
260
|
+
<value>national</value>
|
261
|
+
<value>sector</value>
|
262
|
+
<value>professional</value>
|
263
|
+
<value>local</value>
|
264
|
+
<value>enterprise</value>
|
265
|
+
<value>social-group</value>
|
266
|
+
</choice>
|
267
|
+
</element>
|
268
|
+
</define>
|
269
|
+
<define name="gbmandate">
|
270
|
+
<element name="gbmandate">
|
271
|
+
<choice>
|
272
|
+
<value>mandatory</value>
|
273
|
+
<value>recommended</value>
|
274
|
+
<value>guidelines</value>
|
275
|
+
</choice>
|
276
|
+
</element>
|
277
|
+
</define>
|
278
|
+
<define name="gbprefix">
|
279
|
+
<element name="gbprefix">
|
280
|
+
<text/>
|
281
|
+
</element>
|
282
|
+
</define>
|
283
|
+
<define name="gbtopic">
|
284
|
+
<element name="gbtopic">
|
285
|
+
<choice>
|
286
|
+
<value>basic</value>
|
287
|
+
<value>health-and-safety</value>
|
288
|
+
<value>environment-protection</value>
|
289
|
+
<value>engineering-and-construction</value>
|
290
|
+
<value>product</value>
|
291
|
+
<value>method</value>
|
292
|
+
<value>management-techniques</value>
|
293
|
+
<value>other</value>
|
294
|
+
</choice>
|
295
|
+
</element>
|
296
|
+
</define>
|
297
|
+
</grammar>
|
@@ -31,18 +31,22 @@ module RelatonGb
|
|
31
31
|
|
32
32
|
def initialize(**args)
|
33
33
|
super
|
34
|
-
@committee = GbTechnicalCommittee.new
|
34
|
+
@committee = GbTechnicalCommittee.new(**args[:committee]) if args[:committee]
|
35
35
|
@ccs = args[:ccs].map { |c| c.is_a?(Cnccs::Ccs) ? c : Cnccs.fetch(c) }
|
36
|
-
@gbtype = GbStandardType.new
|
36
|
+
@gbtype = GbStandardType.new(**args[:gbtype])
|
37
37
|
@gbplannumber = args[:gbplannumber] ||
|
38
38
|
structuredidentifier&.project_number
|
39
39
|
end
|
40
40
|
|
41
|
+
def ext_schema
|
42
|
+
@ext_schema ||= schema_versions["relaton-model-gb"]
|
43
|
+
end
|
44
|
+
|
41
45
|
# @param hash [Hash]
|
42
46
|
# @return [RelatonGb::GbBibliographicItem]
|
43
47
|
def self.from_hash(hash)
|
44
48
|
item_hash = ::RelatonGb::HashConverter.hash_to_bib(hash)
|
45
|
-
new
|
49
|
+
new(**item_hash)
|
46
50
|
end
|
47
51
|
|
48
52
|
# @param opts [Hash]
|
@@ -51,10 +55,10 @@ module RelatonGb
|
|
51
55
|
# @option opts [Symbol, NilClass] :date_format (:short), :full
|
52
56
|
# @option opts [String, Symbol] :lang language
|
53
57
|
# @return [String] XML
|
54
|
-
def to_xml(**opts)
|
58
|
+
def to_xml(**opts) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
55
59
|
super(**opts) do |b|
|
56
60
|
if opts[:bibdata] && has_ext_attrs?
|
57
|
-
b.ext do
|
61
|
+
ext = b.ext do
|
58
62
|
b.doctype doctype if doctype
|
59
63
|
b.horizontal horizontal unless horizontal.nil?
|
60
64
|
# b.docsubtype docsubtype if docsubtype
|
@@ -64,6 +68,7 @@ module RelatonGb
|
|
64
68
|
b.stagename stagename if stagename
|
65
69
|
render_gbxml(b)
|
66
70
|
end
|
71
|
+
ext["schema-version"] = ext_schema unless opts[:embedded]
|
67
72
|
end
|
68
73
|
end
|
69
74
|
end
|
@@ -20,8 +20,8 @@ module RelatonGb
|
|
20
20
|
# @return [RelatonGb::HitCollection]
|
21
21
|
def scrape_page(text)
|
22
22
|
search_html = OpenURI.open_uri(
|
23
|
-
"http://www.ttbz.org.cn/Home/Standard?searchType=2&key="
|
24
|
-
CGI.escape(text.tr(
|
23
|
+
"http://www.ttbz.org.cn/Home/Standard?searchType=2&key=" \
|
24
|
+
"#{CGI.escape(text.tr('-', [8212].pack('U')))}",
|
25
25
|
).read
|
26
26
|
header = Nokogiri::HTML search_html
|
27
27
|
xpath = '//table[contains(@class, "standard_list_table")]/tr/td/a'
|
@@ -29,7 +29,7 @@ module RelatonGb
|
|
29
29
|
hits = header.xpath(xpath).map do |h|
|
30
30
|
docref = h.at(t_xpath).text.gsub(/â\u0080\u0094/, "-")
|
31
31
|
status = h.at("../preceding-sibling::td[1]").text.delete "\r\n"
|
32
|
-
pid = h[:href].sub(%r{
|
32
|
+
pid = h[:href].sub(%r{/$}, "")
|
33
33
|
Hit.new pid: pid, docref: docref, status: status, scrapper: self
|
34
34
|
end
|
35
35
|
HitCollection.new hits
|
@@ -43,7 +43,7 @@ module RelatonGb
|
|
43
43
|
def scrape_doc(hit)
|
44
44
|
src = "http://www.ttbz.org.cn#{hit.pid}"
|
45
45
|
doc = Nokogiri::HTML OpenURI.open_uri(src), nil, Encoding::UTF_8.to_s
|
46
|
-
GbBibliographicItem.new
|
46
|
+
GbBibliographicItem.new(**scrapped_data(doc, src, hit))
|
47
47
|
rescue OpenURI::HTTPError, SocketError, OpenSSL::SSL::SSLError, Net::OpenTimeout
|
48
48
|
raise RelatonBib::RequestError, "Cannot access #{src}"
|
49
49
|
end
|
data/lib/relaton_gb/version.rb
CHANGED
data/relaton_gb.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-gb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: equivalent-xml
|
@@ -156,14 +156,14 @@ dependencies:
|
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 1.
|
159
|
+
version: 1.14.0
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 1.
|
166
|
+
version: 1.14.0
|
167
167
|
description: 'RelatonGb: retrieve Chinese GB Standards for bibliographic use using
|
168
168
|
the BibliographicItem model.'
|
169
169
|
email:
|
@@ -173,6 +173,7 @@ extensions: []
|
|
173
173
|
extra_rdoc_files: []
|
174
174
|
files:
|
175
175
|
- ".github/workflows/rake.yml"
|
176
|
+
- ".github/workflows/release.yml"
|
176
177
|
- ".gitignore"
|
177
178
|
- ".hound.yml"
|
178
179
|
- ".rspec"
|
@@ -185,11 +186,10 @@ files:
|
|
185
186
|
- bin/rspec
|
186
187
|
- bin/setup
|
187
188
|
- grammars/basicdoc.rng
|
189
|
+
- grammars/biblio-standoc.rng
|
188
190
|
- grammars/biblio.rng
|
189
|
-
- grammars/
|
190
|
-
- grammars/
|
191
|
-
- grammars/isostandard.rng
|
192
|
-
- grammars/reqt.rng
|
191
|
+
- grammars/relaton-gb-compile.rng
|
192
|
+
- grammars/relaton-gb.rng
|
193
193
|
- lib/relaton_gb.rb
|
194
194
|
- lib/relaton_gb/ccs.rb
|
195
195
|
- lib/relaton_gb/gb_bibliographic_item.rb
|