ttl2html 0.1.0 → 0.2.0
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 +4 -4
- data/lib/ttl2html/template.rb +59 -1
- data/lib/ttl2html/version.rb +1 -1
- data/lib/ttl2html.rb +41 -8
- data/templates/about.html.erb +24 -0
- data/templates/shape-table.html.erb +55 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbbc4da0cfa20d2803025a5273b8399a1376af7e6e2a181cad79eaba19e7da9f
|
4
|
+
data.tar.gz: 6962165c275071e94c34152e6474777f94f46f196fb1b04804b3ea17d6a0c8c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2129bdefbb7b498a06301479638c96d1d35a67a8812a28202d0fc3eae1a706e393433b684f0e629c7cc0a2a7ba8e05d3cf5caa1a51e10731a9b0145c009af7b1
|
7
|
+
data.tar.gz: 5e5e04ce0c0f2e1e8434cba7ac54a146eb23fb00ab39e007f4c78146f78cd1ddda4bdd89ae7d168ddb831c935b4ff3bde306e9f274c0477b67e9e7b1c49b0d3c
|
data/lib/ttl2html/template.rb
CHANGED
@@ -48,7 +48,65 @@ module TTL2HTML
|
|
48
48
|
end
|
49
49
|
return nil
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
|
+
def expand_shape(data, uri, prefixes = {})
|
53
|
+
return nil if not data[uri]
|
54
|
+
return nil if not data[uri]["http://www.w3.org/ns/shacl#property"]
|
55
|
+
result = data[uri]["http://www.w3.org/ns/shacl#property"].sort_by do |e|
|
56
|
+
e["http://www.w3.org/ns/shacl#order"]
|
57
|
+
end.map do |property|
|
58
|
+
path = data[property]["http://www.w3.org/ns/shacl#path"].first
|
59
|
+
shorten_path = path.dup
|
60
|
+
prefixes.each do |prefix, val|
|
61
|
+
if path.index(val) == 0
|
62
|
+
shorten_path = path.sub(/\A#{val}/, "#{prefix}:")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
repeatable = false
|
66
|
+
if data[property]["http://www.w3.org/ns/shacl#maxCount"]
|
67
|
+
max_count = data[property]["http://www.w3.org/ns/shacl#maxCount"].first.to_i
|
68
|
+
if max_count > 1
|
69
|
+
repeatable = true
|
70
|
+
end
|
71
|
+
else
|
72
|
+
repeatable = true
|
73
|
+
end
|
74
|
+
nodes = nil
|
75
|
+
if data[property]["http://www.w3.org/ns/shacl#node"]
|
76
|
+
node = data[property]["http://www.w3.org/ns/shacl#node"].first
|
77
|
+
if data[node]["http://www.w3.org/ns/shacl#or"]
|
78
|
+
node_or = data[data[node]["http://www.w3.org/ns/shacl#or"].first]
|
79
|
+
node_mode = :or
|
80
|
+
nodes = []
|
81
|
+
nodes << expand_shape(data, node_or["http://www.w3.org/1999/02/22-rdf-syntax-ns#first"].first, prefixes)
|
82
|
+
rest = node_or["http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"].first
|
83
|
+
while data[rest] do
|
84
|
+
nodes << expand_shape(data, data[rest]["http://www.w3.org/1999/02/22-rdf-syntax-ns#first"].first, prefixes)
|
85
|
+
rest = data[rest]["http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"].first
|
86
|
+
end
|
87
|
+
else
|
88
|
+
nodes = expand_shape(data, node, prefixes)
|
89
|
+
end
|
90
|
+
#p nodes
|
91
|
+
end
|
92
|
+
{
|
93
|
+
path: path,
|
94
|
+
shorten_path: shorten_path,
|
95
|
+
name: data[property]["http://www.w3.org/ns/shacl#name"].first,
|
96
|
+
example: data[property]["http://www.w3.org/2004/02/skos/core#example"] ? data[property]["http://www.w3.org/2004/02/skos/core#example"].first : nil,
|
97
|
+
description: data[property]["http://www.w3.org/ns/shacl#description"] ? data[property]["http://www.w3.org/ns/shacl#description"].first : nil,
|
98
|
+
required: data[property]["http://www.w3.org/ns/shacl#minCount"] ? data[property]["http://www.w3.org/ns/shacl#minCount"].first.to_i > 0 : false,
|
99
|
+
repeatable: repeatable,
|
100
|
+
nodeKind: data[property]["http://www.w3.org/ns/shacl#nodeKind"] ? data[property]["http://www.w3.org/ns/shacl#nodeKind"].first : nil,
|
101
|
+
nodes: nodes,
|
102
|
+
node_mode: node_mode,
|
103
|
+
}
|
104
|
+
end
|
105
|
+
template = "shape-table.html.erb"
|
106
|
+
tmpl = Template.new(template)
|
107
|
+
tmpl.to_html_raw(template, {properties: result})
|
108
|
+
end
|
109
|
+
|
52
110
|
# helper method:
|
53
111
|
def relative_path(dest)
|
54
112
|
src = @param[:output_file]
|
data/lib/ttl2html/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
TTL2HTML::VERSION = "0.
|
1
|
+
TTL2HTML::VERSION = "0.2.0"
|
data/lib/ttl2html.rb
CHANGED
@@ -18,6 +18,7 @@ module TTL2HTML
|
|
18
18
|
end
|
19
19
|
@data = {}
|
20
20
|
@data_inverse = {}
|
21
|
+
@prefix = {}
|
21
22
|
@graph = RDF::Graph.new
|
22
23
|
end
|
23
24
|
|
@@ -33,6 +34,7 @@ module TTL2HTML
|
|
33
34
|
STDERR.puts "loading #{file}..."
|
34
35
|
count = 0
|
35
36
|
RDF::Turtle::Reader.open(file) do |reader|
|
37
|
+
@prefix.merge! reader.prefixes
|
36
38
|
reader.statements.each do |statement|
|
37
39
|
@graph.insert(statement)
|
38
40
|
s = statement.subject
|
@@ -137,17 +139,48 @@ module TTL2HTML
|
|
137
139
|
end
|
138
140
|
index_html = "index.html"
|
139
141
|
index_html = File.join(@config[:output_dir], "index.html") if @config[:output_dir]
|
140
|
-
if @config.has_key? :top_class
|
141
|
-
|
142
|
+
if @config.has_key? :top_class
|
143
|
+
subjects = @graph.query([nil,
|
144
|
+
RDF::URI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
|
145
|
+
RDF::URI(@config[:top_class])]).subjects
|
146
|
+
if subjects.empty?
|
147
|
+
STDERR.puts "WARN: top_class parameter specified as [#{@config[:top_class]}], but there is no instance data."
|
148
|
+
STDERR.puts " Skip generation of top page."
|
149
|
+
else
|
150
|
+
template = Template.new("index.html.erb", @config)
|
151
|
+
param = @config.dup
|
152
|
+
param[:data_global] = @data
|
153
|
+
subjects.each do |subject|
|
154
|
+
param[:index_data] ||= []
|
155
|
+
param[:index_data] << subject.to_s
|
156
|
+
end
|
157
|
+
template.output_to(index_html, param)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
shapes = @graph.query([nil,
|
161
|
+
RDF::URI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
|
162
|
+
RDF::URI("http://www.w3.org/ns/shacl#NodeShape")])
|
163
|
+
if shapes.size > 0
|
164
|
+
about_html = @config[:about_file] || "about.html"
|
165
|
+
about_html = File.join(@config[:output_dir], about_html) if @config[:output_dir]
|
166
|
+
template = Template.new("about.html.erb", @config)
|
142
167
|
param = @config.dup
|
143
168
|
param[:data_global] = @data
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
169
|
+
param[:content] = {}
|
170
|
+
shapes.subjects.each do |subject|
|
171
|
+
label = nil
|
172
|
+
target_class = @data[subject.to_s]["http://www.w3.org/ns/shacl#targetClass"]
|
173
|
+
if target_class and @data[target_class.first]
|
174
|
+
label = template.get_title(@data[target_class.first])
|
175
|
+
else
|
176
|
+
label = template.get_title(@data[subject.to_s])
|
177
|
+
end
|
178
|
+
param[:content][subject] = {
|
179
|
+
label: label,
|
180
|
+
html: template.expand_shape(@data, subject.to_s, @prefix),
|
181
|
+
}
|
149
182
|
end
|
150
|
-
template.output_to(
|
183
|
+
template.output_to(about_html, param)
|
151
184
|
end
|
152
185
|
end
|
153
186
|
def output_turtle_files
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<div class="jumbotron">
|
2
|
+
<div class="container">
|
3
|
+
<h1><%=h param[:site_title] %>について</h1>
|
4
|
+
</div>
|
5
|
+
</div>
|
6
|
+
<div class="container">
|
7
|
+
<div class="row">
|
8
|
+
<div class="col-md-12">
|
9
|
+
<ol class="breadcrumb">
|
10
|
+
<li><a href="./"><span class="glyphicon glyphicon-home" aria-hidden="true"></span> Home</a></li>
|
11
|
+
<li class="active"><%=h param[:site_title] %>について</li>
|
12
|
+
</ol>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<div class="row">
|
17
|
+
<div class="col-md-10">
|
18
|
+
<%- param[:content].keys.sort.each do |shape| -%>
|
19
|
+
<h3><%=h param[:content][shape][:label] %>をあらわすリソース</h3>
|
20
|
+
<p><%=h param[:content][shape][:label] %>リソースが持つプロパティを下表に示します</p>
|
21
|
+
<%= param[:content][shape][:html] -%>
|
22
|
+
<%- end -%>
|
23
|
+
</div>
|
24
|
+
</div>
|
@@ -0,0 +1,55 @@
|
|
1
|
+
<table class="table table-condensed">
|
2
|
+
<tr>
|
3
|
+
<th>プロパティ名</th><th>説明</th><th>プロパティ値の例</th><th>必須・省略の別<br>繰り返しの有無</th><th>備考</th>
|
4
|
+
</tr>
|
5
|
+
<tbody>
|
6
|
+
<%- param[:properties].each do |property| -%>
|
7
|
+
<tr>
|
8
|
+
<%- if property[:nodeKind] == "http://www.w3.org/ns/shacl#BlankNode" -%>
|
9
|
+
<td rowspan="2"><code><%=h property[:shorten_path] %></code></td>
|
10
|
+
<%- else -%>
|
11
|
+
<td><code><%=h property[:shorten_path] %></code></td>
|
12
|
+
<%- end -%>
|
13
|
+
<td><%= property[:name_ja] %></td>
|
14
|
+
<%- if property[:nodeKind] == "http://www.w3.org/ns/shacl#IRI" -%>
|
15
|
+
<td class="url"><%= property[:example] %></td>
|
16
|
+
<%- else -%>
|
17
|
+
<td><%= property[:example] %></td>
|
18
|
+
<%- end -%>
|
19
|
+
<td>
|
20
|
+
<div>
|
21
|
+
<%- if property[:required] -%>
|
22
|
+
<strong>必須</strong>
|
23
|
+
<%- else -%>
|
24
|
+
省略可能
|
25
|
+
<%- end -%>
|
26
|
+
</div>
|
27
|
+
<div>
|
28
|
+
<%- if property[:repeatable] -%>
|
29
|
+
繰り返し有り
|
30
|
+
<%- else -%>
|
31
|
+
繰り返し無し
|
32
|
+
<%- end -%>
|
33
|
+
</div>
|
34
|
+
</td>
|
35
|
+
<td><%= property[:description_ja] %></td>
|
36
|
+
</tr>
|
37
|
+
<%- if property[:nodeKind] == "http://www.w3.org/ns/shacl#BlankNode" -%>
|
38
|
+
<tr>
|
39
|
+
<td colspan="4">
|
40
|
+
<%- if property[:node_mode] == :or -%>
|
41
|
+
ブランクノードの内容は以下のいずれかの内容からなる構造を持ちます。
|
42
|
+
<%- property[:nodes].each do |e| -%>
|
43
|
+
<div class="blank_node"><%= e.sub(/class="table"/, 'class="table table-condensed"') %></div>
|
44
|
+
<%- end -%>
|
45
|
+
<%- else -%>
|
46
|
+
ブランクノードの内容は以下の構造を持ちます。
|
47
|
+
<div class="blank_node"><%= property[:nodes].sub(/class="table"/, 'class="table table-condensed"') %></div>
|
48
|
+
<%- end -%>
|
49
|
+
</td>
|
50
|
+
</tr>
|
51
|
+
<%- end -%>
|
52
|
+
<%- end -%>
|
53
|
+
</tbody>
|
54
|
+
</table>
|
55
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ttl2html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masao Takaku
|
@@ -122,9 +122,11 @@ files:
|
|
122
122
|
- lib/ttl2html/template.rb
|
123
123
|
- lib/ttl2html/version.rb
|
124
124
|
- lib/xlsx2shape.rb
|
125
|
+
- templates/about.html.erb
|
125
126
|
- templates/default.html.erb
|
126
127
|
- templates/index.html.erb
|
127
128
|
- templates/layout.html.erb
|
129
|
+
- templates/shape-table.html.erb
|
128
130
|
- templates/triples.html.erb
|
129
131
|
homepage: https://github.com/masao/ttl2html
|
130
132
|
licenses:
|