relaton-nist 0.3.9 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/grammars/nist.rng ADDED
@@ -0,0 +1,227 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
3
+ <!--
4
+ Currently we inherit from a namespaced grammar, isostandard. Until we inherit from isodoc,
5
+ we cannot have a new default namespace: we will end up with a grammar with two different
6
+ namespaces, one for isostandard and one for csand additions. And we do not want that.
7
+ -->
8
+ <include href="isostandard.rng">
9
+ <start>
10
+ <ref name="nist-standard"/>
11
+ </start>
12
+ <define name="figure">
13
+ <element name="figure">
14
+ <attribute name="id">
15
+ <data type="ID"/>
16
+ </attribute>
17
+ <optional>
18
+ <ref name="tname"/>
19
+ </optional>
20
+ <choice>
21
+ <ref name="image"/>
22
+ <ref name="pre"/>
23
+ <oneOrMore>
24
+ <ref name="subfigure"/>
25
+ </oneOrMore>
26
+ </choice>
27
+ <zeroOrMore>
28
+ <ref name="fn"/>
29
+ </zeroOrMore>
30
+ <optional>
31
+ <ref name="dl"/>
32
+ </optional>
33
+ <zeroOrMore>
34
+ <ref name="note"/>
35
+ </zeroOrMore>
36
+ </element>
37
+ </define>
38
+ <define name="subfigure">
39
+ <element name="figure">
40
+ <attribute name="id">
41
+ <data type="ID"/>
42
+ </attribute>
43
+ <optional>
44
+ <ref name="tname"/>
45
+ </optional>
46
+ <choice>
47
+ <ref name="image"/>
48
+ <ref name="pre"/>
49
+ </choice>
50
+ </element>
51
+ </define>
52
+ <define name="DocumentType">
53
+ <value>standard</value>
54
+ </define>
55
+ <define name="TitleType">
56
+ <choice>
57
+ <value>alternative</value>
58
+ <value>original</value>
59
+ <value>unofficial</value>
60
+ <value>subtitle</value>
61
+ <value>main</value>
62
+ </choice>
63
+ </define>
64
+ <!-- DocRelationType |= "obsoletedBy" | "supersedes" | "supersededBy" -->
65
+ <define name="DocRelationType">
66
+ <choice>
67
+ <value>obsoletes</value>
68
+ <value>updates</value>
69
+ <value>updatedBy</value>
70
+ <value>complements</value>
71
+ <value>derivedFrom</value>
72
+ <value>translatedFrom</value>
73
+ <value>adoptedFrom</value>
74
+ <value>equivalent</value>
75
+ <value>identical</value>
76
+ <value>nonequivalent</value>
77
+ <value>includedIn</value>
78
+ <value>includes</value>
79
+ <value>instance</value>
80
+ <value>partOf</value>
81
+ <value>hasDraft</value>
82
+ <value>obsoletedBy</value>
83
+ <value>supersedes</value>
84
+ <value>supersededBy</value>
85
+ </choice>
86
+ </define>
87
+ <!-- BibliographicDateType |= "abandoned" | "superseded" -->
88
+ <define name="BibliographicDateType">
89
+ <choice>
90
+ <value>published</value>
91
+ <value>accessed</value>
92
+ <value>created</value>
93
+ <value>implemented</value>
94
+ <value>obsoleted</value>
95
+ <value>confirmed</value>
96
+ <value>updated</value>
97
+ <value>issued</value>
98
+ <value>transmitted</value>
99
+ <value>copied</value>
100
+ <value>unchanged</value>
101
+ <value>circulated</value>
102
+ <value>abandoned</value>
103
+ <value>superseded</value>
104
+ </choice>
105
+ </define>
106
+ <define name="preface">
107
+ <element name="preface">
108
+ <optional>
109
+ <ref name="preface_abstract"/>
110
+ </optional>
111
+ <optional>
112
+ <ref name="foreword"/>
113
+ </optional>
114
+ <zeroOrMore>
115
+ <ref name="clause"/>
116
+ </zeroOrMore>
117
+ <optional>
118
+ <ref name="reviewernote"/>
119
+ </optional>
120
+ <optional>
121
+ <ref name="executivesummary"/>
122
+ </optional>
123
+ </element>
124
+ </define>
125
+ <define name="annex">
126
+ <element name="annex">
127
+ <optional>
128
+ <attribute name="id">
129
+ <data type="ID"/>
130
+ </attribute>
131
+ </optional>
132
+ <optional>
133
+ <attribute name="language"/>
134
+ </optional>
135
+ <optional>
136
+ <attribute name="script"/>
137
+ </optional>
138
+ <optional>
139
+ <attribute name="inline-header">
140
+ <data type="boolean"/>
141
+ </attribute>
142
+ </optional>
143
+ <optional>
144
+ <attribute name="obligation">
145
+ <choice>
146
+ <value>normative</value>
147
+ <value>informative</value>
148
+ </choice>
149
+ </attribute>
150
+ </optional>
151
+ <optional>
152
+ <ref name="section-title"/>
153
+ </optional>
154
+ <zeroOrMore>
155
+ <!--
156
+ allow hanging paragraps in annexes: they introduce lists
157
+ ( paragraph-with-footnote | table | note | formula | admonition | ol | ul | dl | figure | quote | sourcecode | review | example )*,
158
+ -->
159
+ <ref name="BasicBlock"/>
160
+ </zeroOrMore>
161
+ <zeroOrMore>
162
+ <ref name="note"/>
163
+ </zeroOrMore>
164
+ <choice>
165
+ <zeroOrMore>
166
+ <ref name="clause-hanging-paragraph-with-footnote"/>
167
+ </zeroOrMore>
168
+ <ref name="terms"/>
169
+ </choice>
170
+ </element>
171
+ </define>
172
+ <define name="BibDataExtensionType">
173
+ <optional>
174
+ <ref name="doctype"/>
175
+ </optional>
176
+ <optional>
177
+ <ref name="commentperiod"/>
178
+ </optional>
179
+ </define>
180
+ </include>
181
+ <define name="commentperiod">
182
+ <element name="commentperiod">
183
+ <element name="from">
184
+ <ref name="ISO8601Date"/>
185
+ </element>
186
+ <optional>
187
+ <element name="to">
188
+ <ref name="ISO8601Date"/>
189
+ </element>
190
+ </optional>
191
+ <optional>
192
+ <element name="extended">
193
+ <ref name="ISO8601Date"/>
194
+ </element>
195
+ </optional>
196
+ </element>
197
+ </define>
198
+ <define name="reviewernote">
199
+ <element name="reviewernote">
200
+ <ref name="Basic-Section"/>
201
+ </element>
202
+ </define>
203
+ <define name="executivesummary">
204
+ <element name="executivesummary">
205
+ <ref name="Basic-Section"/>
206
+ </element>
207
+ </define>
208
+ <define name="nist-standard">
209
+ <element name="nist-standard">
210
+ <ref name="bibdata"/>
211
+ <zeroOrMore>
212
+ <ref name="termdocsource"/>
213
+ </zeroOrMore>
214
+ <optional>
215
+ <ref name="boilerplate"/>
216
+ </optional>
217
+ <ref name="preface"/>
218
+ <oneOrMore>
219
+ <ref name="sections"/>
220
+ </oneOrMore>
221
+ <zeroOrMore>
222
+ <ref name="annex"/>
223
+ </zeroOrMore>
224
+ <ref name="bibliography"/>
225
+ </element>
226
+ </define>
227
+ </grammar>
data/grammars/reqt.rng ADDED
@@ -0,0 +1,165 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
3
+ <!--
4
+ Presupposes isodoc.rnc, is included in it
5
+ include "isodoc.rnc" { }
6
+ -->
7
+ <define name="requirement">
8
+ <element name="requirement">
9
+ <ref name="RequirementType"/>
10
+ </element>
11
+ </define>
12
+ <define name="recommendation">
13
+ <element name="recommendation">
14
+ <ref name="RequirementType"/>
15
+ </element>
16
+ </define>
17
+ <define name="permission">
18
+ <element name="permission">
19
+ <ref name="RequirementType"/>
20
+ </element>
21
+ </define>
22
+ <define name="RequirementType">
23
+ <optional>
24
+ <attribute name="obligation">
25
+ <ref name="ObligationType"/>
26
+ </attribute>
27
+ </optional>
28
+ <optional>
29
+ <attribute name="unnumbered">
30
+ <data type="boolean"/>
31
+ </attribute>
32
+ </optional>
33
+ <optional>
34
+ <attribute name="subsequence"/>
35
+ </optional>
36
+ <attribute name="id">
37
+ <data type="ID"/>
38
+ </attribute>
39
+ <optional>
40
+ <attribute name="filename"/>
41
+ </optional>
42
+ <optional>
43
+ <ref name="reqtitle"/>
44
+ </optional>
45
+ <optional>
46
+ <ref name="label"/>
47
+ </optional>
48
+ <optional>
49
+ <ref name="subject"/>
50
+ </optional>
51
+ <optional>
52
+ <ref name="reqinherit"/>
53
+ </optional>
54
+ <zeroOrMore>
55
+ <ref name="classification"/>
56
+ </zeroOrMore>
57
+ <zeroOrMore>
58
+ <choice>
59
+ <ref name="measurementtarget"/>
60
+ <ref name="specification"/>
61
+ <ref name="verification"/>
62
+ <ref name="import"/>
63
+ <ref name="description"/>
64
+ </choice>
65
+ </zeroOrMore>
66
+ <optional>
67
+ <ref name="reqt_references"/>
68
+ </optional>
69
+ <zeroOrMore>
70
+ <choice>
71
+ <ref name="requirement"/>
72
+ <ref name="recommendation"/>
73
+ <ref name="permission"/>
74
+ </choice>
75
+ </zeroOrMore>
76
+ </define>
77
+ <define name="reqtitle">
78
+ <element name="title">
79
+ <ref name="FormattedString"/>
80
+ </element>
81
+ </define>
82
+ <define name="label">
83
+ <element name="label">
84
+ <text/>
85
+ </element>
86
+ </define>
87
+ <define name="subject">
88
+ <element name="subject">
89
+ <text/>
90
+ </element>
91
+ </define>
92
+ <define name="reqinherit">
93
+ <element name="inherit">
94
+ <text/>
95
+ </element>
96
+ </define>
97
+ <define name="measurementtarget">
98
+ <element name="measurement-target">
99
+ <ref name="RequirementSubpart"/>
100
+ </element>
101
+ </define>
102
+ <define name="specification">
103
+ <element name="specification">
104
+ <ref name="RequirementSubpart"/>
105
+ </element>
106
+ </define>
107
+ <define name="verification">
108
+ <element name="verification">
109
+ <ref name="RequirementSubpart"/>
110
+ </element>
111
+ </define>
112
+ <define name="import">
113
+ <element name="import">
114
+ <ref name="RequirementSubpart"/>
115
+ </element>
116
+ </define>
117
+ <define name="description">
118
+ <element name="description">
119
+ <ref name="RequirementSubpart"/>
120
+ </element>
121
+ </define>
122
+ <define name="reqt_references">
123
+ <element name="references">
124
+ <oneOrMore>
125
+ <ref name="bibitem"/>
126
+ </oneOrMore>
127
+ </element>
128
+ </define>
129
+ <define name="RequirementSubpart">
130
+ <optional>
131
+ <attribute name="type"/>
132
+ </optional>
133
+ <optional>
134
+ <attribute name="exclude">
135
+ <data type="boolean"/>
136
+ </attribute>
137
+ </optional>
138
+ <oneOrMore>
139
+ <ref name="BasicBlock"/>
140
+ </oneOrMore>
141
+ </define>
142
+ <define name="ObligationType">
143
+ <choice>
144
+ <value>requirement</value>
145
+ <value>recommendation</value>
146
+ <value>permission</value>
147
+ </choice>
148
+ </define>
149
+ <define name="classification">
150
+ <element name="classification">
151
+ <ref name="classification_tag"/>
152
+ <ref name="classification_value"/>
153
+ </element>
154
+ </define>
155
+ <define name="classification_tag">
156
+ <element name="tag">
157
+ <text/>
158
+ </element>
159
+ </define>
160
+ <define name="classification_value">
161
+ <element name="value">
162
+ <text/>
163
+ </element>
164
+ </define>
165
+ </grammar>
data/lib/relaton_nist.rb CHANGED
@@ -8,4 +8,13 @@ require "relaton_nist/nist_bibliography"
8
8
 
9
9
  module RelatonNist
10
10
  class Error < StandardError; end
11
+
12
+ # Returns hash of XML reammar
13
+ # @return [String]
14
+ def self.grammar_hash
15
+ gem_path = File.expand_path "..", __dir__
16
+ grammars_path = File.join gem_path, "grammars", "*"
17
+ grammars = Dir[grammars_path].sort.map { |gp| File.read gp }.join
18
+ Digest::MD5.hexdigest grammars
19
+ end
11
20
  end
@@ -9,17 +9,12 @@ module RelatonNist
9
9
  ret = super
10
10
  return if ret.nil?
11
11
 
12
- keyword_hash_to_bib(ret)
13
12
  commentperiod_hash_to_bib(ret)
14
13
  ret
15
14
  end
16
15
 
17
16
  private
18
17
 
19
- def keyword_hash_to_bib(ret)
20
- ret[:keyword]&.map! { |kw| Keyword.new kw }
21
- end
22
-
23
18
  def commentperiod_hash_to_bib(ret)
24
19
  return unless ret[:commentperiod]
25
20
 
@@ -16,17 +16,18 @@ module RelatonNist
16
16
  def sort_value
17
17
  @sort_value ||= begin
18
18
  sort_phrase = [hit[:serie], hit[:code], hit[:title]].join " "
19
- corr = hit_collection.text.split.map do |w|
19
+ corr = hit_collection&.text&.split&.map do |w|
20
20
  if w =~ /\w+/ &&
21
21
  sort_phrase =~ Regexp.new(Regexp.escape(w), Regexp::IGNORECASE)
22
22
  1
23
23
  else 0
24
24
  end
25
- end.sum
25
+ end&.sum.to_i
26
26
  corr + case hit[:status]
27
- when "final" then 3
28
- when "withdrawn" then 2
29
- when "draft (withdrawn)" then 1
27
+ when "final" then 4
28
+ when "withdrawn" then 3
29
+ when "draft" then 2
30
+ when "draft (obsolete)" then 1
30
31
  else 0
31
32
  end
32
33
  end