relaton-jis 1.14.0 → 1.14.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30edf630d85d2e1abafa0c0c03c7b5b22be3b5eebe8c18a7b9df955d8588e22b
4
- data.tar.gz: 79ce45cba39f96353038c95c608c38b893ddbad335a671ade2361384ab8e3a3c
3
+ metadata.gz: a6a4ecb8042069c8babc406d37ee36702fa28bb6efe4d4bdbc60c48ed7fc6599
4
+ data.tar.gz: 45ee95535b80261e3ad03f76a8025b86b9a4854509f2aab94056b6e438e38b6e
5
5
  SHA512:
6
- metadata.gz: b0a58bb07a4b7b6f00b8b18014e3b6500ec5403f0c26cca6fac3286aa97ff0736a604d4d1e7a61c3e4379f5625409720c1119229a9c0dc4642173da46498b170
7
- data.tar.gz: 6ba60be774e61bbfbcff9d10fe4dc031e4e07026c52fb64bbd56b9e6ccb59a2999f46c7c29475afcc8801effcc7fccf5f7076d64cb27744612abb291d1ad8219
6
+ metadata.gz: c60b2041b0c812cafb40f3f96ab6d253a21f4e7381422551a702cba2ab9b84a2f2f03f1f05aaad6bcd187eaa95d097bf947fc142dcee142d6c2c73f4011fabe4
7
+ data.tar.gz: 52bfca55bb5bf3e49cb2f26d83d6a8068efb2a112676bfd9450248cbd7aa6e9834f1b96ff5da976c84013adbd846189d89b90bcb5f85ec543776497c60bf6a4d
@@ -6,9 +6,6 @@
6
6
  <attribute name="schema-version"/>
7
7
  </optional>
8
8
  <ref name="doctype"/>
9
- <optional>
10
- <ref name="docsubtype"/>
11
- </optional>
12
9
  <ref name="editorialgroup"/>
13
10
  <zeroOrMore>
14
11
  <ref name="ics"/>
@@ -18,93 +15,12 @@
18
15
  <ref name="stagename"/>
19
16
  </optional>
20
17
  </define>
21
- <define name="bdate">
22
- <element name="date">
23
- <attribute name="type">
24
- <choice>
25
- <ref name="BibliographicDateType"/>
26
- <text/>
27
- </choice>
28
- </attribute>
29
- <choice>
30
- <group>
31
- <element name="from">
32
- <ref name="ISO8601Date"/>
33
- </element>
34
- <optional>
35
- <element name="to">
36
- <ref name="ISO8601Date"/>
37
- </element>
38
- </optional>
39
- </group>
40
- <element name="on">
41
- <choice>
42
- <ref name="ISO8601Date"/>
43
- <value>--</value>
44
- <value>–</value>
45
- </choice>
46
- </element>
47
- </choice>
48
- </element>
49
- </define>
50
- <define name="organization">
51
- <element name="organization">
52
- <oneOrMore>
53
- <ref name="orgname"/>
54
- </oneOrMore>
55
- <optional>
56
- <ref name="abbreviation"/>
57
- </optional>
58
- <optional>
59
- <ref name="uri"/>
60
- </optional>
61
- <zeroOrMore>
62
- <ref name="org-identifier"/>
63
- </zeroOrMore>
64
- <zeroOrMore>
65
- <ref name="contact"/>
66
- </zeroOrMore>
67
- <optional>
68
- <ref name="technical-committee"/>
69
- </optional>
70
- <optional>
71
- <ref name="subcommittee"/>
72
- </optional>
73
- <optional>
74
- <ref name="workgroup"/>
75
- </optional>
76
- <optional>
77
- <ref name="secretariat"/>
78
- </optional>
79
- </element>
80
- </define>
81
18
  <define name="DocumentType">
82
19
  <choice>
83
- <value>british-standard</value>
84
- <value>draft-for-development</value>
85
- <value>published-document</value>
86
- <value>privately-subscribed-standard</value>
87
- <value>publicly-available-specification</value>
88
- <value>flex-standard</value>
89
- <value>international-standard</value>
90
- <value>technical-specification</value>
20
+ <value>japanese-industrial-standard</value>
91
21
  <value>technical-report</value>
92
- <value>guide</value>
93
- <value>international-workshop-agreement</value>
94
- <value>industry-technical-agreement</value>
95
- <value>standard</value>
96
- <value>european-workshop-agreement</value>
97
- <value>fast-track-standard</value>
98
- <value>expert-commentary</value>
99
- </choice>
100
- </define>
101
- <define name="DocumentSubtype">
102
- <choice>
103
- <value>specification</value>
104
- <value>method-of-test</value>
105
- <value>method-of-specifying</value>
106
- <value>vocabulary</value>
107
- <value>code-of-practice</value>
22
+ <value>technical-specification</value>
23
+ <value>amendment</value>
108
24
  </choice>
109
25
  </define>
110
26
  <define name="structuredidentifier">
@@ -126,11 +42,6 @@
126
42
  </element>
127
43
  </define>
128
44
  </include>
129
- <define name="updates_document_type">
130
- <element name="updates-document-type">
131
- <ref name="DocumentType"/>
132
- </element>
133
- </define>
134
45
  <define name="ISOProjectGroup">
135
46
  <zeroOrMore>
136
47
  <ref name="agency"/>
@@ -148,21 +59,11 @@
148
59
  <ref name="secretariat"/>
149
60
  </optional>
150
61
  </define>
151
- <define name="approvalgroup">
152
- <element name="approvalgroup">
153
- <ref name="ISOProjectGroup"/>
154
- </element>
155
- </define>
156
62
  <define name="agency">
157
63
  <element name="agency">
158
64
  <text/>
159
65
  </element>
160
66
  </define>
161
- <define name="horizontal">
162
- <element name="horizontal">
163
- <data type="boolean"/>
164
- </element>
165
- </define>
166
67
  <define name="documentnumber">
167
68
  <element name="project-number">
168
69
  <optional>
@@ -221,11 +122,4 @@
221
122
  <text/>
222
123
  </element>
223
124
  </define>
224
- <define name="coverimages">
225
- <element name="coverimages">
226
- <oneOrMore>
227
- <ref name="image"/>
228
- </oneOrMore>
229
- </element>
230
- </define>
231
125
  </grammar>
@@ -16,6 +16,9 @@ module RelatonJis
16
16
  agent = Mechanize.new
17
17
  resp = agent.post "#{SOURCE}0010/searchByKeyword", search_type: "JIS", keyword: code
18
18
  disp = JSON.parse resp.body
19
+ # raise RelatonBib::RequestError, "No results found for #{code}" if disp["disp_screen"].nil?
20
+ return if disp["disp_screen"].nil?
21
+
19
22
  result = agent.get "#{SOURCE}#{disp['disp_screen']}/index"
20
23
  HitCollection.new code, year, result: result.xpath("//div[@class='blockGenaral']")
21
24
  end
@@ -25,16 +28,24 @@ module RelatonJis
25
28
  #
26
29
  # @param [String] ref JIS document reference
27
30
  # @param [String] year JIS document year
28
- # @param [Hash] _opts options
31
+ # @param [Hash] opts options
32
+ # @option opts [String] :all_parts return all parts of document
29
33
  #
30
34
  # @return [RelatonJis::BibliographicItem, nil] JIS document
31
35
  #
32
- def get(ref, year = nil, _opts = {})
36
+ def get(ref, year = nil, opts = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
37
+ code = ref.sub(/\s\((all parts|規格群)\)/, "")
38
+ opts[:all_parts] ||= !$1.nil?
33
39
  warn "[relaton-jis] (\"#{ref}\") fetching..."
34
- result = search(ref, year).find
35
- if result[:bib]
36
- warn "[relaton-jis] (\"#{ref}\") found #{result[:bib].docidentifier[0].id}"
37
- return result[:bib]
40
+ hits = search(code, year)
41
+ unless hits
42
+ hint [], ref, year
43
+ return
44
+ end
45
+ result = opts[:all_parts] ? hits.find_all_parts : hits.find
46
+ if result.is_a? RelatonJis::BibliographicItem
47
+ warn "[relaton-jis] (\"#{ref}\") found #{result.docidentifier[0].id}"
48
+ return result
38
49
  end
39
50
  hint result, ref, year
40
51
  end
@@ -42,16 +53,16 @@ module RelatonJis
42
53
  #
43
54
  # Log hint message
44
55
  #
45
- # @param [Hash] result search result
56
+ # @param [Array] result search result
46
57
  # @param [String] ref reference to search
47
58
  # @param [String, nil] year year to search
48
59
  #
49
60
  def hint(result, ref, year)
50
61
  warn "[relaton-jis] (\"#{ref}\") not found. The identifier must be " \
51
62
  "exactly as shown on the webdesk.jsa.or.jp website."
52
- if result[:missed_years]
53
- warn "[relaton-jis] (\"#{ref}\") TIP: No match for edition year #{year}, " \
54
- "but matches exist for #{result[:missed_years].uniq.join(', ')}."
63
+ if result.any?
64
+ warn "[relaton-jis] (\"#{ref}\") TIP: No match for edition " \
65
+ "year #{year}, but matches exist for #{result.uniq.join(', ')}."
55
66
  end
56
67
  end
57
68
  end
@@ -19,11 +19,13 @@ module RelatonJis
19
19
  #
20
20
  # @param [Hash] ref_parts parts of reference
21
21
  # @param [String, nil] year year
22
+ # @param [Boolean] all_parts check all parts of reference
22
23
  #
23
24
  # @return [Boolean] true if hit matches reference
24
25
  #
25
- def match?(ref_parts, year = nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity
26
+ def eq?(ref_parts, year = nil, all_parts: false) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity
26
27
  id_parts[:code].include?(ref_parts[:code]) &&
28
+ (all_parts || (ref_parts[:part].nil? || ref_parts[:part] == id_parts[:part])) &&
27
29
  (year.nil? || year == id_parts[:year]) &&
28
30
  ((ref_parts[:expl].nil? || !id_parts[:expl].nil?) &&
29
31
  (ref_parts[:expl_num].nil? || ref_parts[:expl_num] == id_parts[:expl_num])) &&
@@ -15,17 +15,56 @@ module RelatonJis
15
15
  #
16
16
  # Find hit in collection
17
17
  #
18
- # @return [Hash] hash with bib ot array of missed years
18
+ # @return [RelatonJis::BibliographicItem, Array<Strig>] hash with bib ot array of missed years
19
19
  #
20
20
  def find
21
+ ref_year = year || ref_parts[:year]
22
+ if ref_year
23
+ find_by_year ref_year
24
+ else
25
+ find_all_years
26
+ end
27
+ end
28
+
29
+ def find_by_year(ref_year)
21
30
  missed_years = []
22
- y = year || ref_parts[:year]
23
31
  @array.each do |hit|
24
- return { bib: hit.fetch } if hit.match? ref_parts, y
32
+ return hit.fetch if hit.eq? ref_parts, ref_year
33
+
34
+ missed_years << hit.id_parts[:year] if hit.eq?(ref_parts)
35
+ end
36
+ missed_years
37
+ end
38
+
39
+ def find_all_years # rubocop:disable Metrics/AbcSize
40
+ hits = @array.select { |hit| hit.eq? ref_parts }
41
+ item = hits.max_by { |i| i.id_parts[:year].to_i }.fetch
42
+ item_id = item.docidentifier.first.id
43
+ parent = item.to_most_recent_reference
44
+ hits.each do |hit|
45
+ next if hit.hit[:id] == item_id
25
46
 
26
- missed_years << hit.id_parts[:year] if y && hit.match?(ref_parts)
47
+ parent.relation << create_relation(hit)
27
48
  end
28
- { missed_years: missed_years }
49
+ parent
50
+ end
51
+
52
+ def find_all_parts # rubocop:disable Metrics/AbcSize
53
+ hits = @array.select { |hit| hit.eq? ref_parts, all_parts: true }
54
+ item = hits.min_by { |i| i.id_parts[:part].to_i }.fetch.to_all_parts
55
+ hits.each do |hit|
56
+ next if hit.hit[:id] == item.docidentifier.first.id
57
+
58
+ item.relation << create_relation(hit)
59
+ end
60
+ item
61
+ end
62
+
63
+ def create_relation(hit)
64
+ docid = RelatonBib::DocumentIdentifier.new id: hit.hit[:id], type: "JIS", primary: true
65
+ fref = RelatonBib::FormattedRef.new content: hit.hit[:id]
66
+ bibitem = BibliographicItem.new docid: [docid], formattedref: fref
67
+ RelatonBib::DocumentRelation.new(type: "instance", bibitem: bibitem)
29
68
  end
30
69
 
31
70
  #
@@ -46,13 +85,14 @@ module RelatonJis
46
85
  #
47
86
  def parse_ref(ref)
48
87
  %r{
49
- ^(?<code>\w+\s\w\s?\d+)
88
+ ^(?<code>\w+\s\w\s?\w+)
89
+ (?:-(?<part>\w+))?
50
90
  (?::(?<year>\d{4}))?
51
91
  (?:/(?<expl>EXPL(?:ANATION)?)(?:\s(?<expl_num>\d+))?)?
52
92
  (?:/(?<amd>AMDENDMENT)(?:\s(?<amd_num>\d+)(?::(?<amd_year>\d{4}))?)?)?
53
93
  }x =~ ref
54
- { code: code, year: year, expl: expl, expl_num: expl_num, amd: amd,
55
- amd_num: amd_num, amd_year: amd_year }
94
+ { code: code, part: part, year: year, expl: expl, expl_num: expl_num,
95
+ amd: amd, amd_num: amd_num, amd_year: amd_year }
56
96
  end
57
97
  end
58
98
  end
@@ -52,15 +52,18 @@ module RelatonJis
52
52
  end
53
53
 
54
54
  def fetch_docid
55
- id = @doc.at("./h2/text()[1]").text.strip
56
- [RelatonBib::DocumentIdentifier.new(id: id, type: "JIS", primary: true)]
55
+ [RelatonBib::DocumentIdentifier.new(id: document_id, type: "JIS", primary: true)]
57
56
  end
58
57
 
59
58
  def fetch_docnumber
60
- match = @doc.at("./h2/text()[1]").text.strip.match(/^\w+\s(\w)\s?(\d+)/)
59
+ match = document_id.match(/^\w+\s(\w)\s?(\d+)/)
61
60
  "#{match[1]}#{match[2]}"
62
61
  end
63
62
 
63
+ def document_id
64
+ @document_id ||= @doc.at("./h2/text()[1]").text.strip
65
+ end
66
+
64
67
  def fetch_date
65
68
  DATETYPES.each_with_object([]) do |(key, type), a|
66
69
  node = @doc.at("./div/div/div/p/text()[contains(.,'#{key}')]")
@@ -100,7 +103,12 @@ module RelatonJis
100
103
  end
101
104
 
102
105
  def fetch_doctype
103
- "standard"
106
+ case document_id
107
+ when /JIS\s[A-Z]\s[\w-]+:\d{4}\/AMENDMENT/ then "amendment"
108
+ when /JIS\s[A-Z]\s[\w-]+/ then "japanese-industrial-standard"
109
+ when /TR[\s\/][\w-]+/ then "technical-report"
110
+ when /TS[\s\/][\w-]+/ then "technical-specification"
111
+ end
104
112
  end
105
113
 
106
114
  def fetch_ics
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonJis
4
- VERSION = "1.14.0"
4
+ VERSION = "1.14.2"
5
5
  end
data/relaton_jis.gemspec CHANGED
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  # Uncomment to register a new dependency of your gem
37
37
  spec.add_dependency "mechanize", "~> 2.8.0"
38
+ spec.add_dependency "relaton-bib", "~> 1.14.9"
38
39
  spec.add_dependency "relaton-iso-bib", "~> 1.14.0"
39
40
 
40
41
  # For more information and examples about making a new gem, check out our
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-jis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.0
4
+ version: 1.14.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-21 00:00:00.000000000 Z
11
+ date: 2023-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: relaton-bib
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.14.9
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.14.9
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: relaton-iso-bib
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -89,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
103
  - !ruby/object:Gem::Version
90
104
  version: '0'
91
105
  requirements: []
92
- rubygems_version: 3.1.6
106
+ rubygems_version: 3.3.26
93
107
  signing_key:
94
108
  specification_version: 4
95
109
  summary: 'RelatonJis: retrieve IETF Standards for bibliographic use using the BibliographicItem