relaton-w3c 1.12.3 → 1.12.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/relaton_w3c/data_fetcher.rb +44 -13
- data/lib/relaton_w3c/data_parser.rb +55 -18
- data/lib/relaton_w3c/version.rb +1 -1
- data/lib/relaton_w3c/w3c_bibliographic_item.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99d8437c234f255a39c904f66b9a31a54bc8d96278cdf62be3097e53bc3f22d4
|
4
|
+
data.tar.gz: 42cb93c06794e8c72cbf81f43af3a7b3e4f5504f54215e2ac4872e61b84169bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f970f7fbcdf0f3490ceea00f891877bfc235e5c1ac6a3e2dbf61845686088800281ae7c2d09ac98c8a51a5d6e8b4e9447e4aaa0ab14db52be141265ed4b2999
|
7
|
+
data.tar.gz: 57b934f34559e319b627c1747133a807f4befbf1a41f28523197c6fc66e51484bab2b43feaea90e92c02f7a15a3dedde55a20b9cf5f97c3c6410b85a2fa3acbe
|
data/.gitignore
CHANGED
@@ -67,21 +67,52 @@ module RelatonW3c
|
|
67
67
|
#
|
68
68
|
# @param [RelatonW3c::W3cBibliographicItem] bib bibligraphic item
|
69
69
|
#
|
70
|
-
def add_has_edition_relation(bib) # rubocop:disable Metrics/
|
70
|
+
def add_has_edition_relation(bib) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
|
71
71
|
file = file_name bib.docnumber
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
when "bibxml" then BibXMLParser.parse File.read(file, encoding: "UTF-8")
|
80
|
-
end
|
81
|
-
b.relation.each do |r|
|
82
|
-
same_edition = bib.relation.detect { |r2| same_edition?(r, r2) }
|
83
|
-
bib.relation << r unless same_edition
|
72
|
+
if File.exist? file
|
73
|
+
item = send "read_#{@format}", file
|
74
|
+
item.relation.each do |r1|
|
75
|
+
r1.type = "hasEdition" if r1.type == "instance"
|
76
|
+
same_edition = bib.relation.detect { |r2| same_edition?(r1, r2) }
|
77
|
+
bib.relation << r1 unless same_edition
|
78
|
+
end
|
84
79
|
end
|
80
|
+
bib.relation.select { |r| r.type == "hasEdition" }
|
81
|
+
.max_by { |r| r.bibitem.id.match(/(?<=-)\d{8}$/).to_s }&.type = "instance"
|
82
|
+
end
|
83
|
+
|
84
|
+
#
|
85
|
+
# Read XML file
|
86
|
+
#
|
87
|
+
# @param [String] file file name
|
88
|
+
#
|
89
|
+
# @return [RelatonW3c::W3cBibliographicItem] bibliographic item
|
90
|
+
#
|
91
|
+
def read_xml(file)
|
92
|
+
XMLParser.from_xml(File.read(file, encoding: "UTF-8"))
|
93
|
+
end
|
94
|
+
|
95
|
+
#
|
96
|
+
# Read YAML file
|
97
|
+
#
|
98
|
+
# @param [String] file file name
|
99
|
+
#
|
100
|
+
# @return [RelatonW3c::W3cBibliographicItem] bibliographic item
|
101
|
+
#
|
102
|
+
def read_yaml(file)
|
103
|
+
hash = YAML.load_file(file)
|
104
|
+
W3cBibliographicItem.from_hash(hash)
|
105
|
+
end
|
106
|
+
|
107
|
+
#
|
108
|
+
# Read BibXML file
|
109
|
+
#
|
110
|
+
# @param [String] file file name
|
111
|
+
#
|
112
|
+
# @return [RelatonW3c::W3cBibliographicItem] bibliographic item
|
113
|
+
#
|
114
|
+
def read_bibxml(file)
|
115
|
+
BibXMLParser.parse File.read(file, encoding: "UTF-8")
|
85
116
|
end
|
86
117
|
|
87
118
|
#
|
@@ -101,7 +101,7 @@ module RelatonW3c
|
|
101
101
|
#
|
102
102
|
def parse_link
|
103
103
|
link = @sol.respond_to?(:link) ? @sol.link : @sol.version_of
|
104
|
-
[RelatonBib::TypedUri.new(type: "src", content: link.to_s.strip)]
|
104
|
+
[RelatonBib::TypedUri.new(type: "src", content: link.to_s.strip)] + editor_drafts
|
105
105
|
end
|
106
106
|
|
107
107
|
#
|
@@ -176,29 +176,64 @@ module RelatonW3c
|
|
176
176
|
#
|
177
177
|
# @return [Array<String>] types and stages
|
178
178
|
#
|
179
|
-
def types_stages
|
180
|
-
return unless @sol.respond_to?(:link)
|
181
|
-
|
179
|
+
def types_stages
|
182
180
|
@types_stages ||= begin
|
183
|
-
sse =
|
184
|
-
PREFIX : <http://www.w3.org/2001/02pd/rec54#>
|
185
|
-
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
186
|
-
SELECT ?type
|
187
|
-
WHERE {
|
188
|
-
{ <#{@sol.link.to_s.strip}> rdf:type ?type }
|
189
|
-
}
|
190
|
-
))
|
181
|
+
sse = @sol.respond_to?(:link) ? versioned_types_stages : unversioned_types_stages
|
191
182
|
@rdf.query(sse).map { |s| s.type.to_s.split("#").last }
|
192
183
|
end
|
193
184
|
end
|
194
185
|
|
186
|
+
#
|
187
|
+
# Create SPARQL query for versioned types and stages
|
188
|
+
#
|
189
|
+
# @return [SPARQL::Algebra::Operator::Prefix] SPARQL query
|
190
|
+
#
|
191
|
+
def versioned_types_stages
|
192
|
+
SPARQL.parse(%(
|
193
|
+
PREFIX : <http://www.w3.org/2001/02pd/rec54#>
|
194
|
+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
195
|
+
SELECT ?type
|
196
|
+
WHERE {
|
197
|
+
{ <#{@sol.link.to_s.strip}> rdf:type ?type }
|
198
|
+
}
|
199
|
+
))
|
200
|
+
end
|
201
|
+
|
202
|
+
#
|
203
|
+
# Create SPARQL query for unversioned types and stages
|
204
|
+
#
|
205
|
+
# @return [SPARQL::Algebra::Operator::Prefix] SPARQL query
|
206
|
+
#
|
207
|
+
def unversioned_types_stages
|
208
|
+
SPARQL.parse(%(
|
209
|
+
PREFIX : <http://www.w3.org/2001/02pd/rec54#>
|
210
|
+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
211
|
+
PREFIX doc: <http://www.w3.org/2000/10/swap/pim/doc#>
|
212
|
+
SELECT ?type
|
213
|
+
WHERE {
|
214
|
+
?link doc:versionOf <#{@sol.version_of}>; rdf:type ?type .
|
215
|
+
FILTER ( isURI(?link) && STR(?link) != <#{@sol.version_of}> )
|
216
|
+
}
|
217
|
+
))
|
218
|
+
end
|
219
|
+
|
195
220
|
#
|
196
221
|
# Parse doctype
|
197
222
|
#
|
198
|
-
# @return [
|
223
|
+
# @return [String, nil] doctype
|
199
224
|
#
|
200
225
|
def parse_doctype
|
201
|
-
DOCTYPES[type] ||
|
226
|
+
DOCTYPES[type] || DOCTYPES[type_from_link]
|
227
|
+
end
|
228
|
+
|
229
|
+
#
|
230
|
+
# Fetch type from link
|
231
|
+
#
|
232
|
+
# @return [String, nil] type
|
233
|
+
#
|
234
|
+
def type_from_link
|
235
|
+
link = @sol.respond_to?(:link) ? @sol.link : @sol.version_of
|
236
|
+
link.to_s.strip.match(/www\.w3\.org\/(TR)/)&.to_a&.fetch 1
|
202
237
|
end
|
203
238
|
|
204
239
|
#
|
@@ -219,7 +254,7 @@ module RelatonW3c
|
|
219
254
|
#
|
220
255
|
def parse_relation
|
221
256
|
if @sol.respond_to?(:link)
|
222
|
-
relations
|
257
|
+
relations
|
223
258
|
else
|
224
259
|
document_versions.map { |r| create_relation(r.link.to_s.strip, "hasEdition") }
|
225
260
|
end
|
@@ -250,14 +285,16 @@ module RelatonW3c
|
|
250
285
|
# @return [Array<RelatonBib::DocumentRelation>] relation
|
251
286
|
#
|
252
287
|
def editor_drafts # rubocop:disable Metrics/MethodLength
|
288
|
+
return [] unless @sol.respond_to?(:link)
|
289
|
+
|
253
290
|
sse = SPARQL.parse(%(
|
254
291
|
PREFIX : <http://www.w3.org/2001/02pd/rec54#>
|
255
292
|
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
256
|
-
SELECT ?
|
257
|
-
WHERE { <#{@sol.link.to_s.strip}> :ED ?
|
293
|
+
SELECT ?latest
|
294
|
+
WHERE { <#{@sol.link.to_s.strip}> :ED ?latest . }
|
258
295
|
))
|
259
296
|
@rdf.query(sse).map do |s|
|
260
|
-
|
297
|
+
RelatonBib::TypedUri.new(type: "current", content: s.latest.to_s.strip)
|
261
298
|
end
|
262
299
|
end
|
263
300
|
|
data/lib/relaton_w3c/version.rb
CHANGED
@@ -2,7 +2,7 @@ module RelatonW3c
|
|
2
2
|
class W3cBibliographicItem < RelatonBib::BibliographicItem
|
3
3
|
TYPES = %w[
|
4
4
|
candidateRecommendation groupNote proposedEditedRecommendation
|
5
|
-
proposedRecommendation recommendation retired workingDraft
|
5
|
+
proposedRecommendation recommendation retired workingDraft technicalReport
|
6
6
|
].freeze
|
7
7
|
|
8
8
|
# @param doctype [String]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-w3c
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.12.
|
4
|
+
version: 1.12.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: equivalent-xml
|