relaton-w3c 1.20.0 → 1.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9c777f3bbcbff5de8311b7103f7f64dee70971f5745be10f0415200ec8a3fe9
4
- data.tar.gz: c13ba956f36f1d4e18a846aeb5d550aad5dbd0128a63457418032958d9d503ff
3
+ metadata.gz: beb3bb1a8550059e754f001412336b78ab55771f25ebf33534dd92f59a724b9d
4
+ data.tar.gz: d32d55f604c16613c04d5d2ad5554e7c7ed8c6151ad0218411c47d58099b5a63
5
5
  SHA512:
6
- metadata.gz: efbc142c4590df61f6b625bc1e00a29e95edad3ca97d940ea05f57caec3cf8db9fc5ed2a64ec6d5a4079ef3228fd682bae801b6c659a5afb83279d49c4d0b2e8
7
- data.tar.gz: ef68de56840568a3e7d063a5c72876d23ae8d7f02d8cd35169e5a5b619c240edad1622738d38cd5d80642301f892e17a6f40d9fe17e33520bd523440064c9dc0
6
+ metadata.gz: b2927bebbb35dde93cb2659b44e0ef47608ffa164ae33d138041a46139ca17b1a62061eb1055959fe91771bf397bf5ecb11f9ff2ca19055d7d804a65962a8974
7
+ data.tar.gz: 240f1c9f84770eb129a372a015b582c7f3ff6870eaf83e2dd723ff9538bbc19da34d58190234441b3c6b9dde224810e09c5e287473afa1183f23c53deabcc849
data/README.adoc CHANGED
@@ -108,16 +108,13 @@ RelatonW3c::W3cBibliographicItem.new **bib_hash
108
108
 
109
109
  === Fetch data
110
110
 
111
- The method `RelatonW3c::DataFetcher.fetch(source, output: "data", format: "yaml")` converts all the documents from the dataset and saves them to the `./data` folder in YAML format.
111
+ The method `RelatonW3c::DataFetcher.fetch(output: "data", format: "yaml")` converts all the documents from the dataset and saves them to the `./data` folder in YAML format.
112
112
  Arguments:
113
113
 
114
- - `source` - the name of the dataset (`w3c-rdf` or `w3c-tr-archive`)
115
114
  - `output` - folder to save documents (default './data').
116
115
  - `format` - the format in which the documents are saved. Possible formats are: `yaml`, `xml`, `bibxml` (default `yaml`).
117
116
 
118
- The available datasets are:
119
- - `w3c-rdf` - The dataset is fetched from http://www.w3.org/2002/01/tr-automation/tr.rdf.
120
- - `w3c-tr-archive` - The archive dataset files should be downloaded from https://github.com/relaton/w3c-tr-archive repository and placed into `w3c-tr-archive` folder.
117
+ The method uses https://api.w3.org/doc API to fetch all the W3C documents.
121
118
 
122
119
  [source,ruby]
123
120
  ----
@@ -1,13 +1,10 @@
1
- require "rdf"
2
- require "linkeddata"
3
- require "sparql"
4
- require "mechanize"
5
- require_relative "rdf_archive"
1
+ require "w3c_api"
2
+ require_relative "rate_limit_handler"
6
3
  require_relative "data_parser"
7
4
 
8
5
  module RelatonW3c
9
6
  class DataFetcher
10
- attr_reader :data, :group_names, :rdf_archive
7
+ include RelatonW3c::RateLimitHandler
11
8
 
12
9
  #
13
10
  # Data fetcher initializer
@@ -19,9 +16,8 @@ module RelatonW3c
19
16
  @output = output
20
17
  @format = format
21
18
  @ext = format.sub(/^bib/, "")
22
- dir = File.dirname(File.expand_path(__FILE__))
23
- @group_names = YAML.load_file(File.join(dir, "workgroups.yaml"))
24
19
  @files = Set.new
20
+ @fetched_urls = {}
25
21
  @index = DataIndex.create_from_file
26
22
  @index1 = Relaton::Index.find_or_create :W3C, file: "index1.yaml"
27
23
  end
@@ -29,7 +25,6 @@ module RelatonW3c
29
25
  #
30
26
  # Initialize fetcher and run fetch
31
27
  #
32
- # @param [String] source source name "w3c-tr-archive" or "w3c-rdf"
33
28
  # @param [Strin] output directory to save files, default: "data"
34
29
  # @param [Strin] format format of output files (xml, yaml, bibxml), default: yaml
35
30
  #
@@ -43,132 +38,46 @@ module RelatonW3c
43
38
  puts "Done in: #{(t2 - t1).round} sec."
44
39
  end
45
40
 
46
- def rdf_archive
47
- @rdf_archive ||= RDFArchive.new
41
+ def client
42
+ @client ||= W3cApi::Client.new
48
43
  end
49
44
 
50
45
  #
51
46
  # Parse documents
52
47
  #
53
- # @param [String] source source name "w3c-tr-archive" or "w3c-rdf"
54
- #
55
- def fetch # (source) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
56
- rdf = rdf_archive.get_data
57
- %i[versioned unversioned].each do |type|
58
- send("query_#{type}_docs", rdf).each do |sl|
59
- bib = DataParser.parse(rdf, sl, self)
60
- add_has_edition_relation(bib) if type == :unversioned
61
- save_doc bib
62
- rescue StandardError => e
63
- link = sl.respond_to?(:link) ? sl.link : sl.version_of
64
- Util.error "Error: document #{link} #{e.message}\n#{e.backtrace.join("\n")}"
48
+ def fetch
49
+ specs = client.specifications
50
+ loop do
51
+ specs.links.specifications.each do |spec|
52
+ fetch_spec spec
65
53
  end
54
+
55
+ break unless specs.next?
56
+
57
+ specs = specs.next
66
58
  end
67
59
  @index.sort!.save
68
60
  @index1.save
69
61
  end
70
62
 
71
- #
72
- # Add hasEdition relations form previous parsed document
73
- #
74
- # @param [RelatonW3c::W3cBibliographicItem] bib bibligraphic item
75
- #
76
- def add_has_edition_relation(bib) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
77
- file = file_name bib.docnumber
78
- if File.exist? file
79
- item = send "read_#{@format}", file
80
- item.relation.each do |r1|
81
- r1.type = "hasEdition" if r1.type == "instanceOf"
82
- same_edition = bib.relation.detect { |r2| same_edition?(r1, r2) }
83
- bib.relation << r1 unless same_edition
84
- end
85
- end
86
- bib.relation.select { |r| r.type == "hasEdition" }
87
- .max_by { |r| r.bibitem.id.match(/(?<=-)\d{8}$/).to_s }&.type = "instanceOf"
88
- end
89
-
90
- #
91
- # Read XML file
92
- #
93
- # @param [String] file file name
94
- #
95
- # @return [RelatonW3c::W3cBibliographicItem] bibliographic item
96
- #
97
- def read_xml(file)
98
- XMLParser.from_xml(File.read(file, encoding: "UTF-8"))
99
- end
100
-
101
- #
102
- # Read YAML file
103
- #
104
- # @param [String] file file name
105
- #
106
- # @return [RelatonW3c::W3cBibliographicItem] bibliographic item
107
- #
108
- def read_yaml(file)
109
- hash = YAML.load_file(file)
110
- W3cBibliographicItem.from_hash(hash)
111
- end
63
+ def fetch_spec(unrealized_spec)
64
+ spec = realize unrealized_spec
65
+ save_doc DataParser.parse(spec)
112
66
 
113
- #
114
- # Read BibXML file
115
- #
116
- # @param [String] file file name
117
- #
118
- # @return [RelatonW3c::W3cBibliographicItem] bibliographic item
119
- #
120
- def read_bibxml(file)
121
- BibXMLParser.parse File.read(file, encoding: "UTF-8")
122
- end
123
-
124
- #
125
- # Compare two relations
126
- #
127
- # @param [RelatonW3c::W3cBibliographicItem] rel1 relation 1
128
- # @param [RelatonW3c::W3cBibliographicItem] rel2 relation 2
129
- #
130
- # @return [Boolean] true if relations are same
131
- #
132
- def same_edition?(rel1, rel2)
133
- return false unless rel1.type == "hasEdition" && rel1.type == rel2.type
134
-
135
- ids1 = rel1.bibitem.docidentifier.map(&:id)
136
- ids2 = rel2.bibitem.docidentifier.map(&:id)
137
- (ids1 & ids2).any?
138
- end
67
+ if spec.links.respond_to?(:version_history) && spec.links.version_history
68
+ version_history = realize spec.links.version_history
69
+ version_history.links.spec_versions.each { |version| save_doc DataParser.parse(realize version) }
70
+ end
139
71
 
140
- #
141
- # Query RDF source for versioned documents
142
- #
143
- # @return [RDF::Query::Solutions] query results
144
- #
145
- def query_versioned_docs(rdf)
146
- sse = SPARQL.parse(%(
147
- PREFIX : <http://www.w3.org/2001/02pd/rec54#>
148
- PREFIX dc: <http://purl.org/dc/elements/1.1/>
149
- PREFIX doc: <http://www.w3.org/2000/10/swap/pim/doc#>
150
- PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
151
- SELECT ?link ?title ?date
152
- WHERE { ?link dc:title ?title ; dc:date ?date . }
153
- ))
154
- rdf.query sse
155
- end
72
+ if spec.links.respond_to?(:predecessor_versions) && spec.links.predecessor_versions
73
+ predecessor_versions = realize spec.links.predecessor_versions
74
+ predecessor_versions.links.predecessor_versions.each { |version| save_doc DataParser.parse(realize version) }
75
+ end
156
76
 
157
- #
158
- # Query RDF source for unversioned documents
159
- #
160
- # @return [Array<RDF::Query::Solution>] query results
161
- #
162
- def query_unversioned_docs(rdf)
163
- sse = SPARQL.parse(%(
164
- PREFIX doc: <http://www.w3.org/2000/10/swap/pim/doc#>
165
- SELECT ?version_of
166
- WHERE {
167
- ?link doc:versionOf ?version_of .
168
- FILTER ( isURI(?link) && isURI(?version_of) && ?link != ?version_of )
169
- }
170
- ))
171
- rdf.query(sse).uniq { |s| s.version_of.to_s.sub(/^https?:\/\//, "").sub(/\/$/, "") }
77
+ if spec.links.respond_to?(:successor_versions) && spec.links.successor_versions
78
+ successor_versions = realize spec.links.successor_versions
79
+ successor_versions.links.successor_versions.each { |version| save_doc DataParser.parse(realize version) }
80
+ end
172
81
  end
173
82
 
174
83
  #
@@ -1,5 +1,7 @@
1
1
  module RelatonW3c
2
2
  class DataParser
3
+ include RelatonW3c::RateLimitHandler
4
+
3
5
  USED_TYPES = %w[WD NOTE PER PR REC CR].freeze
4
6
 
5
7
  DOCTYPES = {
@@ -22,25 +24,22 @@ module RelatonW3c
22
24
  #
23
25
  # Document parser initalization
24
26
  #
25
- # @param [RDF::Query::Solution] sol entry from the SPARQL query
27
+ # @param [W3cApi::Models::SpecVersion] sol entry from the SPARQL query
26
28
  # @param [RelatonW3c::DataFetcher] fetcher data fetcher
27
29
  #
28
- def initialize(rdf, sol, fetcher)
29
- @rdf = rdf
30
- @sol = sol
31
- @fetcher = fetcher
30
+ def initialize(spec)
31
+ @spec = spec
32
32
  end
33
33
 
34
34
  #
35
35
  # Initialize document parser and run it
36
36
  #
37
- # @param [RDF::Query::Solution] sol entry from the SPARQL query
38
- # @param [RelatonW3c::DataFetcher] fetcher data fetcher
37
+ # @param [W3cApi::Models::SpecVersion] sol entry from the SPARQL query
39
38
  #
40
39
  # @return [RelatonW3c:W3cBibliographicItem, nil] bibliographic item
41
40
  #
42
- def self.parse(rdf, sol, fetcher)
43
- new(rdf, sol, fetcher).parse
41
+ def self.parse(spec)
42
+ new(spec).parse
44
43
  end
45
44
 
46
45
  #
@@ -49,7 +48,7 @@ module RelatonW3c
49
48
  # @return [RelatonW3c:W3cBibliographicItem, nil] bibliographic item
50
49
  #
51
50
  def parse # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
52
- return if @sol.respond_to?(:link) && !types_stages.detect { |ts| USED_TYPES.include?(ts) }
51
+ # return if @sol.respond_to?(:link) && !types_stages.detect { |ts| USED_TYPES.include?(ts) }
53
52
 
54
53
  RelatonW3c::W3cBibliographicItem.new(
55
54
  type: "standard",
@@ -76,8 +75,10 @@ module RelatonW3c
76
75
  # @return [RelatonBib::DocumentStatus, nil] dcoument status
77
76
  #
78
77
  def parse_docstatus
79
- stage = types_stages&.detect { |st| STAGES.include?(st) }
80
- RelatonBib::DocumentStatus.new stage: STAGES[stage] if stage
78
+ # stage = types_stages&.detect { |st| STAGES.include?(st) }
79
+ return unless @spec.respond_to?(:status) && @spec.status
80
+
81
+ RelatonBib::DocumentStatus.new stage: @spec.status
81
82
  end
82
83
 
83
84
  #
@@ -85,22 +86,22 @@ module RelatonW3c
85
86
  #
86
87
  # @return [RelatonBib::TypedTitleStringCollection] title
87
88
  #
88
- def parse_title
89
- content = if @sol.respond_to?(:title) then @sol.title.to_s
90
- else document_versions.max_by { |dv| dv.date.to_s }.title.to_s
91
- end
92
- t = RelatonBib::TypedTitleString.new content: content
89
+ def parse_title(spec = @spec)
90
+ t = RelatonBib::TypedTitleString.new content: spec.title
93
91
  RelatonBib::TypedTitleStringCollection.new [t]
94
92
  end
95
93
 
94
+ def doc_uri(spec = @spec)
95
+ spec.respond_to?(:uri) ? spec.uri : spec.shortlink
96
+ end
97
+
96
98
  #
97
99
  # Parse link
98
100
  #
99
101
  # @return [Array<RelatonBib::TypedUri>] link
100
102
  #
101
103
  def parse_link
102
- link = @sol.respond_to?(:link) ? @sol.link : @sol.version_of
103
- [RelatonBib::TypedUri.new(type: "src", content: link.to_s.strip)] + editor_drafts
104
+ [RelatonBib::TypedUri.new(type: "src", content: doc_uri)] # + editor_drafts
104
105
  end
105
106
 
106
107
  #
@@ -109,14 +110,14 @@ module RelatonW3c
109
110
  # @return [Arra<RelatonBib::DocumentIdentifier>] docidentifier
110
111
  #
111
112
  def parse_docid
112
- id = @sol.respond_to?(:link) ? pub_id(@sol.link) : pub_id(@sol.version_of)
113
+ id = pub_id(doc_uri)
113
114
  [RelatonBib::DocumentIdentifier.new(type: "W3C", id: id, primary: true)]
114
115
  end
115
116
 
116
117
  #
117
118
  # Generate PubID
118
119
  #
119
- # @return [RDF::URI] PubID
120
+ # @return [String] PubID
120
121
  #
121
122
  def pub_id(url)
122
123
  "W3C #{identifier(url)}"
@@ -125,13 +126,12 @@ module RelatonW3c
125
126
  #
126
127
  # Generate identifier from URL
127
128
  #
128
- # @param [RDF::URI, nil] link
129
+ # @param [String] link
129
130
  #
130
131
  # @return [String] identifier
131
132
  #
132
- def identifier(link = nil)
133
- url = link || (@sol.respond_to?(:link) ? @sol.link : @sol.version_of)
134
- self.class.parse_identifier(url.to_s.strip)
133
+ def identifier(link = doc_uri)
134
+ self.class.parse_identifier(link)
135
135
  end
136
136
 
137
137
  #
@@ -166,54 +166,9 @@ module RelatonW3c
166
166
  # @return [String] type
167
167
  #
168
168
  def type
169
- # thre are many types, we need to find the right one
170
- @type ||= types_stages&.detect { |t| USED_TYPES.include?(t) } || "technicalReport"
171
- end
172
-
173
- #
174
- # Fetches types and stages
175
- #
176
- # @return [Array<String>] types and stages
177
- #
178
- def types_stages
179
- @types_stages ||= begin
180
- sse = @sol.respond_to?(:link) ? versioned_types_stages : unversioned_types_stages
181
- @rdf.query(sse).map { |s| s.type.to_s.split("#").last }
182
- end
183
- end
184
-
185
- #
186
- # Create SPARQL query for versioned types and stages
187
- #
188
- # @return [SPARQL::Algebra::Operator::Prefix] SPARQL query
189
- #
190
- def versioned_types_stages
191
- SPARQL.parse(%(
192
- PREFIX : <http://www.w3.org/2001/02pd/rec54#>
193
- PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
194
- SELECT ?type
195
- WHERE {
196
- { <#{@sol.link.to_s.strip}> rdf:type ?type }
197
- }
198
- ))
199
- end
200
-
201
- #
202
- # Create SPARQL query for unversioned types and stages
203
- #
204
- # @return [SPARQL::Algebra::Operator::Prefix] SPARQL query
205
- #
206
- def unversioned_types_stages
207
- SPARQL.parse(%(
208
- PREFIX : <http://www.w3.org/2001/02pd/rec54#>
209
- PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
210
- PREFIX doc: <http://www.w3.org/2000/10/swap/pim/doc#>
211
- SELECT ?type
212
- WHERE {
213
- ?link doc:versionOf <#{@sol.version_of}>; rdf:type ?type .
214
- FILTER ( isURI(?link) && STR(?link) != <#{@sol.version_of}> )
215
- }
216
- ))
169
+ # there are many types, we need to find the right one
170
+ # @type ||= types_stages&.detect { |t| USED_TYPES.include?(t) } || "technicalReport"
171
+ @type ||= @spec.respond_to?(:status) ? @spec.status : "technicalReport"
217
172
  end
218
173
 
219
174
  #
@@ -222,8 +177,8 @@ module RelatonW3c
222
177
  # @return [String, nil] doctype
223
178
  #
224
179
  def parse_doctype
225
- type = DOCTYPES[type] || DOCTYPES[type_from_link]
226
- DocumentType.new(type: type) if type
180
+ t = DOCTYPES[type] || DOCTYPES[type_from_link]
181
+ DocumentType.new(type: t) if t
227
182
  end
228
183
 
229
184
  #
@@ -232,8 +187,8 @@ module RelatonW3c
232
187
  # @return [String, nil] type
233
188
  #
234
189
  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
190
+ # link = @sol.respond_to?(:link) ? @sol.link : @sol.version_of
191
+ @spec.shortlink.strip.match(/www\.w3\.org\/(TR)/)&.to_a&.fetch 1
237
192
  end
238
193
 
239
194
  #
@@ -242,9 +197,9 @@ module RelatonW3c
242
197
  # @return [Array<RelatonBib::BibliographicDate>] date
243
198
  #
244
199
  def parse_date
245
- return [] unless @sol.respond_to?(:date)
200
+ return [] unless @spec.respond_to?(:date)
246
201
 
247
- [RelatonBib::BibliographicDate.new(type: "published", on: @sol.date.to_s)]
202
+ [RelatonBib::BibliographicDate.new(type: "published", on: @spec.date.to_date.to_s)]
248
203
  end
249
204
 
250
205
  #
@@ -253,10 +208,11 @@ module RelatonW3c
253
208
  # @return [Array<RelatonBib::DocumentRelation>] relation
254
209
  #
255
210
  def parse_relation
256
- if @sol.respond_to?(:link)
257
- relations
211
+ if @spec.links.respond_to?(:version_history)
212
+ version_history = realize @spec.links.version_history
213
+ version_history.links.spec_versions.map { |version| create_relation(version, "hasEdition") }
258
214
  else
259
- document_versions.map { |r| create_relation(r.link.to_s.strip, "hasEdition") }
215
+ relations
260
216
  end
261
217
  end
262
218
 
@@ -266,99 +222,21 @@ module RelatonW3c
266
222
  # @return [Array<RelatonBib::DocumentRelation>] relations
267
223
  #
268
224
  def relations # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
269
- {
270
- "doc:obsoletes" => { type: "obsoletes" },
271
- "mat:hasErrata" => { type: "updatedBy", description: "errata" },
272
- # "mat:hasTranslations" => "hasTranslation",
273
- # "mat:hasImplReport" => "hasImpReport",
274
- ":previousEdition" => { type: "editionOf" },
275
- }.reduce([]) do |acc, (predicate, tp)|
276
- acc + relation_query(predicate).map do |r|
277
- create_relation(r.rel.to_s, tp[:type], tp[:description])
225
+ rels = []
226
+ rels << create_relation(@spec.links.specification, "editionOf") if @spec.links.respond_to?(:specification)
227
+ if @spec.links.respond_to?(:predecessor_versions) && @spec.links.predecessor_versions
228
+ predecessor_versions = realize @spec.links.predecessor_versions
229
+ predecessor_versions.links.predecessor_versions.each do |version|
230
+ rels << create_relation(version, "obsoletes")
278
231
  end
279
232
  end
280
- end
281
-
282
- #
283
- # Parse editor drafts links
284
- #
285
- # @return [Array<RelatonBib::TypedUri>] links
286
- #
287
- def editor_drafts # rubocop:disable Metrics/MethodLength
288
- return [] unless @sol.respond_to?(:link)
289
-
290
- sse = SPARQL.parse(%(
291
- PREFIX : <http://www.w3.org/2001/02pd/rec54#>
292
- PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
293
- SELECT ?latest
294
- WHERE { <#{@sol.link.to_s.strip}> :ED ?latest . }
295
- ))
296
- @rdf.query(sse).map do |s|
297
- RelatonBib::TypedUri.new(type: "current", content: s.latest.to_s.strip)
298
- end
299
- end
300
-
301
- #
302
- # Query for relations
303
- #
304
- # @param [String] predicate relation type
305
- #
306
- # @return [RDF::Query::Solutions] query result
307
- #
308
- def relation_query(predicate)
309
- sse = SPARQL.parse(%(
310
- PREFIX : <http://www.w3.org/2001/02pd/rec54#>
311
- PREFIX doc: <http://www.w3.org/2000/10/swap/pim/doc#>
312
- PREFIX mat: <http://www.w3.org/2002/05/matrix/vocab#>
313
- SELECT ?rel
314
- WHERE {
315
- <#{@sol.link.to_s.strip}> #{predicate} ?rel .
316
- FILTER ( isURI(?rel) )
317
- }
318
- ))
319
- @rdf.query(sse).order_by(:rel)
320
- end
321
-
322
- #
323
- # Query document versions relations
324
- #
325
- # @return [Array<RDF::Query::Solution>] query results
326
- #
327
- def document_versions # rubocop:disable Metrics/MethodLength
328
- @document_versions ||= version_of.each_with_object([]) do |s, acc|
329
- sse = SPARQL.parse(%(
330
- PREFIX : <http://www.w3.org/2001/02pd/rec54#>
331
- PREFIX dc: <http://purl.org/dc/elements/1.1/>
332
- PREFIX doc: <http://www.w3.org/2000/10/swap/pim/doc#>
333
- PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
334
- SELECT ?link ?title ?date
335
- WHERE {
336
- ?link doc:versionOf <#{s.version_of}> ;
337
- dc:title ?title ;
338
- dc:date ?date .
339
- }
340
- ))
341
- @rdf.query(sse).each { |r| acc << r }
233
+ if @spec.links.respond_to?(:successor_versions) && @spec.links.successor_versions
234
+ successor_versions = realize @spec.links.successor_versions
235
+ successor_versions.links.successor_versions.each do |version|
236
+ rels << create_relation(version, "updatedBy", "errata")
237
+ end
342
238
  end
343
- end
344
-
345
- #
346
- # Query for document versions
347
- #
348
- # @return [RDF::Query::Solutions] query results
349
- #
350
- def version_of
351
- return [@sol] unless @sol.respond_to?(:link)
352
-
353
- sse = SPARQL.parse(%(
354
- PREFIX doc: <http://www.w3.org/2000/10/swap/pim/doc#>
355
- SELECT ?version_of
356
- WHERE {
357
- <#{@sol.link.to_s.strip}> doc:versionOf ?version_of .
358
- FILTER ( isURI(?version_of) && <#{@sol.link.to_s.strip}> != str(?version_of) )
359
- }
360
- ))
361
- @rdf.query(sse)
239
+ rels
362
240
  end
363
241
 
364
242
  #
@@ -370,12 +248,15 @@ module RelatonW3c
370
248
  #
371
249
  # @return [RelatonBib::DocumentRelation] <description>
372
250
  #
373
- def create_relation(url, type, desc = nil)
251
+ def create_relation(version, type, desc = nil)
252
+ version_spec = realize version
253
+ url = doc_uri(version_spec)
374
254
  id = pub_id(url)
375
- fref = RelatonBib::FormattedRef.new content: id
255
+ # fref = RelatonBib::FormattedRef.new content: id
256
+ title = parse_title(version_spec)
376
257
  docid = RelatonBib::DocumentIdentifier.new(type: "W3C", id: id, primary: true)
377
258
  link = [RelatonBib::TypedUri.new(type: "src", content: url)]
378
- bib = W3cBibliographicItem.new formattedref: fref, docid: [docid], link: link
259
+ bib = W3cBibliographicItem.new title: title, docid: [docid], link: link
379
260
  dsc = RelatonBib::FormattedString.new content: desc if desc
380
261
  RelatonBib::DocumentRelation.new(type: type, bibitem: bib, description: dsc)
381
262
  end
@@ -386,9 +267,9 @@ module RelatonW3c
386
267
  # @return [RelatonBib::FormattedRef] formattedref
387
268
  #
388
269
  def parse_formattedref
389
- return if @sol.respond_to?(:link)
270
+ return unless @spec.respond_to?(:uri)
390
271
 
391
- RelatonBib::FormattedRef.new(content: pub_id(@sol.version_of))
272
+ RelatonBib::FormattedRef.new(content: pub_id(@spec.uri))
392
273
  end
393
274
 
394
275
  #
@@ -401,26 +282,27 @@ module RelatonW3c
401
282
  name: "World Wide Web Consortium", abbreviation: "W3C", url: "https://www.w3.org/"
402
283
  )
403
284
  contribs = [RelatonBib::ContributionInfo.new(entity: publisher, role: [type: "publisher"])]
404
- return contribs unless @sol.respond_to?(:link)
405
-
406
- sse = SPARQL.parse(%(
407
- PREFIX : <http://www.w3.org/2001/02pd/rec54#>
408
- PREFIX contact: <http://www.w3.org/2000/10/swap/pim/contact#>
409
- SELECT ?full_name
410
- WHERE {
411
- <#{@sol.link.to_s.strip}> :editor/contact:fullName ?full_name
412
- }
413
- ))
414
- @rdf.query(sse).order_by(:full_name).each_with_object(contribs) do |ed, obj|
415
- obj << create_editor(ed.full_name.to_s)
285
+
286
+ if @spec.links.respond_to?(:editors)
287
+ editors = realize @spec.links.editors
288
+ editors.links.editors&.each do |ed|
289
+ editor = create_editor(ed)
290
+ contribs << editor if editor
291
+ end
416
292
  end
293
+
294
+ contribs
417
295
  end
418
296
 
419
- def create_editor(name)
420
- cn = RelatonBib::LocalizedString.new(name, "en", "Latn")
421
- n = RelatonBib::FullName.new completename: cn
422
- p = RelatonBib::Person.new name: n
423
- RelatonBib::ContributionInfo.new(entity: p, role: [type: "editor"])
297
+ def create_editor(unrealized_editor)
298
+ editor = realize unrealized_editor
299
+ return unless editor
300
+
301
+ surname = RelatonBib::LocalizedString.new(editor.family, "en", "Latn")
302
+ forename = RelatonBib::Forename.new(content: editor.given, language: "en", script: "Latn")
303
+ name = RelatonBib::FullName.new surname: surname, forename: [forename]
304
+ person = RelatonBib::Person.new name: name
305
+ RelatonBib::ContributionInfo.new(entity: person, role: [type: "editor"])
424
306
  end
425
307
 
426
308
  #
@@ -429,27 +311,16 @@ module RelatonW3c
429
311
  # @return [RelatonBib::EditorialGroup] editorialgroup
430
312
  #
431
313
  def parse_editorialgroup # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
432
- return unless @sol.respond_to?(:link)
433
-
434
- sse = SPARQL.parse(%(
435
- PREFIX org: <http://www.w3.org/2001/04/roadmap/org#>
436
- PREFIX contact: <http://www.w3.org/2000/10/swap/pim/contact#>
437
- SELECT ?home_page
438
- WHERE {
439
- <#{@sol.link.to_s.strip}> org:deliveredBy/contact:homePage ?home_page
440
- }
441
- ))
442
- res = @rdf.query(sse).order_by(:home_page)
443
- tc = res.each_with_object([]) do |edg, obj|
444
- group_path = edg.home_page.to_s.sub(/^https?:\/\//, "").sub(/\/$/, "")
445
- wg = @fetcher.group_names[group_path]
446
- if wg
447
- rwg = RelatonBib::WorkGroup.new name: wg["name"]
448
- obj << RelatonBib::TechnicalCommittee.new(rwg)
449
- else
450
- Util.warn "Working group name not found for: `#{edg.home_page}`"
451
- end
314
+ return unless @spec.links.respond_to?(:deliverers)
315
+
316
+ deliverers = realize @spec.links.deliverers
317
+ return unless deliverers.links.deliverers
318
+
319
+ tc = deliverers.links.deliverers.map do |edg|
320
+ wg = RelatonBib::WorkGroup.new(name: edg.title)
321
+ RelatonBib::TechnicalCommittee.new(wg)
452
322
  end
323
+
453
324
  RelatonBib::EditorialGroup.new tc
454
325
  end
455
326
  end