relaton-bsi 1.9.2 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -142,14 +142,9 @@
142
142
  </optional>
143
143
  <choice>
144
144
  <choice>
145
- <group>
146
- <oneOrMore>
147
- <ref name="BasicBlock"/>
148
- </oneOrMore>
149
- <zeroOrMore>
150
- <ref name="note"/>
151
- </zeroOrMore>
152
- </group>
145
+ <oneOrMore>
146
+ <ref name="BasicBlock"/>
147
+ </oneOrMore>
153
148
  <ref name="amend"/>
154
149
  </choice>
155
150
  <oneOrMore>
@@ -164,6 +159,20 @@
164
159
  <data type="ID"/>
165
160
  </attribute>
166
161
  </optional>
162
+ <optional>
163
+ <attribute name="language"/>
164
+ </optional>
165
+ <optional>
166
+ <attribute name="script"/>
167
+ </optional>
168
+ <optional>
169
+ <attribute name="tag"/>
170
+ </optional>
171
+ <optional>
172
+ <attribute name="multilingual-rendering">
173
+ <ref name="MultilingualRenderingType"/>
174
+ </attribute>
175
+ </optional>
167
176
  <ref name="preferred"/>
168
177
  <zeroOrMore>
169
178
  <ref name="admitted"/>
@@ -174,7 +183,7 @@
174
183
  <optional>
175
184
  <ref name="termdomain"/>
176
185
  </optional>
177
- <ref name="definition"/>
186
+ <ref name="termdefinition"/>
178
187
  <zeroOrMore>
179
188
  <ref name="termnote"/>
180
189
  </zeroOrMore>
@@ -184,6 +193,9 @@
184
193
  <zeroOrMore>
185
194
  <ref name="termsource"/>
186
195
  </zeroOrMore>
196
+ <zeroOrMore>
197
+ <ref name="term"/>
198
+ </zeroOrMore>
187
199
  </element>
188
200
  </define>
189
201
  <define name="annex">
@@ -222,9 +234,6 @@
222
234
  -->
223
235
  <ref name="BasicBlock"/>
224
236
  </zeroOrMore>
225
- <zeroOrMore>
226
- <ref name="note"/>
227
- </zeroOrMore>
228
237
  <zeroOrMore>
229
238
  <ref name="clause-hanging-paragraph-with-footnote"/>
230
239
  </zeroOrMore>
@@ -348,14 +357,9 @@
348
357
  <ref name="section-title"/>
349
358
  </optional>
350
359
  <choice>
351
- <group>
352
- <zeroOrMore>
353
- <ref name="BasicBlock"/>
354
- </zeroOrMore>
355
- <zeroOrMore>
356
- <ref name="note"/>
357
- </zeroOrMore>
358
- </group>
360
+ <zeroOrMore>
361
+ <ref name="BasicBlock"/>
362
+ </zeroOrMore>
359
363
  <oneOrMore>
360
364
  <ref name="content-subsection"/>
361
365
  </oneOrMore>
@@ -472,9 +476,6 @@
472
476
  <!-- allow hanging paragraphs in annexes: they introduce lists -->
473
477
  <ref name="BasicBlock"/>
474
478
  </zeroOrMore>
475
- <zeroOrMore>
476
- <ref name="note"/>
477
- </zeroOrMore>
478
479
  <zeroOrMore>
479
480
  <ref name="clause-hanging-paragraph-with-footnote"/>
480
481
  </zeroOrMore>
data/grammars/reqt.rng CHANGED
@@ -58,15 +58,23 @@
58
58
  <optional>
59
59
  <attribute name="type"/>
60
60
  </optional>
61
+ <optional>
62
+ <attribute name="tag"/>
63
+ </optional>
64
+ <optional>
65
+ <attribute name="multilingual-rendering">
66
+ <ref name="MultilingualRenderingType"/>
67
+ </attribute>
68
+ </optional>
61
69
  <optional>
62
70
  <ref name="reqtitle"/>
63
71
  </optional>
64
72
  <optional>
65
73
  <ref name="label"/>
66
74
  </optional>
67
- <optional>
75
+ <zeroOrMore>
68
76
  <ref name="subject"/>
69
- </optional>
77
+ </zeroOrMore>
70
78
  <zeroOrMore>
71
79
  <ref name="reqinherit"/>
72
80
  </zeroOrMore>
@@ -80,6 +88,7 @@
80
88
  <ref name="verification"/>
81
89
  <ref name="import"/>
82
90
  <ref name="description"/>
91
+ <ref name="component"/>
83
92
  </choice>
84
93
  </zeroOrMore>
85
94
  <optional>
@@ -100,17 +109,23 @@
100
109
  </define>
101
110
  <define name="label">
102
111
  <element name="label">
103
- <text/>
112
+ <oneOrMore>
113
+ <ref name="TextElement"/>
114
+ </oneOrMore>
104
115
  </element>
105
116
  </define>
106
117
  <define name="subject">
107
118
  <element name="subject">
108
- <text/>
119
+ <oneOrMore>
120
+ <ref name="TextElement"/>
121
+ </oneOrMore>
109
122
  </element>
