| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
require 'linkeddata' |
| 8 |
require 'haml' |
| 9 |
require 'active_support' |
| 10 |
|
| 11 |
File.open("vocab.jsonld", "w") do |f| |
| 12 |
r = RDF::Repository.load("vocab.ttl") |
| 13 |
JSON::LD::API.fromRDF(r, useNativeTypes: true) do |expanded| |
| 14 |
|
| 15 |
expanded.each do |o| |
| 16 |
c = o[RDF::RDFS.comment.to_s].first['@value'] |
| 17 |
o[RDF::RDFS.comment.to_s].first['@value'] = c.strip.gsub(/\s+/m, ' ') |
| 18 |
end |
| 19 |
JSON::LD::API.compact(expanded, File.open("vocab_context.jsonld")) do |compacted| |
| 20 |
|
| 21 |
f.write(compacted.to_json(JSON::LD::JSON_STATE)) |
| 22 |
|
| 23 |
|
| 24 |
template = File.read("vocab_template.haml") |
| 25 |
|
| 26 |
html = Haml::Engine.new(template, :format => :html5).render(self, |
| 27 |
ontology: compacted['@graph'].detect {|o| o['@id'] == "http://json-ld.github.io/normalization/tests/vocab#"}, |
| 28 |
classes: compacted['@graph'].select {|o| o['@type'] == "rdfs:Class"}.sort_by {|o| o['rdfs:label']}, |
| 29 |
properties: compacted['@graph'].select {|o| o['@type'] == "rdf:Property"}.sort_by {|o| o['rdfs:label']} |
| 30 |
) |
| 31 |
File.open("vocab.html", "w") {|fh| fh.write html} |
| 32 |
end |
| 33 |
end |
| 34 |
end |