relaton-gb 1.0.1 → 1.4.0

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.
@@ -91,6 +91,12 @@
91
91
  </define>
92
92
  <define name="sections">
93
93
  <element name="sections">
94
+ <zeroOrMore>
95
+ <choice>
96
+ <ref name="note"/>
97
+ <ref name="admonition"/>
98
+ </choice>
99
+ </zeroOrMore>
94
100
  <ref name="clause"/>
95
101
  <optional>
96
102
  <choice>
@@ -247,7 +253,7 @@
247
253
  <define name="preface">
248
254
  <element name="preface">
249
255
  <optional>
250
- <ref name="preface_abstract"/>
256
+ <ref name="abstract"/>
251
257
  </optional>
252
258
  <ref name="foreword"/>
253
259
  <optional>
@@ -263,6 +269,8 @@
263
269
  <value>publicly-available-specification</value>
264
270
  <value>international-workshop-agreement</value>
265
271
  <value>guide</value>
272
+ <value>amendment</value>
273
+ <value>technical-corrigendum</value>
266
274
  </choice>
267
275
  </define>
268
276
  <define name="structuredidentifier">
@@ -354,6 +362,9 @@
354
362
  <data type="boolean"/>
355
363
  </attribute>
356
364
  </optional>
365
+ <optional>
366
+ <attribute name="number"/>
367
+ </optional>
357
368
  <optional>
358
369
  <attribute name="subsequence"/>
359
370
  </optional>
@@ -510,7 +521,7 @@
510
521
  </attribute>
511
522
  </optional>
512
523
  <oneOrMore>
513
- <ref name="paragraph-with-footnote"/>
524
+ <ref name="BasicBlock"/>
514
525
  </oneOrMore>
515
526
  </element>
516
527
  </define>
@@ -19,4 +19,4 @@ module RelatonGb
19
19
  grammars = Dir[grammars_path].sort.map { |gp| File.read gp }.join
20
20
  Digest::MD5.hexdigest grammars
21
21
  end
22
- end
22
+ end
@@ -4,5 +4,17 @@ module Cnccs
4
4
  def to_hash
5
5
  { "code" => code }
6
6
  end
7
+
8
+ # @param prefix [String]
9
+ # @param count [Integer]
10
+ # @return [String]
11
+ def to_aciibib(prefix = "", count = 1)
12
+ pref = prefix.empty? ? prefix : prefix + "."
13
+ pref += "ccs"
14
+ out = count > 1 ? "#{pref}::\n" : ""
15
+ out += "#{pref}.code:: #{code}\n" if code
16
+ out += "#{pref}.description:: #{description}\n" if description
17
+ out
18
+ end
7
19
  end
8
20
  end
@@ -35,6 +35,7 @@ module RelatonGb
35
35
  @ccs = args[:ccs].map { |c| c.is_a?(Cnccs::Ccs) ? c : Cnccs.fetch(c) }
36
36
  @gbtype = GbStandardType.new args[:gbtype]
37
37
  @gbplannumber = args[:gbplannumber] || structuredidentifier&.project_number
38
+ # @doctype = args[:doctype]
38
39
  end
39
40
 
40
41
  # @param builder [Nokogiri::XML::Builder]
@@ -59,11 +60,17 @@ module RelatonGb
59
60
  hash
60
61
  end
61
62
 
63
+ # @param prefix [String]
64
+ # @return [String]
65
+ def to_asciibib(prefix = "")
66
+ out = super
67
+ ccs.each { |c| out += c.to_aciibib prefix, ccs.size }
68
+ out
69
+ end
70
+
62
71
  # @return [String]
63
72
  def inspect
64
- "<#{self.class}:#{format('%#.14x', object_id << 1)}>"
65
- # "@fullIdentifier=\"#{@fetch&.shortref}\" "\
66
- # "@title=\"#{title}\">"
73
+ "<#{self.class}:#{format('%<id>#.14x', id: object_id << 1)}>"
67
74
  end
68
75
 
69
76
  # @return [String]
@@ -76,34 +83,11 @@ module RelatonGb
76
83
 
77
84
  id ||= @docidentifier.reject { |i| i.type == "DOI" }[0]
78
85
  idstr = id.id
79
- # if id.part_number&.size&.positive?
80
- # idstr = idstr + "-#{id.part_number}"
81
- # end
82
86
  idstr.gsub(/\s/, "").strip
83
87
  end
84
88
 
85
89
  private
86
90
 
87
- # Overraides IsoBibliographicItem method.
88
- # @param language [Array<String>]
89
- # @raise ArgumentError
90
- def check_language(language)
91
- language.each do |lang|
92
- unless %w[en zh].include? lang
93
- raise ArgumentError, "invalid language: #{lang}"
94
- end
95
- end
96
- end
97
-
98
- # Overraides IsoBibliographicItem method.
99
- # @param script [Array<String>]
100
- # @raise ArgumentError
101
- def check_script(script)
102
- script.each do |scr|
103
- raise ArgumentError, "invalid script: #{scr}" unless %w[Latn Hans].include? scr
104
- end
105
- end
106
-
107
91
  # @param builder [Nokogiri::XML::Builder]
108
92
  def render_gbxml(builder)
109
93
  gbtype.to_xml builder
@@ -16,7 +16,7 @@ module RelatonGb
16
16
  # @return [RelatonGb::HitCollection]
17
17
  def scrape_page(text)
18
18
  search_html = OpenURI.open_uri(
19
- "http://openstd.samr.gov.cn/bzgk/gb/std_list?p.p2=" + text
19
+ "http://openstd.samr.gov.cn/bzgk/gb/std_list?p.p2=" + text,
20
20
  )
21
21
  result = Nokogiri::HTML search_html
22
22
  hits = result.xpath(
@@ -17,6 +17,15 @@ module RelatonGb
17
17
 
18
18
  private
19
19
 
20
+ #
21
+ # Ovverides superclass's method
22
+ #
23
+ # @param item [Hash]
24
+ # @retirn [RelatonGb::GbBibliographicItem]
25
+ def bib_item(item)
26
+ GbBibliographicItem.new(item)
27
+ end
28
+
20
29
  def ccs_hash_to_bib(ret)
21
30
  ret[:ccs] = array(ret[:ccs]).map do |ccs|
22
31
  ccs[:code] ? Cnccs.fetch(ccs[:code]) : Cnccs.fetch(ccs)
@@ -38,7 +38,7 @@ module RelatonGb
38
38
 
39
39
  # @return [String]
40
40
  def inspect
41
- "<#{self.class}:#{format('%#.14x', object_id << 1)} "\
41
+ "<#{self.class}:#{format('%<id>#.14x', id: object_id << 1)} "\
42
42
  "@fullIdentifier=\"#{@fetch&.shortref}\" "\
43
43
  "@docref=\"#{docref}\">"
44
44
  end
@@ -5,10 +5,11 @@ module RelatonGb
5
5
  class HitCollection < RelatonBib::HitCollection
6
6
  # @param hits [Array<Hash>]
7
7
  # @param hit_pages [Integer]
8
- # @param scrapper [RelatonGb::GbScrapper, RelatonGb::SecScrapper, RelatonGb::TScrapper]
8
+ # @param scrapper [RelatonGb::GbScrapper, RelatonGb::SecScrapper,
9
+ # RelatonGb::TScrapper]
9
10
  def initialize(hits = [])
10
11
  @array = hits
11
- @fetched = false
12
+ @fetched = false
12
13
  end
13
14
  end
14
15
  end
@@ -55,32 +55,37 @@ module RelatonGb
55
55
  # @param docref [Strings]
56
56
  # @return [Array<Hash>]
57
57
  def get_contributors(doc, docref)
58
- gb_en = GbAgencies::Agencies.new("en", {}, "")
59
- gb_zh = GbAgencies::Agencies.new("zh", {}, "")
60
58
  name = docref.match(/^[^\s]+/).to_s
61
59
  name.sub!(%r{/[TZ]$}, "") unless name =~ /^GB/
62
60
  gbtype = get_gbtype(doc, docref)
63
- entity = RelatonBib::Organization.new name: [
64
- { language: "en", content: gb_en.standard_agency1(gbtype[:scope], name, gbtype[:mandate]) },
65
- { language: "zh", content: gb_zh.standard_agency1(gbtype[:scope], name, gbtype[:mandate]) },
66
- ]
61
+ orgs = %w[en zh].map { |l| org(l, name, gbtype) }.compact
62
+ return [] unless orgs.any?
63
+
64
+ entity = RelatonBib::Organization.new name: orgs
67
65
  [{ entity: entity, role: [type: "publisher"] }]
68
66
  end
69
67
 
68
+ # @param lang [String]
69
+ # @param name [String]
70
+ # @param gbtype [Hash]
71
+ # @return [Hash]
72
+ def org(lang, name, gbtype)
73
+ ag = GbAgencies::Agencies.new(lang, {}, "")
74
+ content = ag.standard_agency1(gbtype[:scope], name, gbtype[:mandate])
75
+ return unless content
76
+
77
+ { language: lang, content: content }
78
+ end
79
+
70
80
  # @param doc [Nokogiri::HTML::Document]
71
- # @return [Array<Hash>]
72
- # * :title_intro [String]
73
- # * :title_main [String]
74
- # * :language [String]
75
- # * :script [String]
81
+ # @return [Array<RelatonBib::TypedTitleString>]
76
82
  def get_titles(doc)
77
- titles = [{ title_main: doc.at("//td[contains(text(), '中文标准名称')]/b").text,
78
- title_intro: nil, language: "zh", script: "Hans" }]
79
- title_main = doc.at("//td[contains(text(), '英文标准名称')]").text.match(/[\w\s]+/).to_s
80
- unless title_main.empty?
81
- titles << { title_main: title_main, title_intro: nil, language: "en", script: "Latn" }
82
- end
83
- titles
83
+ tzh = doc.at("//td[contains(text(), '中文标准名称')]/b").text
84
+ titles = RelatonBib::TypedTitleString.from_string tzh, "zh", "Hans"
85
+ ten = doc.at("//td[contains(text(), '英文标准名称')]").text.match(/[\w\s]+/).to_s
86
+ return titles if ten.empty?
87
+
88
+ titles + RelatonBib::TypedTitleString.from_string(ten, "en", "Latn")
84
89
  end
85
90
 
86
91
  def get_type
@@ -113,12 +118,6 @@ module RelatonGb
113
118
  mandate: get_mandate(ref), topic: "other" }