110
123
  </define>
111
124
  <define name="reqinherit">
112
125
  <element name="inherit">
113
- <text/>
126
+ <oneOrMore>
127
+ <ref name="TextElement"/>
128
+ </oneOrMore>
114
129
  </element>
115
130
  </define>
116
131
  <define name="measurementtarget">
@@ -138,6 +153,12 @@
138
153
  <ref name="RequirementSubpart"/>
139
154
  </element>
140
155
  </define>
156
+ <define name="component">
157
+ <element name="component">
158
+ <attribute name="class"/>
159
+ <ref name="RequirementSubpart"/>
160
+ </element>
161
+ </define>
141
162
  <define name="reqt_references">
142
163
  <element name="references">
143
164
  <oneOrMore>
@@ -164,6 +185,14 @@
164
185
  <data type="boolean"/>
165
186
  </attribute>
166
187
  </optional>
188
+ <optional>
189
+ <attribute name="tag"/>
190
+ </optional>
191
+ <optional>
192
+ <attribute name="multilingual-rendering">
193
+ <ref name="MultilingualRenderingType"/>
194
+ </attribute>
195
+ </optional>
167
196
  <oneOrMore>
168
197
  <ref name="BasicBlock"/>
169
198
  </oneOrMore>
@@ -24,17 +24,21 @@ module RelatonBsi
24
24
  raise RelatonBib::RequestError, e.message
25
25
  end
26
26
 
27
+ #
27
28
  # @param code [String] the BSI standard Code to look up
28
29
  # @param year [String] the year the standard was published (optional)
29
- # @param opts [Hash] options; restricted to :all_parts if all-parts reference is required
30
+ # @param opts [Hash] options
31
+ # @option opts [Boolean] :all_parts if all-parts reference is required
32
+ # @option opts [Boolean] :no_year if last published document is required
33
+ #
30
34
  # @return [String] Relaton XML serialisation of reference
31
- def get(code, year = nil, opts = {}) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
32
- c, y = code.split ':'
33
- year ||= y
34
- ret = bib_get1(c, year, opts)
35
+ def get(code, year = nil, opts = {})
36
+ # y = code.split(":")[1]
37
+ year ||= code_parts(code)[:year]
38
+ ret = bib_get1(code, year, opts)
35
39
  return nil if ret.nil?
36
40
 
37
- # ret = ret.to_most_recent_reference unless year || opts[:keep_year]
41
+ ret = ret.to_most_recent_reference unless year || opts[:keep_year]
38
42
  # ret = ret.to_all_parts if opts[:all_parts]
39
43
  ret
40
44
  end
@@ -44,35 +48,48 @@ module RelatonBsi
44
48
  def fetch_ref_err(code, year, missed_years) # rubocop:disable Metrics/MethodLength
45
49
  id = year ? "#{code}:#{year}" : code
46
50
  warn "[relaton-bsi] WARNING: no match found online for #{id}. "\
47
- "The code must be exactly like it is on the standards website."
51
+ "The code must be exactly like it is on the standards website."
48
52
  unless missed_years.empty?
49
- warn "[relaton-bsi] (There was no match for #{year}, though there were matches "\
50
- "found for #{missed_years.join(', ')}.)"
53
+ warn "[relaton-bsi] (There was no match for #{year}, though there "\
54
+ "were matches found for #{missed_years.join(', ')}.)"
51
55
  end
52
56
  # if /\d-\d/.match? code
53
- # warn "[relaton-bsi] The provided document part may not exist, or the document "\
54
- # "may no longer be published in parts."
57
+ # warn "[relaton-bsi] The provided document part may not exist, or "\
58
+ # "the document may no longer be published in parts."
55
59
  # else
56
- # warn "[relaton-bsi] If you wanted to cite all document parts for the reference, "\
57
- # "use \"#{code} (all parts)\".\nIf the document is not a standard, "\
58
- # "use its document type abbreviation (TS, TR, PAS, Guide)."
60
+ # warn "[relaton-bsi] If you wanted to cite all document parts for "\
61
+ # "the reference, use \"#{code} (all parts)\".\nIf the document "\
62
+ # "is not a standard, use its document type abbreviation (TS, TR, "\
63
+ # "PAS, Guide)."
59
64
  # end
60
65
  nil
61
66
  end
62
67
 
63
68
  def search_filter(code) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
64
- # %r{^BSI\s(?<code1>[^:]+)} =~ code
65
- code1 = code.sub(/^BSI\s/, "")
69
+ # %r{^(?:BSI\s)?(?<code1>[^:]+)} =~ code
70
+ # %r{^(?<code1>[^:]+)} =~ code.sub(/^BSI\s/, "")
71
+ cp1 = code_parts code
66
72
  warn "[relaton-bsi] (\"#{code}\") fetching..."
67
- return [] unless code1
73
+ return [] unless cp1
68
74
 
69
75
  result = search(code)
70
76
  result.select do |i|
