ttl2html 0.2.6 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/catttl +52 -0
- data/bin/xlsx2shape +2 -1
- data/lib/ttl2html/version.rb +1 -1
- data/lib/ttl2html.rb +19 -1
- data/lib/xlsx2shape.rb +4 -4
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a4695d17d266cffe1bdc9b1b902c3cec45dcda2a6278a705d52a7d13b4fea50
|
4
|
+
data.tar.gz: bed7947d84c69ddc661c7d12da8c53aa6f63ec331430c18a9d2f5fdbbbdfe9ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c8b4b8b7c5497477b7ebcd4fd51e79a9d5e1db04c26b9382aecc3af71433eb3b720c0cc0c0cb78295a47634de6fb445ce422bef78a9f40f4b66f153df000993
|
7
|
+
data.tar.gz: 5516d4fc1c2a4f7ebb590bb67ee4a4fe11015548b9c0ea3cdd6b3eca4edeb2d7a3eba9c6265aec58ad26466d7df1f6c3d031e43904530be15ed3c0ad5f08ff24
|
data/bin/catttl
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "zlib"
|
4
|
+
require "ttl2html"
|
5
|
+
include TTL2HTML
|
6
|
+
|
7
|
+
prefix = {}
|
8
|
+
ttl = []
|
9
|
+
|
10
|
+
ARGV.each do |file|
|
11
|
+
filename = find_turtle(file)
|
12
|
+
if filename.nil?
|
13
|
+
STDERR.puts "#{file} not found. skipping."
|
14
|
+
next
|
15
|
+
end
|
16
|
+
klass = File
|
17
|
+
if File.extname(filename) == ".gz"
|
18
|
+
klass = Zlib::GzipReader
|
19
|
+
end
|
20
|
+
io = klass.open(filename)
|
21
|
+
io.each do |line|
|
22
|
+
line = line.chomp
|
23
|
+
next if line.empty?
|
24
|
+
if line =~ /^@prefix\s+(\w[\w\-]*):\s*<(.+)>/
|
25
|
+
prefix[$1] ||= []
|
26
|
+
prefix[$1] << $2
|
27
|
+
else
|
28
|
+
ttl << line
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
ARGV.each do |file|
|
33
|
+
filename = find_turtle(file)
|
34
|
+
STDERR.puts filename
|
35
|
+
end
|
36
|
+
|
37
|
+
prefix.each do |k, v|
|
38
|
+
STDERR.puts "Duplicate prefixes: #{k}: #{v}" if v.uniq.size > 1
|
39
|
+
prefix[k] = v.sort.first
|
40
|
+
end
|
41
|
+
dups = prefix.values.group_by{|e| e }.select{|k, v| v.size > 1 }.keys
|
42
|
+
unless dups.empty?
|
43
|
+
dups.each do |uri|
|
44
|
+
uris = prefix.keys.select{|e| prefix[e] == uri }
|
45
|
+
STDERR.puts "Duplicate prefixes: #{uri} (#{uris.join(",")})"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
prefix.sort.each do |prefix, uri|
|
50
|
+
puts "@prefix #{prefix}: <#{uri}>."
|
51
|
+
end
|
52
|
+
puts ttl
|
data/bin/xlsx2shape
CHANGED
data/lib/ttl2html/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
TTL2HTML::VERSION = "0.
|
1
|
+
TTL2HTML::VERSION = "0.3.1"
|
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)
|
@@ -229,4 +234,17 @@ module TTL2HTML
|
|
229
234
|
end
|
230
235
|
end
|
231
236
|
end
|
237
|
+
|
238
|
+
def find_turtle(filename, params = {})
|
239
|
+
if params[:noexpand] == true
|
240
|
+
filename if File.exists? filename
|
241
|
+
else
|
242
|
+
file = nil
|
243
|
+
basename = File.basename(filename, ".ttl")
|
244
|
+
dirname = File.dirname(filename)
|
245
|
+
files = Dir.glob("#{dirname}/#{basename}-[0-9]*.ttl{,.gz}")
|
246
|
+
file = files.sort.last
|
247
|
+
file
|
248
|
+
end
|
249
|
+
end
|
232
250
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masao Takaku
|
8
|
-
autorequire:
|
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
|
@@ -132,7 +134,7 @@ homepage: https://github.com/masao/ttl2html
|
|
132
134
|
licenses:
|
133
135
|
- MIT
|
134
136
|
metadata: {}
|
135
|
-
post_install_message:
|
137
|
+
post_install_message:
|
136
138
|
rdoc_options: []
|
137
139
|
require_paths:
|
138
140
|
- lib
|
@@ -147,8 +149,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
149
|
- !ruby/object:Gem::Version
|
148
150
|
version: '0'
|
149
151
|
requirements: []
|
150
|
-
rubygems_version: 3.
|
151
|
-
signing_key:
|
152
|
+
rubygems_version: 3.2.3
|
153
|
+
signing_key:
|
152
154
|
specification_version: 4
|
153
155
|
summary: ttl2html
|
154
156
|
test_files: []
|