114
119
  end
115
120
 
116
- # @param doc [Nokogiri::HTML::Document]
117
- # @return [String]
118
- # def get_ref(doc)
119
- # doc.xpath('//dt[text()="标准号"]/following-sibling::dd[1]').text
120
- # end
121
-
122
121
  # @param doc [Nokogiri::HTML::Document]
123
122
  # @return [Array<String>]
124
123
  def get_ccs(doc)
@@ -58,13 +58,15 @@ module RelatonGb
58
58
  # * :language [String]
59
59
  # * :script [String]
60
60
  def get_titles(doc)
61
- titles = [{ title_main: doc.at("//h4").text.delete("\r\n\t"),
62
- title_intro: nil, language: "zh", script: "Hans" }]
61
+ # titles = [{ title_main: doc.at("//h4").text.delete("\r\n\t"),
62
+ # title_intro: nil, language: "zh", script: "Hans" }]
63
+ tzh = doc.at("//h4").text.delete("\r\n\t")
64
+ RelatonBib::TypedTitleString.from_string tzh, "zh", "Hans"
63
65
  # title_main = doc.at("//td[contains(text(), '英文标准名称')]").text.match(/[\w\s]+/).to_s
64
66
  # unless title_main.empty?
65
67
  # titles << { title_main: title_main, title_intro: nil, language: "en", script: "Latn" }
66
68
  # end
67
- titles
69
+ # titles
68
70
  end
69
71
 
70
72
  # @param _doc [Nokogiri::HTML::Document]
@@ -21,7 +21,7 @@ module RelatonGb
21
21
  def scrape_page(text)
22
22
  search_html = OpenURI.open_uri(
23
23
  "http://www.ttbz.org.cn/Home/Standard?searchType=2&key=" +
24
- CGI.escape(text.tr("-", [8212].pack("U"))),
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'
@@ -84,26 +84,21 @@ module RelatonGb
84
84
  end
85
85
 
86
86
  def get_titles(doc)
87
- xpath = '//td[contains(.,"中文标题")]/following-sibling::td[1]'
88
- titles = [{ title_main: doc.xpath(xpath).text,
89
- title_intro: nil, language: "zh", script: "Hans" }]
90
- xpath = '//td[contains(.,"英文标题")]/following-sibling::td[1]'
91
- title_main = doc.xpath(xpath).text
92
- unless title_main.empty?
93
- titles << { title_main: title_main, title_intro: nil, language: "en",
94
- script: "Latn" }
95
- end
96
- titles
87
+ xpz = '//td[contains(.,"中文标题")]/following-sibling::td[1]'
88
+ titles = RelatonBib::TypedTitleString.from_string doc.at(xpz)
89
+ .text, "zh", "Hans"
90
+ xpe = '//td[contains(.,"英文标题")]/following-sibling::td[1]'
91
+ ten = doc.xpath(xpe).text
92
+ return titles if ten.empty?
93
+
94
+ titles + RelatonBib::TypedTitleString.from_string(ten, "en", "Latn")
97
95
  end
98
96
 
99
97
  def gbtype
100
- { scope: "social-group", prefix: "T", mandate: "mandatory", topic: "other" }
98
+ { scope: "social-group", prefix: "T", mandate: "mandatory",
99
+ topic: "other" }
101
100
  end
102
101
 
103
- # def get_group_code(ref)
104
- # ref.match(%r{(?<=\/)[^\s]})
105
- # end
106
-
107
102
  def get_ccs(doc)
108
103
  [doc.xpath('//td[contains(.,"中国标准分类号")]/following-sibling::td[1]')
109
104
  .text.gsub(/[\r\n]/, "").strip.match(/^[^\s]+/).to_s]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonGb
4
- VERSION = "1.0.1"
4
+ VERSION = "1.4.0"
5
5
  end
@@ -3,18 +3,15 @@ require "nokogiri"
3
3
  module RelatonGb
4
4
  class XMLParser < RelatonIsoBib::XMLParser
5
5
  class << self
6
- def from_xml(xml)
7
- doc = Nokogiri::XML(xml)
8
- gbitem = doc.at "/bibitem|/bibdata"
9
- if gbitem
10
- GbBibliographicItem.new item_data(gbitem)
11
- else
12
- warn "[relato-gb] can't find bibitem or bibdata element in the XML"
13
- end
14
- end
15
-
16
6
  private
17
7
 
8
+ # override RelatonBib::BibliographicItem.bib_item method
9
+ # @param item_hash [Hash]
10
+ # @return [RelatonGb::GbBibliographicItem]
11
+ def bib_item(item_hash)
12
+ GbBibliographicItem.new item_hash
13
+ end
14
+
18
15
  def item_data(gbitem)
19
16
  data = super
20
17
  data[:committee] = fetch_committee gbitem
@@ -24,11 +21,6 @@ module RelatonGb
24
21
  data
25
22
  end
26
23
 
27
- # Overrade get_id from RelatonIsoBib::XMLParser
28
- # def get_id(did)
29
- # did.text.match(/^(?<project>.*?\d+)(?<hyphen>-)?(?(<hyphen>)(?<year>\d*))/)
30
- # end
31
-
32
24
  def fetch_committee(doc)
33
25
  committee = doc.at "./ext/gbcommittee"
34
26
  return nil unless committee
@@ -37,5 +37,5 @@ Gem::Specification.new do |spec|
37
37
 
38
38
  spec.add_dependency "cnccs", "~> 0.1.1"
39
39
  spec.add_dependency "gb-agencies", "~> 0.0.1"
40
- spec.add_dependency "relaton-iso-bib", ">= 1.0.1"
40
+ spec.add_dependency "relaton-iso-bib", ">= 1.4.0"
41
41
  end
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.0.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-20 00:00:00.000000000 Z
11
+ date: 2020-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debase
@@ -184,14 +184,14 @@ dependencies:
184
184
  requirements:
185
185
  - - ">="
186
186
  - !ruby/object:Gem::Version
187
- version: 1.0.1
187
+ version: 1.4.0
188
188
  type: :runtime
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - ">="
193
193
  - !ruby/object:Gem::Version
194
- version: 1.0.1
194
+ version: 1.4.0
195
195
  description: 'RelatonGb: retrieve Chinese GB Standards for bibliographic use using
196
196
  the BibliographicItem model.'
197
197
  email:
@@ -241,7 +241,7 @@ homepage: https://github.com/metanorma/relaton_gb
241
241
  licenses:
242
242
  - BSD-2-Clause
243
243
  metadata: {}
244
- post_install_message:
244
+ post_install_message:
245
245
  rdoc_options: []
246
246
  require_paths:
247
247
  - lib
@@ -257,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
257
257
  version: '0'
258
258
  requirements: []
259
259
  rubygems_version: 3.0.6
260
- signing_key:
260
+ signing_key:
261
261
  specification_version: 4
262
262
  summary: 'RelatonGb: retrieve Chinese GB Standards for bibliographic use using the
263
263
  BibliographicItem model.'