71
- %r{^(?<code2>[^:]+)} =~ i.hit[:code]
72
- code2.include?(code1)
77
+ # %r{^(?<code2>[^:]+)} =~ i.hit[:code]
78
+ cp2 = code_parts i.hit[:code]
79
+ cp2[:code] == cp1[:code] && (!cp1[:a] || cp2[:a] == cp1[:a]) &&
80
+ (!cp1[:y] || cp2[:y] == cp1[:y])
73
81
  end
74
82
  end
75
83
 
84
+ def code_parts(code)
85
+ %r{
86
+ ^(?:BSI\s)?(?<code>[^:]+)
87
+ (?::(?<year>\d{4}))?
88
+ (?:\+(?<a>[^:]+):)?
89
+ (?::(?<y>\d{4}))?
90
+ }x.match code
91
+ end
92
+
76
93
  # Sort through the results from Isobib, fetching them three at a time,
77
94
  # and return the first result that matches the code,
78
95
  # matches the year (if provided), and which # has a title (amendments do not).
@@ -8,16 +8,14 @@ module RelatonBsi
8
8
  class HitCollection < RelatonBib::HitCollection
9
9
  DOMAIN = "https://shop.bsigroup.com"
10
10
 
11
- # @return [Mechanize]
12
- # attr_reader :agent
13
-
14
11
  # @param ref [String]
15
12
  # @param year [String]
16
13
  def initialize(ref, year = nil)
17
14
  super ref, year
18
- # @agent = Mechanize.new
19
- # resp = agent.get "#{DOMAIN}/SearchResults/?q=#{ref}"
20
- config = Algolia::Search::Config.new(application_id: "575YE157G9", api_key: "a057b4e74099445df2eddb7940828a10")
15
+ config = Algolia::Search::Config.new(
16
+ application_id: "575YE157G9",
17
+ api_key: "a057b4e74099445df2eddb7940828a10",
18
+ )
21
19
  client = Algolia::Search::Client.new config, logger: ::Logger.new($stderr)
22
20
  index = client.init_index "shopify_products"
23
21
  resp = index.search text # , facetFilters: "product_type:standard"
@@ -28,11 +26,13 @@ module RelatonBsi
28
26
 
29
27
  # @param hits [Array<Hash>]
30
28
  # @return [Array<RelatonBsi::Hit>]
31
- def hits(hits) # rubocop:disable Metrics/MethodLength
29
+ def hits(hits) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
32
30
  hits.map do |h|
31
+ code = h[:meta][:global][:primaryDesignator]
32
+ .sub(/\s(?:LOOSELEAF|\(A5 LAMINATED\)|-\sTC$)/, "")
33
33
  Hit.new(
34
34
  {
35
- code: h[:meta][:global][:primaryDesignator],
35
+ code: code,
36
36
  title: h[:title],
37
37
  url: h[:handle],
38
38
  date: h[:meta][:global][:publishedDate],
@@ -42,7 +42,7 @@ module RelatonBsi
42
42
  doctype: h[:product_type],
43
43
  }, self
44
44
  )
45
- end
45
+ end.sort_by { |h| h.hit[:date] }.reverse
46
46
  end
47
47
  end
48
48
  end
@@ -118,7 +118,7 @@ module RelatonBsi
118
118
  # @param docid [String]
119
119
  # @param data [Hash]
120
120
  # @return [Array<RelatonBib::DocumentIdentifier>]
121
- def fetch_docid(docid, data)
121
+ def fetch_docid(docid, data) # rubocop:disable Metrics/AbcSize
122
122
  ids = [{ type: "BSI", id: docid }]
123
123
  if data.any? && data["variants"]["edges"][0]["node"]["isbn"]
124
124
  isbn = data["variants"]["edges"][0]["node"]["isbn"]["value"]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonBsi
4
- VERSION = "1.9.2"
4
+ VERSION = "1.10.0"
5
5
  end
data/relaton_bsi.gemspec CHANGED
@@ -37,7 +37,8 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency "webmock"
38
38
 
39
39
  spec.add_dependency "algolia", "~> 2.1.1"
40
+ spec.add_dependency "graphql", "1.13.6"
40
41
  spec.add_dependency "graphql-client", "~> 0.16.0"
41
42
  # spec.add_dependency "mechanize", "~> 2.8.0"
42
- spec.add_dependency "relaton-iso-bib", "~> 1.9.0"
43
+ spec.add_dependency "relaton-iso-bib", "~> 1.10.0"
43
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-bsi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.2
4
+ version: 1.10.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: 2021-11-04 00:00:00.000000000 Z
11
+ date: 2022-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: equivalent-xml
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 2.1.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: graphql
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 1.13.6
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 1.13.6
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: graphql-client
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +142,14 @@ dependencies:
128
142
  requirements:
129
143
  - - "~>"
130
144
  - !ruby/object:Gem::Version
131
- version: 1.9.0
145
+ version: 1.10.0
132
146
  type: :runtime
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - "~>"
137
151
  - !ruby/object:Gem::Version
138
- version: 1.9.0
152
+ version: 1.10.0
139
153
  description: 'RelatonBsi: retrieve BSI Standards for bibliographic use using the BibliographicItem
140
154
  model'
141
155
  email: