skos2html 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/skos2html.rb +58 -10
  2. metadata +1 -1
data/lib/skos2html.rb CHANGED
@@ -86,6 +86,7 @@ class Skos2Html
86
86
  head.meta(:charset => "UTF-8")
87
87
  head.title(title)
88
88
  head.meta(:name => "generator", :content => "skos2html")
89
+ head.comment! "Edit styles and other html in this file as you like but do not change text or id-attributes."
89
90
  head.style("""
90
91
  html {
91
92
  margin: auto;
@@ -209,30 +210,22 @@ div.concept {
209
210
  if conceptschemes.size == 1
210
211
 
211
212
  scheme = conceptschemes[0]
212
- @log.info("Looping concept scheme " + scheme.scheme)
213
+ @log.info("Concept scheme " + scheme.scheme)
213
214
 
214
215
  scheme_info = RDF::Query.execute(@graph) do
215
216
  pattern [scheme.scheme, :predicate, :object]
216
217
  end
217
218
 
218
- # Title
219
219
  title = ""
220
-
221
- # Description
222
220
  description = ""
223
-
224
- # Creators
225
221
  creators = []
226
-
227
- # Contributors
228
222
  contributors = []
229
223
 
230
224
  # get values
231
225
  scheme_info.each do |solution|
232
226
 
233
227
  case solution.predicate
234
- when "http://purl.org/dc/terms/title"
235
- when "http://www.w3.org/2000/01/rdf-schema#label"
228
+ when "http://purl.org/dc/terms/title", "http://www.w3.org/2000/01/rdf-schema#label"
236
229
  title = string_for(solution.object, @default_lang)
237
230
  when "http://purl.org/dc/terms/description"
238
231
  description = string_for(solution.object, @default_lang)
@@ -300,6 +293,7 @@ div.concept {
300
293
  # title element
301
294
  def concept_scheme_title
302
295
 
296
+ # Possible properties
303
297
  title_properties = ["http://purl.org/dc/terms/title",
304
298
  "http://www.w3.org/2000/01/rdf-schema#label",
305
299
  "http://www.w3.org/2004/02/skos/core#prefLabel"]
@@ -335,9 +329,31 @@ div.concept {
335
329
 
336
330
 
337
331
 
332
+ def concept_preflabel(concept_uri)
333
+
334
+ uri = RDF::URI.new(concept_uri)
335
+
336
+ labels = RDF::Query.execute(@graph) do
337
+ pattern [uri, RDF::SKOS.prefLabel, :object]
338
+ end
339
+
340
+ labels.filter { |label| label.object.language == @default_lang }
341
+
342
+ if labels.size > 0
343
+ return labels[0].object.value
344
+ else
345
+ @log.error("Preflabel missing for #{concept_uri}")
346
+ return ""
347
+ end
348
+ end
349
+
350
+
351
+
338
352
  # Generate the HTML for an individual concept.
339
353
  def generate_concept(concept_uri)
340
354
 
355
+ @log.info("Generate concept #{concept_uri}")
356
+
341
357
  concept_info = RDF::Query.execute(@graph) do
342
358
  pattern [concept_uri, :predicate, :object]
343
359
  end
@@ -345,6 +361,8 @@ div.concept {
345
361
  preflabels = []
346
362
  altlabels = []
347
363
  definition = ""
364
+ has_broader = nil
365
+ has_narrower = nil
348
366
 
349
367
  concept_info.each do |solution|
350
368
 
@@ -363,6 +381,10 @@ div.concept {
363
381
  end
364
382
  when "http://www.w3.org/2004/02/skos/core#definition"
365
383
  definition = string_for(solution.object, @default_lang)
384
+ when "http://www.w3.org/2004/02/skos/core#broader"
385
+ has_broader = solution.object.value
386
+ when "http://www.w3.org/2004/02/skos/core#narrower"
387
+ has_narrower = solution.object.value
366
388
  end
367
389
 
368
390
  end
@@ -394,6 +416,32 @@ div.concept {
394
416
  end
395
417
  end
396
418
 
419
+
420
+ if has_broader
421
+
422
+ has_broader_uri = has_broader
423
+
424
+ unless has_broader.start_with?("http://")
425
+ r = RDF::URI.new(concept_uri)
426
+ r.fragment = has_broader[1..-1]
427
+ has_broader_uri = r.to_s
428
+ end
429
+
430
+ html.dt("Has broader", :class => "broader")
431
+ html.dd(:class => "broader") {
432
+ html.a(concept_preflabel(has_broader_uri), :href => has_broader)
433
+ }
434
+ end
435
+
436
+
437
+ if has_narrower
438
+ html.dt("Has narrower", :class => "narrower")
439
+ html.dd(:class => "narrower") {
440
+ html.a(has_narrower, :href => has_narrower)
441
+ }
442
+ end
443
+
444
+
397
445
  html.dt("Identifier", :class => "identifier")
398
446
  html.dd(concept_uri, :class => "identifier")
399
447
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skos2html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: