Skip to content

Commit

Permalink
Create vocab_gen.rb to build vocab.jsonld and vocab.html from vocab.ttl.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Aug 24, 2013
1 parent 08f5240 commit 73f2c63
Show file tree
Hide file tree
Showing 8 changed files with 903 additions and 344 deletions.
6 changes: 5 additions & 1 deletion test-suite/README → test-suite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ comprehensive JSON-LD testing solution for developers creating JSON-LD Processor
Design
------

Tests are defined into _compact_, _expand_, _frame_, _normalize_, and _rdf_ sections:
Tests are defined into _compact_, _expand_, _flatten_, _frame_, _normalize_, and _rdf_ sections:
* _compact_ tests have _input_, _expected_ and _context_ documents. The _expected_ results
can be compared using JSON object comparison with the processor output.
* _expand_ tests have _input_ and _expected_ documents. The _expected_ results
Expand Down Expand Up @@ -60,3 +60,7 @@ and add tests as they see fit. This may mean that the test suite may become
unstable from time to time, but this approach has been taken so that the
long-term goal of having a comprehensive test suite for JSON-LD can be achieved
by the JSON-LD community.

Building Files
==============
The vocab.html and vocab.jsonld files are created from vocab.ttl using with `vocab_gen.rb`.
9 changes: 7 additions & 2 deletions test-suite/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,18 @@ <h1>JSON-LD Test Suite</h1>

<div id="container">
<div class="row">
<h2 id="design" class="span12" style="text-align: center;">Design</h2>
<h2 id="design" class="span12" style="text-align: center;">Running the test suite</h2>
</div>
<div class="row">
<section class="offset2 span8">
<p>Tests are defined into <em>compact</em>, <em>expand</em>, <em>frame</em>, <em>normalize</em>, and <em>rdf</em> sections:</p>
<p>Tests are defined into <em>compact</em>, <em>expand</em>, <em>flatten</em>, <em>frame</em>, <em>normalize</em>, and <em>rdf</em> sections:</p>
<ul>
<li><em>compact</em> tests have <em>input</em>, <em>expected</em> and <em>context</em> documents. The <em>expected</em> results
can be compared using JSON object comparison with the processor output.</li>
<li><em>expand</em> tests have <em>input</em> and <em>expected</em> documents. The <em>expected</em> results
can be compared using JSON object comparison with the processor output.</li>
<li><em>flatten</em> tests have <em>input</em> and <em>expected</em> documents. The <em>expected</em> results
can be compared using JSON object comparison with the processor output.</li>
<li><em>frame</em> tests have <em>input</em>, <em>frame</em> and <em>expected</em> documents. The <em>expected</em> results
can be compared using JSON object comparison with the processor output.</li>
<li><em>normalize</em> tests have <em>input</em> and <em>expected</em> documents. The <em>expected</em> results
Expand All @@ -128,6 +130,9 @@ <h2 id="design" class="span12" style="text-align: center;">Design</h2>
<li><em>fromRdf</em> tests have <em>input</em> and <em>expected</em> documents. The <em>expected</em> results
can be compared using JSON object comparison with the processor output.</li>
</ul>
<p>To run the tests, create a test runner which will run through each test manifest
and execute the tests defined within the manifest using the rules associated with
each <code>@type</code> defined for the test case as defined in <a href="vocab">The test vocabulary</a>.</p>
</section>
</div>

Expand Down
521 changes: 418 additions & 103 deletions test-suite/vocab.html

Large diffs are not rendered by default.

314 changes: 181 additions & 133 deletions test-suite/vocab.jsonld

Large diffs are not rendered by default.

233 changes: 128 additions & 105 deletions test-suite/vocab.ttl

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions test-suite/vocab_context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"@context": {
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"dc": "http://purl.org/dc/elements/1.1/",
"mf": "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"jld": "http://json-ld.org/test-suite/vocab#",
"jld:Test": {"@type": "@id"},
"dc:identifier": {"@type": "@id"},
"rdfs:subClassOf": {"@type": "@id"},
"rdfs:domain": {"@type": "@id"},
"rdfs:range": {"@type": "@id"}
}
}
28 changes: 28 additions & 0 deletions test-suite/vocab_gen.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env ruby
# Generate vocab.jsonld and vocab.html from vocab.ttl and vocab_template.
#
# Generating vocab.jsonld is equivalent to running the following:
#
# jsonld --compact --context vocab_context.jsonld --input-format ttl vocab.ttl -o vocab.jsonld
require 'linkeddata'
require 'haml'

File.open("vocab.jsonld", "w") do |f|
r = RDF::Repository.load("vocab.ttl")
JSON::LD::API.fromRDF(r) do |expanded|
JSON::LD::API.compact(expanded, File.open("vocab_context.jsonld")) do |compacted|
# Create vocab.jsonld
f.write(compacted.to_json(JSON::LD::JSON_STATE))

# Create vocab.html using vocab_template.haml and compacted vocabulary
template = File.read("vocab_template.haml")

html = Haml::Engine.new(template, :format => :html5).render(self,
:ontology => compacted['@graph'].detect {|o| o['@id'] == "http://json-ld.org/test-suite/vocab#"},
:classes => compacted['@graph'].select {|o| o['@type'] == "rdfs:Class"}.sort_by {|o| o['rdfs:label']},
:properties => compacted['@graph'].select {|o| o['@type'] == "rdfs:Property"}.sort_by {|o| o['rdfs:label']}
)
File.open("vocab.html", "w") {|fh| fh.write html}
end
end
end
121 changes: 121 additions & 0 deletions test-suite/vocab_template.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
!!! 5
%html{:prefix => "jld: http://jsonld.org/test-suite/vocab# mf: http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#"}
%head
%meta{"http-equiv" => "Content-Type", :content => "text/html;charset=utf-8"}
%meta{:name => "viewport", :content => "width=device-width, initial-scale=1.0"}
%link{:rel => "stylesheet", :type => "text/css", :href => "../static/css/bootstrap/bootstrap.css"}
%link{:rel => "stylesheet", :type => "text/css", :href => "../static/css/bootstrap/bootstrap-responsive.css"}
%link{:rel => "stylesheet", :type => "text/css", :href => "../static/css/bootstrap/font-awesome.css"}
%script{:type => "text/javascript", :src => "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"}
%script{:type => "text/javascript", :src => "//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0-rc.3/handlebars.min.js"}
:css
dd code {display: inline;}
%title
= ontology['dc:title']
%body{:resource => ontology['@id']}
%meta{:property => "dc:creator", :value => ontology["dc:creator"]}
%link{:property => "dc:identifier", :href => ontology["@id"]}
%div.navbar.navbar-static-top
%div.navbar-inner
%div.row-fluid
%a.btn.btn-navbar{"data-toggle" => "collapse", "data-target" => ".nav-collapse"}
%span.icon-bar
%span.icon-bar
%span.icon-bar
%a.brand.active{:href => "../"}
%img{:src => "../images/json-ld-data-24.png", :alt => "JSON-LD logo"}
JSON-LD
%div.nav-collapse
%ul.nav
%li
%a{:href => "../playground/index.html"}
%span.icon-beer
Playground
%li
%a{:href => "../learn.html"}
%span.icon-book
Documentation
%li.dropdown
%a.dropdown-toggle{:href => "#", "data-toggle" => "dropdown"}
%span.icon-folder-open
Specifications
%b.caret
%ul.dropdown-menu
%li.nav-header
%strong
Latest
%li
%a{:href => "../spec/latest/json-ld/"}
Syntax
%li
%a{:href => "../spec/latest/json-ld-api/"}
API
%li
%a{:href => "../spec/latest/json-ld-framing/"}
Framing
%li
%a{:href => "../spec/latest/rdf-graph-normalization/"}
Normalization
%li.divider
%li.nav-header
%strong
Previous Drafts
%li
%a{:href => "../spec#syntax"}
Syntax
%li
%a{:href => "../spec#api"}
API
%li
%a{:href => "../spec#framing"}
Framing
%li
%a{:href => "../spec#normalization"}
Normalization
%li
%a{:href => "../images/index.html"}
%span.icon-picture
Branding
%div.hero-unit
%h1{:property => "dc:title"}<= ontology["dc:title"]
%p{:property => "dc:description rdfs:comment"}<=ontology["dc:description"]

%div.container
%div.row
%h2.span12#classes{:style => "text-align: center;"}
Test Case Classes
%div.row
%section.offset2.span8
%dl
- classes.each do |cls|
%dt{:about => cls['@id'], :typeof => cls['@type'], :property => "rdfs:label"}<~cls["rdfs:label"]
%dd{:about => cls['@id'], :property => "rdfs:comment"}
:markdown
#{cls["rdfs:comment"].to_s.gsub(/^\s+/, '')}
%div.row
%h2.span12#classes{:style => "text-align: center;"}
Test Case Properties
%div.row
%section.offset2.span8
%dl
- properties.each do |prop|
%dt{:about => prop['@id'], :typeof => prop['@type'], :property => "rdfs:label"}<~prop["rdfs:label"]
%dd{:about => prop['@id']}
%span{:property => "rdfs:comment"}
:markdown
#{prop["rdfs:comment"].to_s.gsub(/^\s+/, '')}
- if prop["rdfs:domain"]
%div
%strong
domain:
%code{:property => "rdfs:domain", :resource => prop["rdfs:domain"]}
= prop["rdfs:domain"]
- if prop["rdfs:range"]
%div
%strong
range:
%code{:property => "rdfs:range", :resource => prop["rdfs:range"]}
= prop["rdfs:range"]
%div.footer
%span{:property => "dc:publisher"}<= ontology["dc:publisher"]
%script{:type => "text/javascript", :src => "../static/js/bootstrap/bootstrap.js"}

2 comments on commit 73f2c63

@gkellogg
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I addressed these issues in fa23573.

@lanthaler
Copy link
Member

@lanthaler lanthaler commented on 73f2c63 Aug 25, 2013 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.