ttl2html 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/xlsx2shape +11 -0
- data/lib/ttl2html/version.rb +1 -1
- data/lib/xlsx2shape.rb +122 -0
- metadata +18 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3285a319273819d00281486dadbdea6c82c162856157075db553e18b659b16cc
|
4
|
+
data.tar.gz: 2f66f22a4ad30bd4dc6e0e9a44f24be37cf2e5c11396f4a2c85414becb1dbe6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4301d623df7599b6344806d66c97c71efb0633f45f663be45a460d5ceb23c1fe452d4ed2b01b2df4f02109d4168b8a31acb2dccb21a7f4e4234926cc59e4f4f5
|
7
|
+
data.tar.gz: 930b188d2f0d89601ba6af9199fd0ce87d40b3a00bd8a6711c14a82cb7dc52dae90d871772cd4e39dd4680ef8894e4c9245651e2a158c33f690f887a267f597a
|
data/bin/xlsx2shape
ADDED
data/lib/ttl2html/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
TTL2HTML::VERSION = "0.0
|
1
|
+
TTL2HTML::VERSION = "0.1.0"
|
data/lib/xlsx2shape.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "roo"
|
4
|
+
|
5
|
+
module XLSX2Shape
|
6
|
+
def xlsx2shape(filename)
|
7
|
+
shapes = {}
|
8
|
+
prefix = {}
|
9
|
+
xlsx = Roo::Excelx.new(filename)
|
10
|
+
xlsx.each_with_pagename do |name, sheet|
|
11
|
+
if name =~ /\Aprefix\z/i
|
12
|
+
sheet.each do |row|
|
13
|
+
prefix[row[0]] = row[1] if not row[1].empty?
|
14
|
+
end
|
15
|
+
else
|
16
|
+
headers = sheet.row(1)
|
17
|
+
uri = headers.first
|
18
|
+
shapes[uri] = ["<#{uri}> a sh:NodeShape"]
|
19
|
+
order = 1
|
20
|
+
sheet.each_with_index do |row, idx|
|
21
|
+
row_h = map_xlsx_row_headers(row, headers)
|
22
|
+
case row.first
|
23
|
+
when "sh:targetClass"
|
24
|
+
shapes[uri] << "#{format_property("sh:targetClass", row[1])}" if row[1]
|
25
|
+
when "sh:property"
|
26
|
+
prop_values = []
|
27
|
+
headers[1..-1].each do |prop|
|
28
|
+
next if row_h[prop].empty?
|
29
|
+
case prop
|
30
|
+
when /\@(\w+)\z/
|
31
|
+
lang = $1
|
32
|
+
property_name = prop.sub(/\@(\w+)\z/, "")
|
33
|
+
prop_values << format_property(property_name, row_h[prop], lang)
|
34
|
+
when "sh:minCount", "sh:maxCount"
|
35
|
+
prop_values << format_property(prop, row_h[prop].to_i)
|
36
|
+
when "sh:languageIn"
|
37
|
+
prop_values << " sh:languageIn (#{row_h[prop].split.map{|e| format_pvalue(e) }.join(" ")})"
|
38
|
+
when "sh:uniqueLang"
|
39
|
+
case row_h[prop]
|
40
|
+
when "true"
|
41
|
+
prop_values << " sh:uniqueLang true"
|
42
|
+
when "false"
|
43
|
+
prop_values << " sh:uniqueLang false"
|
44
|
+
else
|
45
|
+
logger.warn "sh:uniqueLang value unknown: #{row_h[prop]} at #{uri}"
|
46
|
+
end
|
47
|
+
else
|
48
|
+
prop_values << format_property(prop, row_h[prop])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
prop_values << format_property("sh:order", order)
|
52
|
+
order += 1
|
53
|
+
str = prop_values.join(";\n ")
|
54
|
+
shapes[uri] << " sh:property [\n #{str}\n ]"
|
55
|
+
when "sh:or"
|
56
|
+
shapes[uri] << " sh:or (#{row[1..-1].select{|e| not e.empty? }.map{|e| format_pvalue(e) }.join(" ")})"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
result = ""
|
62
|
+
prefix.sort.each do |prefix, val|
|
63
|
+
result << "@prefix #{prefix} <#{val}>.\n"
|
64
|
+
end
|
65
|
+
shapes.sort_by{|uri, val| uri }.each do |uri, val|
|
66
|
+
result << "\n"
|
67
|
+
result << shapes[uri].join(";\n")
|
68
|
+
result << ".\n"
|
69
|
+
end
|
70
|
+
result
|
71
|
+
end
|
72
|
+
|
73
|
+
def map_xlsx_row_headers(data_row, headers)
|
74
|
+
hash = {}
|
75
|
+
headers.each_with_index do |h, idx|
|
76
|
+
hash[h] = data_row[idx].to_s
|
77
|
+
end
|
78
|
+
hash
|
79
|
+
end
|
80
|
+
def format_pvalue(value, lang = nil)
|
81
|
+
str = ""
|
82
|
+
if value.is_a? Hash
|
83
|
+
result = ["["]
|
84
|
+
array = []
|
85
|
+
value.keys.sort.each do |k|
|
86
|
+
array << format_property(k, value[k])
|
87
|
+
end
|
88
|
+
result << array.join(";\n")
|
89
|
+
result << " ]"
|
90
|
+
str = result.join("\n")
|
91
|
+
elsif value.is_a? Integer
|
92
|
+
str = value
|
93
|
+
elsif value =~ /\Ahttps?:\/\//
|
94
|
+
str = %Q|<#{value}>|
|
95
|
+
elsif value =~ /\A\w+:[\w\-\.]+\Z/
|
96
|
+
str = value
|
97
|
+
elsif value =~ /\A(.+?)\^\^(\w+:\w+)\z/
|
98
|
+
str = %Q|"#{escape_turtle($1)}"^^#{$2}|
|
99
|
+
elsif lang
|
100
|
+
str = %Q|"#{escape_turtle(value)}"@#{lang}|
|
101
|
+
else
|
102
|
+
str = %Q|"#{escape_turtle(value)}"|
|
103
|
+
end
|
104
|
+
str
|
105
|
+
end
|
106
|
+
def format_property(property, value, lang = nil)
|
107
|
+
if value.is_a? Array
|
108
|
+
value = value.sort_by{|e|
|
109
|
+
format_pvalue(e)
|
110
|
+
}.map do |e|
|
111
|
+
format_pvalue(e)
|
112
|
+
end
|
113
|
+
%Q| #{property} #{ value.join(", ") }|
|
114
|
+
else
|
115
|
+
value = format_pvalue(value, lang)
|
116
|
+
%Q| #{property} #{value}|
|
117
|
+
end
|
118
|
+
end
|
119
|
+
def escape_turtle(str)
|
120
|
+
str.gsub(/\\/){ '\\\\' }.gsub(/"/){ '\"' }
|
121
|
+
end
|
122
|
+
end
|
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.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masao Takaku
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: roo
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: ruby-progressbar
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,13 +112,16 @@ description: Static site generator for RDF/Turtle
|
|
98
112
|
email: tmasao@acm.org
|
99
113
|
executables:
|
100
114
|
- ttl2html
|
115
|
+
- xlsx2shape
|
101
116
|
extensions: []
|
102
117
|
extra_rdoc_files: []
|
103
118
|
files:
|
104
119
|
- bin/ttl2html
|
120
|
+
- bin/xlsx2shape
|
105
121
|
- lib/ttl2html.rb
|
106
122
|
- lib/ttl2html/template.rb
|
107
123
|
- lib/ttl2html/version.rb
|
124
|
+
- lib/xlsx2shape.rb
|
108
125
|
- templates/default.html.erb
|
109
126
|
- templates/index.html.erb
|
110
127
|
- templates/layout.html.erb
|