relaton-jis 1.14.1 → 1.14.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/relaton_jis/bibliography.rb +7 -2
- data/lib/relaton_jis/hit.rb +2 -2
- data/lib/relaton_jis/hit_collection.rb +34 -9
- data/lib/relaton_jis/scraper.rb +7 -6
- data/lib/relaton_jis/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c952dd17ef7bf9a424b52b9f6ff9bb5ef3aebae20a4538510b66c90b6c8c3a76
|
4
|
+
data.tar.gz: ae56e2d1d9a2950a3666e5862270b5430d24e72d53a515bc5515f3943962dd9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37f5f42cd651872298e65e23a68f8ab738e7b0f84abb7d534ae417b633f44e947addc9ac2f9beb3fdf990cba8d7c52fbb38225f1d577e0b3405053f815829afc
|
7
|
+
data.tar.gz: ca363e1862d44270e08a00c088cc3e6b7eed54179dda6deedfd683a65037c5323e1d0a2fe94c00a0e324d20acd7806eb8892cc76ad3e844cce356beae84964ba
|
@@ -16,7 +16,8 @@ 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?
|
19
|
+
# raise RelatonBib::RequestError, "No results found for #{code}" if disp["disp_screen"].nil?
|
20
|
+
return if disp["disp_screen"].nil?
|
20
21
|
|
21
22
|
result = agent.get "#{SOURCE}#{disp['disp_screen']}/index"
|
22
23
|
HitCollection.new code, year, result: result.xpath("//div[@class='blockGenaral']")
|
@@ -32,11 +33,15 @@ module RelatonJis
|
|
32
33
|
#
|
33
34
|
# @return [RelatonJis::BibliographicItem, nil] JIS document
|
34
35
|
#
|
35
|
-
def get(ref, year = nil, opts = {})
|
36
|
+
def get(ref, year = nil, opts = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
36
37
|
code = ref.sub(/\s\((all parts|規格群)\)/, "")
|
37
38
|
opts[:all_parts] ||= !$1.nil?
|
38
39
|
warn "[relaton-jis] (\"#{ref}\") fetching..."
|
39
40
|
hits = search(code, year)
|
41
|
+
unless hits
|
42
|
+
hint [], ref, year
|
43
|
+
return
|
44
|
+
end
|
40
45
|
result = opts[:all_parts] ? hits.find_all_parts : hits.find
|
41
46
|
if result.is_a? RelatonJis::BibliographicItem
|
42
47
|
warn "[relaton-jis] (\"#{ref}\") found #{result.docidentifier[0].id}"
|
data/lib/relaton_jis/hit.rb
CHANGED
@@ -23,10 +23,10 @@ module RelatonJis
|
|
23
23
|
#
|
24
24
|
# @return [Boolean] true if hit matches reference
|
25
25
|
#
|
26
|
-
def
|
26
|
+
def eq?(ref_parts, year = nil, all_parts: false) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity
|
27
27
|
id_parts[:code].include?(ref_parts[:code]) &&
|
28
28
|
(all_parts || (ref_parts[:part].nil? || ref_parts[:part] == id_parts[:part])) &&
|
29
|
-
(
|
29
|
+
(year.nil? || year == id_parts[:year]) &&
|
30
30
|
((ref_parts[:expl].nil? || !id_parts[:expl].nil?) &&
|
31
31
|
(ref_parts[:expl_num].nil? || ref_parts[:expl_num] == id_parts[:expl_num])) &&
|
32
32
|
((ref_parts[:amd].nil? || !id_parts[:amd].nil?) &&
|
@@ -18,30 +18,55 @@ module RelatonJis
|
|
18
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 hit.fetch if hit.
|
32
|
+
return hit.fetch if hit.eq? ref_parts, ref_year
|
25
33
|
|
26
|
-
missed_years << hit.id_parts[:year] if
|
34
|
+
missed_years << hit.id_parts[:year] if hit.eq?(ref_parts)
|
27
35
|
end
|
28
36
|
missed_years
|
29
37
|
end
|
30
38
|
|
31
|
-
def
|
32
|
-
hits = @array.select { |hit| hit.
|
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
|
46
|
+
|
47
|
+
parent.relation << create_relation(hit)
|
48
|
+
end
|
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 }
|
33
54
|
item = hits.min_by { |i| i.id_parts[:part].to_i }.fetch.to_all_parts
|
34
55
|
hits.each do |hit|
|
35
56
|
next if hit.hit[:id] == item.docidentifier.first.id
|
36
57
|
|
37
|
-
|
38
|
-
fref = RelatonBib::FormattedRef.new content: hit.hit[:id]
|
39
|
-
bibitem = BibliographicItem.new docid: [docid], formattedref: fref
|
40
|
-
item.relation << RelatonBib::DocumentRelation.new(type: "instance", bibitem: bibitem)
|
58
|
+
item.relation << create_relation(hit)
|
41
59
|
end
|
42
60
|
item
|
43
61
|
end
|
44
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)
|
68
|
+
end
|
69
|
+
|
45
70
|
#
|
46
71
|
# Return parts of reference
|
47
72
|
#
|
data/lib/relaton_jis/scraper.rb
CHANGED
@@ -104,17 +104,18 @@ module RelatonJis
|
|
104
104
|
|
105
105
|
def fetch_doctype
|
106
106
|
case document_id
|
107
|
-
when /JIS\s[A-Z]\s[\w-]+:\d{4}\/
|
107
|
+
when /JIS\s[A-Z]\s[\w-]+:\d{4}\/AMENDMENT/ then "amendment"
|
108
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"
|
109
|
+
when /TR[\s\/][\w-]+/ then "technical-report"
|
110
|
+
when /TS[\s\/][\w-]+/ then "technical-specification"
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
114
|
def fetch_ics
|
115
|
-
@doc.
|
116
|
-
|
117
|
-
|
115
|
+
td = @doc.at("./table/tr[th[.='ICS']]/td")
|
116
|
+
return [] unless td
|
117
|
+
|
118
|
+
td.text.strip.split.map { |code| RelatonIsoBib::Ics.new code }
|
118
119
|
end
|
119
120
|
|
120
121
|
def fetch_contributor
|
data/lib/relaton_jis/version.rb
CHANGED
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.
|
4
|
+
version: 1.14.3
|
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-
|
11
|
+
date: 2023-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mechanize
|
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
|
-
rubygems_version: 3.
|
106
|
+
rubygems_version: 3.3.26
|
107
107
|
signing_key:
|
108
108
|
specification_version: 4
|
109
109
|
summary: 'RelatonJis: retrieve IETF Standards for bibliographic use using the BibliographicItem
|