ttl2html 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/catttl +46 -0
- data/bin/xlsx2shape +2 -1
- data/lib/ttl2html/version.rb +1 -1
- data/lib/ttl2html.rb +20 -2
- data/lib/xlsx2shape.rb +4 -4
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c6cc6b025ce5ec57709788d914a9507dc66160feed31a083e101acb2d128461
|
4
|
+
data.tar.gz: 994ea0ec7c5131b21ba7c709c4693c9fe341a9cb3e19f8d53b28f8f2a9d39056
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb77aca35e592354697fddd2b32e65ba8515ed6631bf8edfbf5ddd1ee2442f62f0a872a17a27fb1230c2665b1b5067a13b1e504c31aedfa3c613f87ec0ce1881
|
7
|
+
data.tar.gz: b0d58cf7689127f8d1a47e3f4fbc500e228e075baf49c9edb7f6c3e86378c8f861f8336cabbe5f0e8ad87778091fcfb970a86e2e62a2e894e49cf7bad4dd0eb2
|
data/bin/catttl
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "ttl2html"
|
4
|
+
include Textbook
|
5
|
+
|
6
|
+
prefix = {}
|
7
|
+
ttl = []
|
8
|
+
|
9
|
+
ARGV.each do |file|
|
10
|
+
filename = find_turtle(file)
|
11
|
+
klass = File
|
12
|
+
if File.extname(file) == ".gz"
|
13
|
+
klass = Zlib::GzipReader
|
14
|
+
end
|
15
|
+
klass.readlines(filename).each do |line|
|
16
|
+
line = line.chomp
|
17
|
+
next if line.empty?
|
18
|
+
if line =~ /^@prefix\s+(\w[\w\-]*):\s*<(.+)>/
|
19
|
+
prefix[$1] ||= []
|
20
|
+
prefix[$1] << $2
|
21
|
+
else
|
22
|
+
ttl << line
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
ARGV.each do |file|
|
27
|
+
filename = find_turtle(file)
|
28
|
+
STDERR.puts filename
|
29
|
+
end
|
30
|
+
|
31
|
+
prefix.each do |k, v|
|
32
|
+
STDERR.puts "Duplicate prefixes: #{k}: #{v}" if v.uniq.size > 1
|
33
|
+
prefix[k] = v.sort.first
|
34
|
+
end
|
35
|
+
dups = prefix.values.group_by{|e| e }.select{|k, v| v.size > 1 }.keys
|
36
|
+
unless dups.empty?
|
37
|
+
dups.each do |uri|
|
38
|
+
uris = prefix.keys.select{|e| prefix[e] == uri }
|
39
|
+
STDERR.puts "Duplicate prefixes: #{uri} (#{uris.join(",")})"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
prefix.sort.each do |prefix, uri|
|
44
|
+
puts "@prefix #{prefix}: <#{uri}>."
|
45
|
+
end
|
46
|
+
puts ttl
|
data/bin/xlsx2shape
CHANGED
data/lib/ttl2html/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
TTL2HTML::VERSION = "0.
|
1
|
+
TTL2HTML::VERSION = "0.3.0"
|
data/lib/ttl2html.rb
CHANGED
@@ -33,7 +33,12 @@ module TTL2HTML
|
|
33
33
|
def load_turtle(file)
|
34
34
|
STDERR.puts "loading #{file}..."
|
35
35
|
count = 0
|
36
|
-
|
36
|
+
if file.end_with?(".gz")
|
37
|
+
io = Zlib::GzipReader.open(file)
|
38
|
+
else
|
39
|
+
io = File.open(file)
|
40
|
+
end
|
41
|
+
RDF::Turtle::Reader.new(io) do |reader|
|
37
42
|
@prefix.merge! reader.prefixes
|
38
43
|
reader.statements.each do |statement|
|
39
44
|
@graph.insert(statement)
|
@@ -59,6 +64,19 @@ module TTL2HTML
|
|
59
64
|
STDERR.puts "#{count} triples. #{@data.size} subjects."
|
60
65
|
@data
|
61
66
|
end
|
67
|
+
def find_turtle(filename, params = {})
|
68
|
+
if params[:noexpand] == true
|
69
|
+
filename if File.exists? filename
|
70
|
+
else
|
71
|
+
file = nil
|
72
|
+
basename = File.basename(filename, ".ttl")
|
73
|
+
dirname = File.dirname(filename)
|
74
|
+
files = Dir.glob("#{dirname}/#{basename}-[0-9]*.ttl{,.gz}")
|
75
|
+
file = files.sort.last
|
76
|
+
file
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
62
80
|
def format_turtle(subject, depth = 1)
|
63
81
|
turtle = RDF::Turtle::Writer.new
|
64
82
|
result = ""
|
@@ -152,7 +170,7 @@ module TTL2HTML
|
|
152
170
|
template = Template.new("index.html.erb", @config)
|
153
171
|
param = @config.dup
|
154
172
|
param[:data_global] = @data
|
155
|
-
subjects.each do |subject|
|
173
|
+
subjects.sort.each do |subject|
|
156
174
|
param[:index_data] ||= []
|
157
175
|
param[:index_data] << subject.to_s
|
158
176
|
end
|
data/lib/xlsx2shape.rb
CHANGED
@@ -5,12 +5,12 @@ require "roo"
|
|
5
5
|
module XLSX2Shape
|
6
6
|
def xlsx2shape(filename)
|
7
7
|
shapes = {}
|
8
|
-
prefix = {
|
8
|
+
prefix = { sh: "http://www.w3.org/ns/shacl#" }
|
9
9
|
xlsx = Roo::Excelx.new(filename)
|
10
10
|
xlsx.each_with_pagename do |name, sheet|
|
11
11
|
if name =~ /\Aprefix\z/i
|
12
12
|
sheet.each do |row|
|
13
|
-
prefix[row[0]] = row[1] if not row[1].empty?
|
13
|
+
prefix[row[0].to_s.intern] = row[1] if not row[1].empty?
|
14
14
|
end
|
15
15
|
else
|
16
16
|
headers = sheet.row(1)
|
@@ -59,8 +59,8 @@ module XLSX2Shape
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
result = ""
|
62
|
-
prefix.
|
63
|
-
result << "@prefix #{prefix} <#{val}>.\n"
|
62
|
+
prefix.sort_by{|k,v| [k,v] }.each do |prefix, val|
|
63
|
+
result << "@prefix #{prefix}: <#{val}>.\n"
|
64
64
|
end
|
65
65
|
shapes.sort_by{|uri, val| uri }.each do |uri, val|
|
66
66
|
result << "\n"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ttl2html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masao Takaku
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -113,9 +113,11 @@ email: tmasao@acm.org
|
|
113
113
|
executables:
|
114
114
|
- ttl2html
|
115
115
|
- xlsx2shape
|
116
|
+
- catttl
|
116
117
|
extensions: []
|
117
118
|
extra_rdoc_files: []
|
118
119
|
files:
|
120
|
+
- bin/catttl
|
119
121
|
- bin/ttl2html
|
120
122
|
- bin/xlsx2shape
|
121
123
|
- lib/ttl2html.rb
|