relaton-itu 1.6.pre1 → 1.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +10 -0
- data/grammars/isodoc.rng +14 -43
- data/grammars/itu.rng +14 -0
- data/lib/relaton_itu/hit_collection.rb +4 -5
- data/lib/relaton_itu/itu_bibliographic_item.rb +1 -1
- data/lib/relaton_itu/itu_bibliography.rb +29 -13
- data/lib/relaton_itu/scrapper.rb +30 -16
- data/lib/relaton_itu/version.rb +1 -1
- data/relaton-itu.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 971645ffb5b0111df7d841c47f6ac1a64904cc85274218f2f6ff622dbba3b576
|
4
|
+
data.tar.gz: 68bc7e0bbb844896c7bf30c6d3e5747a9d6f0e68aa9384f9e761f2881f3be2bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83a9d8ee974bfe44cad5715db0199dfcf1eec9709d2a1d778d08cdc21379a69063bb6d6f0ee818b962f825c684d680bb4dda5cbba9b0ca48b24dc8dde4876cdd
|
7
|
+
data.tar.gz: 96a7cf63dd9ff84a115959d7766544e8d8f5f1328fa976737875b7808152939f1168e6a1644e0eb5e4af5cd22f6077b232cf45968e6945bc1a86d2a7721f8e19
|
data/README.adoc
CHANGED
@@ -87,6 +87,16 @@ RelatonItu::ItuBibliography.get("ITU-T L.163", "2018", {})
|
|
87
87
|
...
|
88
88
|
----
|
89
89
|
|
90
|
+
=== Get amendment
|
91
|
+
[source,ruby]
|
92
|
+
----
|
93
|
+
RelatonItu::ItuBibliography.get "ITU-T G.989.2/Amd 1"
|
94
|
+
[relaton-itu] ("ITU-T G.989.2/Amd 1") fetching...
|
95
|
+
[relaton-itu] ("ITU-T G.989.2/Amd 1") found ITU-T G.989.2/Amd 1
|
96
|
+
=> #<RelatonItu::ItuBibliographicItem:0x007fe5409e5840
|
97
|
+
...
|
98
|
+
----
|
99
|
+
|
90
100
|
=== Create bibliographic item form YAML
|
91
101
|
[source,ruby]
|
92
102
|
----
|
data/grammars/isodoc.rng
CHANGED
@@ -24,6 +24,14 @@
|
|
24
24
|
<start>
|
25
25
|
<ref name="standard-document"/>
|
26
26
|
</start>
|
27
|
+
<define name="doctype">
|
28
|
+
<element name="doctype">
|
29
|
+
<optional>
|
30
|
+
<attribute name="abbreviation"/>
|
31
|
+
</optional>
|
32
|
+
<ref name="DocumentType"/>
|
33
|
+
</element>
|
34
|
+
</define>
|
27
35
|
<define name="hyperlink">
|
28
36
|
<element name="link">
|
29
37
|
<attribute name="target">
|
@@ -141,6 +149,11 @@
|
|
141
149
|
<data type="boolean"/>
|
142
150
|
</attribute>
|
143
151
|
</optional>
|
152
|
+
<optional>
|
153
|
+
<attribute name="key">
|
154
|
+
<data type="boolean"/>
|
155
|
+
</attribute>
|
156
|
+
</optional>
|
144
157
|
<oneOrMore>
|
145
158
|
<ref name="dt"/>
|
146
159
|
<ref name="dd"/>
|
@@ -1164,49 +1177,7 @@
|
|
1164
1177
|
</define>
|
1165
1178
|
<define name="annex">
|
1166
1179
|
<element name="annex">
|
1167
|
-
<
|
1168
|
-
<attribute name="id">
|
1169
|
-
<data type="ID"/>
|
1170
|
-
</attribute>
|
1171
|
-
</optional>
|
1172
|
-
<optional>
|
1173
|
-
<attribute name="language"/>
|
1174
|
-
</optional>
|
1175
|
-
<optional>
|
1176
|
-
<attribute name="script"/>
|
1177
|
-
</optional>
|
1178
|
-
<optional>
|
1179
|
-
<attribute name="inline-header">
|
1180
|
-
<data type="boolean"/>
|
1181
|
-
</attribute>
|
1182
|
-
</optional>
|
1183
|
-
<attribute name="obligation">
|
1184
|
-
<choice>
|
1185
|
-
<value>normative</value>
|
1186
|
-
<value>informative</value>
|
1187
|
-
</choice>
|
1188
|
-
</attribute>
|
1189
|
-
<optional>
|
1190
|
-
<ref name="section-title"/>
|
1191
|
-
</optional>
|
1192
|
-
<group>
|
1193
|
-
<group>
|
1194
|
-
<zeroOrMore>
|
1195
|
-
<ref name="BasicBlock"/>
|
1196
|
-
</zeroOrMore>
|
1197
|
-
<zeroOrMore>
|
1198
|
-
<ref name="note"/>
|
1199
|
-
</zeroOrMore>
|
1200
|
-
</group>
|
1201
|
-
<zeroOrMore>
|
1202
|
-
<choice>
|
1203
|
-
<ref name="annex-subsection"/>
|
1204
|
-
<ref name="terms"/>
|
1205
|
-
<ref name="definitions"/>
|
1206
|
-
<ref name="references"/>
|
1207
|
-
</choice>
|
1208
|
-
</zeroOrMore>
|
1209
|
-
</group>
|
1180
|
+
<ref name="Annex-Section"/>
|
1210
1181
|
</element>
|
1211
1182
|
</define>
|
1212
1183
|
<define name="terms">
|
data/grammars/itu.rng
CHANGED
@@ -41,6 +41,9 @@
|
|
41
41
|
<value>technical-report</value>
|
42
42
|
<value>joint-itu-iso-iec</value>
|
43
43
|
<value>resolution</value>
|
44
|
+
<value>service-publication</value>
|
45
|
+
<value>handbook</value>
|
46
|
+
<value>question</value>
|
44
47
|
</choice>
|
45
48
|
</define>
|
46
49
|
<define name="editorialgroup">
|
@@ -97,6 +100,9 @@
|
|
97
100
|
<optional>
|
98
101
|
<ref name="meeting"/>
|
99
102
|
</optional>
|
103
|
+
<optional>
|
104
|
+
<ref name="meeting-place"/>
|
105
|
+
</optional>
|
100
106
|
<optional>
|
101
107
|
<ref name="meeting-date"/>
|
102
108
|
</optional>
|
@@ -127,6 +133,14 @@
|
|
127
133
|
</include>
|
128
134
|
<define name="meeting">
|
129
135
|
<element name="meeting">
|
136
|
+
<optional>
|
137
|
+
<attribute name="acronym"/>
|
138
|
+
</optional>
|
139
|
+
<text/>
|
140
|
+
</element>
|
141
|
+
</define>
|
142
|
+
<define name="meeting-place">
|
143
|
+
<element name="meeting-place">
|
130
144
|
<text/>
|
131
145
|
</element>
|
132
146
|
</define>
|
@@ -54,7 +54,7 @@ module RelatonItu
|
|
54
54
|
"Selected" => false,
|
55
55
|
"Value" => "",
|
56
56
|
"Label" => "Name",
|
57
|
-
"Target" => "
|
57
|
+
"Target" => "\\/name_s",
|
58
58
|
"TypeName" => "CHECKBOX",
|
59
59
|
"GetCriteriaType" => 0,
|
60
60
|
},
|
@@ -62,7 +62,7 @@ module RelatonItu
|
|
62
62
|
"Selected" => false,
|
63
63
|
"Value" => "",
|
64
64
|
"Label" => "Short description",
|
65
|
-
"Target" => "
|
65
|
+
"Target" => "\\/short_description_s",
|
66
66
|
"TypeName" => "CHECKBOX",
|
67
67
|
"GetCriteriaType" => 0,
|
68
68
|
},
|
@@ -70,7 +70,7 @@ module RelatonItu
|
|
70
70
|
"Selected" => false,
|
71
71
|
"Value" => "",
|
72
72
|
"Label" => "File content",
|
73
|
-
"Target" => "
|
73
|
+
"Target" => "\\/file",
|
74
74
|
"TypeName" => "CHECKBOX",
|
75
75
|
"GetCriteriaType" => 0,
|
76
76
|
},
|
@@ -79,9 +79,8 @@ module RelatonItu
|
|
79
79
|
"Selected" => false,
|
80
80
|
}],
|
81
81
|
"Topics" => "",
|
82
|
-
"ClientData" => {
|
82
|
+
"ClientData" => {},
|
83
83
|
"Language" => "en",
|
84
|
-
"IP" => "",
|
85
84
|
"SearchType" => "All",
|
86
85
|
}
|
87
86
|
end
|
@@ -4,7 +4,7 @@ module RelatonItu
|
|
4
4
|
recommendation recommendation-supplement recommendation-amendment
|
5
5
|
recommendation-corrigendum recommendation-errata recommendation-annex
|
6
6
|
focus-group implementers-guide technical-paper technical-report
|
7
|
-
joint-itu-iso-iec
|
7
|
+
joint-itu-iso-iec resolution service-publication handbook question
|
8
8
|
].freeze
|
9
9
|
|
10
10
|
# @params structuredidentifier [RelatonItu::StructuredIdentifier]
|
@@ -30,7 +30,7 @@ module RelatonItu
|
|
30
30
|
# @param year [String] the year the standard was published (optional)
|
31
31
|
# @param opts [Hash] options; restricted to :all_parts if all-parts reference is required
|
32
32
|
# @return [String] Relaton XML serialisation of reference
|
33
|
-
def get(code, year = nil, opts = {})
|
33
|
+
def get(code, year = nil, opts = {}) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
34
34
|
if year.nil?
|
35
35
|
/^(?<code1>[^\s]+\s[^\s]+)\s\(\d{2}\/(?<year1>\d+)\)$/ =~ code
|
36
36
|
unless code1.nil?
|
@@ -50,7 +50,7 @@ module RelatonItu
|
|
50
50
|
|
51
51
|
private
|
52
52
|
|
53
|
-
def fetch_ref_err(code, year, missed_years)
|
53
|
+
def fetch_ref_err(code, year, missed_years) # rubocop:disable Metrics/MethodLength
|
54
54
|
id = year ? "#{code}:#{year}" : code
|
55
55
|
warn "[relaton-itu] WARNING: no match found online for #{id}. "\
|
56
56
|
"The code must be exactly like it is on the standards website."
|
@@ -67,14 +67,35 @@ module RelatonItu
|
|
67
67
|
nil
|
68
68
|
end
|
69
69
|
|
70
|
-
def search_filter(code)
|
71
|
-
|
72
|
-
|
70
|
+
def search_filter(code, year) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
71
|
+
%r{
|
72
|
+
^(?<pref1>ITU)?(-(?<type1>\w))?\s?(?<code1>[^\s\/]+)
|
73
|
+
(\s\(((?<month1>\d{2})\/)?(?<year1>\d{4})\))?
|
74
|
+
(\s-\s(?<buldate1>\d{2}\.\w{1,4}\.\d{4}))?
|
75
|
+
(\/(?<corr1>(Amd|Cor)\s?\d+))?
|
76
|
+
(\s\(((?<cormonth1>\d{2})\/)?(?<coryear1>\d{4})\))?
|
77
|
+
}x =~ code
|
78
|
+
year ||= year1
|
79
|
+
# docidrx = %r{\w+\.\d+|\w\sSuppl\.\s\d+} # %r{^ITU-T\s[^\s]+}
|
80
|
+
# c = code.sub(/Imp\s?/, "").match(docidrx).to_s
|
73
81
|
warn "[relaton-itu] (\"#{code}\") fetching..."
|
74
82
|
result = search(code)
|
83
|
+
code1.sub! /(?<=\.)Imp(?=\d)/, "" if result.gi_imp
|
75
84
|
result.select do |i|
|
76
|
-
|
77
|
-
|
85
|
+
%r{
|
86
|
+
^(?<pref2>ITU)?(-(?<type2>\w))?\s?(?<code2>[\S]+)
|
87
|
+
(\s\(((?<month2>\d{2})\/)?(?<year2>\d{4})\))?
|
88
|
+
(\s(?<corr2>(Amd|Cor)\.\s?\d+))?
|
89
|
+
(\s\(((?<cormonth2>\d{2})\/)?(?<coryear2>\d{4})\))?
|
90
|
+
}x =~ i.hit[:code]
|
91
|
+
/:[^\(]+\((?<buldate2>\d{2}\.\w{1,4}\.\d{4})\)/ =~ i.hit[:title]
|
92
|
+
corr2&.sub! /\.\s?/, " "
|
93
|
+
pref1 == pref2 && (!type1 || type1 == type2) && code1 == code2 &&
|
94
|
+
(!year || year == year2) && (!month1 || month1 == month2) &&
|
95
|
+
corr1 == corr2 && (!coryear1 || coryear1 == coryear2) &&
|
96
|
+
buldate1 == buldate2 && (!cormonth1 || cormonth1 == cormonth2)
|
97
|
+
# i.hit[:code] &&
|
98
|
+
# i.hit[:code].match(docidrx).to_s == c
|
78
99
|
end
|
79
100
|
end
|
80
101
|
|
@@ -86,24 +107,19 @@ module RelatonItu
|
|
86
107
|
# If no match, returns any years which caused mismatch, for error reporting
|
87
108
|
def isobib_results_filter(result, year)
|
88
109
|
missed_years = []
|
89
|
-
# result.each_slice(3) do |s| # ISO website only allows 3 connections
|
90
|
-
# fetch_pages(s, 3).each do |r|
|
91
110
|
result.each do |r|
|
92
111
|
return { ret: r.fetch } if !year
|
93
112
|
|
94
113
|
/\(\d{2}\/(?<pyear>\d{4})\)/ =~ r.hit[:code]
|
95
|
-
# r.date.select { |d| d.type == "published" }.each do |d|
|
96
114
|
return { ret: r.fetch } if year == pyear
|
97
115
|
|
98
116
|
missed_years << pyear
|
99
|
-
# end
|
100
|
-
# end
|
101
117
|
end
|
102
118
|
{ years: missed_years }
|
103
119
|
end
|
104
120
|
|
105
121
|
def itubib_get1(code, year, _opts)
|
106
|
-
result = search_filter(code) || return
|
122
|
+
result = search_filter(code, year) || return
|
107
123
|
ret = isobib_results_filter(result, year)
|
108
124
|
if ret[:ret]
|
109
125
|
warn "[relaton-itu] (\"#{code}\") found #{ret[:ret].docidentifier.first&.id}"
|
data/lib/relaton_itu/scrapper.rb
CHANGED
@@ -44,7 +44,7 @@ module RelatonItu
|
|
44
44
|
ItuBibliographicItem.new(
|
45
45
|
fetched: Date.today.to_s,
|
46
46
|
type: "standard",
|
47
|
-
docid: fetch_docid(doc),
|
47
|
+
docid: fetch_docid(doc, hit_data[:title]),
|
48
48
|
edition: edition,
|
49
49
|
language: ["en"],
|
50
50
|
script: ["Latn"],
|
@@ -59,7 +59,7 @@ module RelatonItu
|
|
59
59
|
copyright: fetch_copyright(hit_data[:code], doc),
|
60
60
|
link: fetch_link(doc, url),
|
61
61
|
relation: fetch_relations(doc),
|
62
|
-
place: ["Geneva"]
|
62
|
+
place: ["Geneva"]
|
63
63
|
)
|
64
64
|
end
|
65
65
|
# rubocop:enable Metrics/AbcSize
|
@@ -92,7 +92,7 @@ module RelatonItu
|
|
92
92
|
uri = URI url
|
93
93
|
resp = Net::HTTP.get_response(uri)
|
94
94
|
until resp.code == "200"
|
95
|
-
uri = URI resp["location"] if resp.code
|
95
|
+
uri = URI resp["location"] if resp.code.match? /^30/
|
96
96
|
resp = Net::HTTP.get_response(uri)
|
97
97
|
end
|
98
98
|
[uri.to_s, Nokogiri::HTML(resp.body)]
|
@@ -105,18 +105,32 @@ module RelatonItu
|
|
105
105
|
|
106
106
|
# Fetch docid.
|
107
107
|
# @param doc [Nokogiri::HTML::Document]
|
108
|
+
# @param title [String]
|
108
109
|
# @return [Hash]
|
109
|
-
def fetch_docid(doc)
|
110
|
-
doc.xpath(
|
110
|
+
def fetch_docid(doc, title)
|
111
|
+
docids = doc.xpath(
|
111
112
|
"//span[@id='ctl00_content_main_uc_rec_main_info1_rpt_main_ctl00_lbl_rec']",
|
112
113
|
"//td[.='Identical standard:']/following-sibling::td",
|
113
|
-
"//div/table[1]/tr[4]/td/strong"
|
114
|
-
).map
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
114
|
+
"//div/table[1]/tr[4]/td/strong"
|
115
|
+
).map { |c| createdocid c.text }
|
116
|
+
docids << createdocid(title) unless docids.any?
|
117
|
+
docids
|
118
|
+
end
|
119
|
+
|
120
|
+
def createdocid(text)
|
121
|
+
%r{
|
122
|
+
^(?<code>((ITU-\w|ISO\/IEC)\s)?[^\(:]+)
|
123
|
+
(\(((?<month>\d{2})\/)?(?<year>\d{4})\))?
|
124
|
+
(:[^\(]+\((?<buldate>\d{2}\.\w{1,4}\.\d{4})\))?
|
125
|
+
(\s(?<corr>(Amd|Cor)\.\s?\d+))?
|
126
|
+
# (\s\(((?<cormonth>\d{2})\/)?(?<coryear>\d{4})\))?
|
127
|
+
}x =~ text.squeeze(" ")
|
128
|
+
corr&.sub! /\.\s?/, " "
|
129
|
+
id = [code.sub(/[[:space:]]$/, ""), corr].compact.join "/"
|
130
|
+
id += " - #{buldate}" if buldate
|
131
|
+
type = id.match(%r{^\w+}).to_s
|
132
|
+
type = "ITU" if type == "G"
|
133
|
+
RelatonBib::DocumentIdentifier.new(type: type, id: id)
|
120
134
|
end
|
121
135
|
|
122
136
|
# Fetch status.
|
@@ -142,13 +156,13 @@ module RelatonItu
|
|
142
156
|
group = wg && itugroup(wg.text)
|
143
157
|
EditorialGroup.new(
|
144
158
|
bureau: code.match(/(?<=-)./).to_s,
|
145
|
-
group: group
|
159
|
+
group: group
|
146
160
|
)
|
147
161
|
end
|
148
162
|
|
149
163
|
# @param name [String]
|
150
164
|
# @return [RelatonItu::ItuGroup]
|
151
|
-
def itugroup(name)
|
165
|
+
def itugroup(name) # rubocop:disable Metrics/MethodLength
|
152
166
|
if name.include? "Study Group"
|
153
167
|
type = "study-group"
|
154
168
|
acronym = "SG"
|
@@ -190,7 +204,7 @@ module RelatonItu
|
|
190
204
|
# Fetch dates
|
191
205
|
# @param doc [Nokogiri::HTML::Document]
|
192
206
|
# @return [Array<Hash>]
|
193
|
-
def fetch_dates(doc)
|
207
|
+
def fetch_dates(doc) # rubocop:disable Metrics/CyclomaticComplexity
|
194
208
|
dates = []
|
195
209
|
date = doc.at("//table/tr/td/span[contains(@id, 'Label5')]",
|
196
210
|
"//p[contains(.,'Approved in')]")
|
@@ -244,7 +258,7 @@ module RelatonItu
|
|
244
258
|
links = [{ type: "src", content: url }]
|
245
259
|
obp_elm = doc.at(
|
246
260
|
'//a[@title="Persistent link to download the PDF file"]',
|
247
|
-
"//font[contains(.,'PDF')]/../.."
|
261
|
+
"//font[contains(.,'PDF')]/../.."
|
248
262
|
)
|
249
263
|
links << typed_link("obp", obp_elm) if obp_elm
|
250
264
|
wrd_elm = doc.at("//font[contains(.,'Word')]/../..")
|
data/lib/relaton_itu/version.rb
CHANGED
data/relaton-itu.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-itu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.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:
|
11
|
+
date: 2021-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: debase
|
@@ -156,14 +156,14 @@ dependencies:
|
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 1.
|
159
|
+
version: 1.7.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.7.0
|
167
167
|
description: 'RelatonItu: retrieve ITU Standards for bibliographic use using the BibliographicItem
|
168
168
|
model'
|
169
169
|
email:
|
@@ -218,9 +218,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
218
218
|
version: 2.4.0
|
219
219
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
220
220
|
requirements:
|
221
|
-
- - "
|
221
|
+
- - ">="
|
222
222
|
- !ruby/object:Gem::Version
|
223
|
-
version:
|
223
|
+
version: '0'
|
224
224
|
requirements: []
|
225
225
|
rubygems_version: 3.0.6
|
226
226
|
signing_key:
|