rdf2json 0.0.2 → 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/.travis.yml +0 -6
- data/Gemfile +4 -0
- data/README.md +2 -0
- data/VERSION +1 -1
- data/lib/rdf2json/rdf2json.rb +61 -28
- data/test/helper.rb +16 -3
- data/test/test_rdf2json.rb +224 -0
- metadata +31 -3
- data/test/test_bio-rdf2json.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 744a041e168424a1d704f0be0e89e36a52e3f24b
|
4
|
+
data.tar.gz: 0cf661762f47da4666a5f69a05d8f107f35bfdc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e062d274606bce55c58c3cf31ae4e7e52138e5d682cce733c63003145028a6a79c0efbba90d73a58418fe7985bc1c4f7b5dfaea32cd2116f5ee41bd810057b2
|
7
|
+
data.tar.gz: 85885316a1eb81fbdea361f1beb6aefe2568c4105657e4c5e4cb4cdcb455562bfbc173f2321c5a8f9d4cdffda126a8431db7eb9dae3aaff1727bde40ad6c1315
|
data/.travis.yml
CHANGED
@@ -1,14 +1,8 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 1.9.2
|
4
3
|
- 1.9.3
|
5
4
|
- 2.0.0
|
6
5
|
- 2.1.1
|
7
6
|
|
8
|
-
# - rbx-19mode
|
9
|
-
# - 1.8.7
|
10
|
-
# - jruby-18mode # JRuby in 1.8 mode
|
11
|
-
# - rbx-18mode
|
12
|
-
|
13
7
|
# uncomment this line if your project needs to run something other than `rake`:
|
14
8
|
# script: bundle exec rspec spec
|
data/Gemfile
CHANGED
@@ -5,9 +5,13 @@ source "http://rubygems.org"
|
|
5
5
|
gem "rdf", ">= 1.1.3"
|
6
6
|
gem "json-ld", ">= 1.1.3"
|
7
7
|
|
8
|
+
# Coverage via Coveralls:
|
9
|
+
gem 'coveralls', require: false
|
10
|
+
|
8
11
|
# Add dependencies to develop your gem here.
|
9
12
|
# Include everything needed to run rake, tests, features, etc.
|
10
13
|
group :development do
|
14
|
+
gem "minitest", ">= 5.3.4"
|
11
15
|
gem "shoulda", ">= 0"
|
12
16
|
gem "simplecov", ">= 0"
|
13
17
|
gem "jeweler", "~> 1.8.4"
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# rdf2json
|
2
2
|
|
3
3
|
[![Build Status](https://secure.travis-ci.org/joejimbo/rdf2json.png)](http://travis-ci.org/joejimbo/rdf2json)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/joejimbo/rdf2json/badge.png?branch=master)](https://coveralls.io/r/joejimbo/rdf2json?branch=master)
|
4
5
|
|
5
6
|
Reads RDF N-Triple/N-Quads that are sorted by subject and
|
6
7
|
append a JSON/JSON-LD document per line in a designated
|
@@ -37,6 +38,7 @@ sort -k 1,1 UNSORTED.EXT > SORTED.EXT
|
|
37
38
|
|
38
39
|
#### Common options
|
39
40
|
|
41
|
+
* `-s`, `--silent`: Do not output summary statistics.
|
40
42
|
* `-h`, `--help`: Show this message.
|
41
43
|
|
42
44
|
#### JSON output (`--minimize` option)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/lib/rdf2json/rdf2json.rb
CHANGED
@@ -13,7 +13,26 @@ module RDF2JSON
|
|
13
13
|
# Command line interface; reads parameters, outputs help, or proceeds with the
|
14
14
|
# transformation of RDF N-Triples/N-Quads into JSON/JSON-LD.
|
15
15
|
def self.cli
|
16
|
-
|
16
|
+
options_or_exit_code = option_parser
|
17
|
+
|
18
|
+
exit options_or_exit_code unless options_or_exit_code.kind_of?(Hash)
|
19
|
+
options = options_or_exit_code
|
20
|
+
|
21
|
+
begin
|
22
|
+
# Why instantiate a Converter instance here? Well, for implementing parallelization later:
|
23
|
+
Converter.new(options[:input], options[:output], options[:input_format], options[:output_format], options[:namespace], options[:prefix], !options[:silent]).convert
|
24
|
+
rescue Interrupt
|
25
|
+
# The user hit Ctrl-C, which is okay and does not need error reporting.
|
26
|
+
exit 0
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Command line option parser. Returns either the set options as a hash, or,
|
31
|
+
# returns an integer that indicates the shell error return code.
|
32
|
+
#
|
33
|
+
# +argv+:: optional command line arguments (may be nil; for unit testing)
|
34
|
+
def self.option_parser(argv = nil)
|
35
|
+
options = { :silent => false }
|
17
36
|
|
18
37
|
parser = OptionParser.new { |opts|
|
19
38
|
opts.banner = 'Usage: rdf2json [options] --input filename.nt --output filename.json'
|
@@ -62,24 +81,31 @@ def self.cli
|
|
62
81
|
opts.separator ''
|
63
82
|
opts.separator 'Common options:'
|
64
83
|
|
84
|
+
opts.on_tail('-s', '--silent', 'Do not output summary statistics.') { |silent|
|
85
|
+
options[:silent] = true
|
86
|
+
}
|
65
87
|
opts.on_tail('-h', '--help', 'Show this message.') { |help|
|
66
88
|
puts opts
|
67
|
-
|
89
|
+
return 0
|
68
90
|
}
|
69
91
|
}
|
70
92
|
|
71
93
|
begin
|
72
|
-
|
94
|
+
if argv then
|
95
|
+
parser.parse! argv
|
96
|
+
else
|
97
|
+
parser.parse!
|
98
|
+
end
|
73
99
|
rescue
|
74
100
|
puts parser
|
75
|
-
|
101
|
+
return 1
|
76
102
|
end
|
77
103
|
|
78
104
|
unless options.has_key?(:input) and options.has_key?(:output) then
|
79
105
|
puts 'Error: Requires --input and --output parameters.'
|
80
106
|
puts ''
|
81
107
|
puts parser
|
82
|
-
|
108
|
+
return 2
|
83
109
|
end
|
84
110
|
|
85
111
|
if options.has_key?(:ntriples) and options.has_key?(:nquads) then
|
@@ -88,18 +114,18 @@ def self.cli
|
|
88
114
|
puts ' setting the input fileformat.'
|
89
115
|
puts ''
|
90
116
|
puts parser
|
91
|
-
|
117
|
+
return 3
|
92
118
|
end
|
93
119
|
|
94
120
|
extension = File.extname(options[:input])
|
95
121
|
if options.has_key?(:ntriples) then
|
96
|
-
input_format = :ntriples
|
122
|
+
options[:input_format] = :ntriples
|
97
123
|
elsif options.has_key?(:nquads) then
|
98
|
-
input_format = :nquads
|
124
|
+
options[:input_format] = :nquads
|
99
125
|
elsif extension == '.nt' then
|
100
|
-
input_format = :ntriples
|
126
|
+
options[:input_format] = :ntriples
|
101
127
|
elsif extension == '.nq' then
|
102
|
-
input_format = :nquads
|
128
|
+
options[:input_format] = :nquads
|
103
129
|
else
|
104
130
|
puts 'Error: Cannot determine input file format by filename extension.'
|
105
131
|
puts ' Recognized fileformat extensions are .nt and .nq for N-Triples'
|
@@ -108,26 +134,20 @@ def self.cli
|
|
108
134
|
puts ' when one of those options is given.'
|
109
135
|
puts ''
|
110
136
|
puts parser
|
111
|
-
|
137
|
+
return 4
|
112
138
|
end
|
113
139
|
|
114
|
-
output_format = :jsonld
|
115
|
-
output_format = :json if options[:minimize]
|
140
|
+
options[:output_format] = :jsonld
|
141
|
+
options[:output_format] = :json if options[:minimize]
|
116
142
|
|
117
143
|
unless File.exist?(options[:input]) then
|
118
144
|
puts 'Error: Input file (--input parameter) does not seem to exist.'
|
119
145
|
puts ''
|
120
146
|
puts parser
|
121
|
-
|
147
|
+
return 6
|
122
148
|
end
|
123
149
|
|
124
|
-
|
125
|
-
# Why instantiate a Converter instance here? Well, for implementing parallelization later:
|
126
|
-
Converter.new(options[:input], options[:output], input_format, output_format, options[:namespace], options[:prefix]).convert
|
127
|
-
rescue Interrupt
|
128
|
-
# The user hit Ctrl-C, which is okay and does not need error reporting.
|
129
|
-
exit 0
|
130
|
-
end
|
150
|
+
return options
|
131
151
|
end
|
132
152
|
|
133
153
|
# Class that takes an input file (RDF N-Triples/N-Quads) and appends JSON/JSON-LD to
|
@@ -143,13 +163,15 @@ class Converter
|
|
143
163
|
# +output_format+:: format of the output (:json or jsonld)
|
144
164
|
# +namespace+:: a possible namespace for replacing "@id" keys (may be nil)
|
145
165
|
# +prefix+:: a possible prefix for shortening keys (may be nil)
|
146
|
-
|
166
|
+
# +summary+:: determines whether summary statistics should be printed (may be nil; means no summary)
|
167
|
+
def initialize(input_filename, output_filename, input_format, output_format, namespace = nil, prefix = nil, summary = nil)
|
147
168
|
@input_file = File.open(input_filename, 'r')
|
148
169
|
@output_file = File.open(output_filename, 'a')
|
149
170
|
@input_format = input_format
|
150
171
|
@output_format = output_format
|
151
172
|
@namespace = namespace
|
152
173
|
@prefix = prefix
|
174
|
+
@summary = summary
|
153
175
|
end
|
154
176
|
|
155
177
|
# Convert the input file by appending the newly formatted data to the output file.
|
@@ -160,6 +182,7 @@ class Converter
|
|
160
182
|
# of lines appended).
|
161
183
|
def convert
|
162
184
|
no_of_lines = 0
|
185
|
+
documents = 0
|
163
186
|
no_of_statements = 0
|
164
187
|
read_errors = 0
|
165
188
|
last_subject = nil
|
@@ -167,14 +190,16 @@ class Converter
|
|
167
190
|
|
168
191
|
@input_file.each_line { |line|
|
169
192
|
no_of_lines += 1
|
170
|
-
line.chomp!
|
171
193
|
|
172
194
|
subject = "#{line.sub(/>.*/, '')}>"
|
173
195
|
|
196
|
+
last_subject = subject unless last_subject
|
197
|
+
|
174
198
|
if subject == last_subject then
|
175
199
|
subject_block << line
|
176
200
|
else
|
177
201
|
stats = write_graph(subject_block)
|
202
|
+
documents += stats[:documents]
|
178
203
|
no_of_statements += stats[:no_of_statements]
|
179
204
|
read_errors += stats[:read_errors]
|
180
205
|
subject_block = ''
|
@@ -184,12 +209,18 @@ class Converter
|
|
184
209
|
}
|
185
210
|
|
186
211
|
stats = write_graph(subject_block)
|
212
|
+
documents += stats[:documents]
|
187
213
|
no_of_statements += stats[:no_of_statements]
|
188
214
|
read_errors += stats[:read_errors]
|
189
215
|
|
190
|
-
|
191
|
-
|
192
|
-
|
216
|
+
@output_file.close
|
217
|
+
|
218
|
+
if @summary then
|
219
|
+
puts "Total number of lines read : #{no_of_lines}"
|
220
|
+
puts "Statement read errors (N-Quads or N-Triples) : #{read_errors}"
|
221
|
+
puts "Statements that are captured in JSON/JSON-LD : #{no_of_statements}"
|
222
|
+
puts "JSON/JSON-LD documents output : #{documents}"
|
223
|
+
end
|
193
224
|
end
|
194
225
|
|
195
226
|
# Minimize a JSON-LD hash to JSON.
|
@@ -224,7 +255,7 @@ class Converter
|
|
224
255
|
#
|
225
256
|
# +block+:: one or more lines that share the same subject in RDF N-Triples/N-Quads
|
226
257
|
def write_graph(block)
|
227
|
-
return { :read_errors => 0, :no_of_statements => 0 } unless block and not block.empty?
|
258
|
+
return { :read_errors => 0, :no_of_statements => 0, :documents => 0 } unless block and not block.empty?
|
228
259
|
|
229
260
|
# Virtuoso output error-handling:
|
230
261
|
block.gsub!("\\'", "'")
|
@@ -243,6 +274,7 @@ class Converter
|
|
243
274
|
end
|
244
275
|
}
|
245
276
|
|
277
|
+
documents = 0
|
246
278
|
JSON::LD::API::fromRdf(graph) { |document|
|
247
279
|
document.each{ |entity|
|
248
280
|
# Parsed JSON-LD representation:
|
@@ -252,10 +284,11 @@ class Converter
|
|
252
284
|
minify(entity) if @output_format == :json
|
253
285
|
|
254
286
|
@output_file.puts entity.to_json
|
287
|
+
documents += 1
|
255
288
|
}
|
256
289
|
}
|
257
290
|
|
258
|
-
return { :read_errors => read_errors, :no_of_statements => no_of_statements }
|
291
|
+
return { :read_errors => read_errors, :no_of_statements => no_of_statements, :documents => documents }
|
259
292
|
end
|
260
293
|
|
261
294
|
end
|
data/test/helper.rb
CHANGED
@@ -23,12 +23,25 @@ rescue Bundler::BundlerError => e
|
|
23
23
|
$stderr.puts "Run `bundle install` to install missing gems"
|
24
24
|
exit e.status_code
|
25
25
|
end
|
26
|
-
require '
|
26
|
+
require 'minitest'
|
27
|
+
require 'minitest/spec'
|
28
|
+
require 'minitest/autorun'
|
27
29
|
require 'shoulda'
|
28
30
|
|
29
31
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
30
32
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
31
|
-
require 'bio-rdf2json'
|
32
33
|
|
33
|
-
|
34
|
+
require 'coveralls'
|
35
|
+
|
36
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
37
|
+
SimpleCov.start do
|
38
|
+
add_filter 'test'
|
39
|
+
add_filter 'gems'
|
40
|
+
add_filter 'rubies'
|
41
|
+
add_group 'Converter', 'lib'
|
34
42
|
end
|
43
|
+
|
44
|
+
Coveralls.wear!
|
45
|
+
|
46
|
+
require 'rdf2json'
|
47
|
+
|
@@ -0,0 +1,224 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
# Test the RDF N-Triples/N-Quads to JSON/JSON-LD conversion.
|
6
|
+
class TestRDF2JSON < Minitest::Test
|
7
|
+
|
8
|
+
# RDF N-Triples test dataset:
|
9
|
+
@@test_ntriples = <<-EOI
|
10
|
+
<s1> <http://test/p1> <o1> .
|
11
|
+
<s1> <p2> "l1" .
|
12
|
+
<s1> <p3> <o3> .
|
13
|
+
<s1> <p3> <o4> .
|
14
|
+
<s2> <http://test/p1> <o5> .
|
15
|
+
<s2> <p4> "l2" .
|
16
|
+
EOI
|
17
|
+
|
18
|
+
# RDF N-Triples test dataset:
|
19
|
+
@@test_nquads = <<-EOI
|
20
|
+
<s1> <http://test/p1> <o1> <g1> .
|
21
|
+
<s1> <p2> "l1" <g1> .
|
22
|
+
<s1> <p3> <o3> <g1> .
|
23
|
+
<s1> <p3> <o4> <g1> .
|
24
|
+
<s2> <http://test/p1> <o5> <g2> .
|
25
|
+
<s2> <p4> "l2" <g2> .
|
26
|
+
EOI
|
27
|
+
|
28
|
+
# Dummy file path for a fake input file; command line parameter testing.
|
29
|
+
@@dummy_file = '/tmp/non_existing_file_239805167_ALHFASBIWEO.nt'
|
30
|
+
|
31
|
+
# Creates a temporary file that holds either N-Triples or N-Quads.
|
32
|
+
#
|
33
|
+
# +format+:: whether N-Triples or N-Quads should be used (:ntriples, :nquads)
|
34
|
+
def self.create_input(format)
|
35
|
+
input = Tempfile.new('rdf2json-converter-input')
|
36
|
+
if format == :ntriples then
|
37
|
+
input.puts @@test_ntriples
|
38
|
+
elsif format == :nquads then
|
39
|
+
input.puts @@test_nquads
|
40
|
+
else
|
41
|
+
raise "Passed a constant to create_input that is not understood."
|
42
|
+
end
|
43
|
+
input.close
|
44
|
+
|
45
|
+
return input
|
46
|
+
end
|
47
|
+
|
48
|
+
# Reads JSON/JSON-LD documents from a file; one document per line.
|
49
|
+
#
|
50
|
+
# +output+:: handle to the file that contains JSON/JSON-LD documents (one per line)
|
51
|
+
def self.get_json(output)
|
52
|
+
output.rewind
|
53
|
+
|
54
|
+
return output.readlines
|
55
|
+
end
|
56
|
+
|
57
|
+
# Tests whether the reference and output arrays match.
|
58
|
+
#
|
59
|
+
# +reference+:: an array of reference objects
|
60
|
+
# +output+:: an array containing the converter output objects
|
61
|
+
def self.test(reference, output)
|
62
|
+
output.length.must_equal(reference.length)
|
63
|
+
reference.each_index { |index|
|
64
|
+
output[index].must_equal(reference[index])
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
# Temporarily redirect STDOUT, so that the testing output
|
69
|
+
# does not get cluttered.
|
70
|
+
#
|
71
|
+
# +method+:: name of the class method that should be called on RDF2JSON
|
72
|
+
# +parameters+:: optional parameters for the method call
|
73
|
+
def self.silence(method, parameters = nil)
|
74
|
+
stdout, $stdout = $stdout, StringIO.new
|
75
|
+
result = RDF2JSON.send(method, *parameters)
|
76
|
+
$stdout = stdout
|
77
|
+
|
78
|
+
return result
|
79
|
+
end
|
80
|
+
|
81
|
+
# Command line parameter tests.
|
82
|
+
describe 'Command line parameters' do
|
83
|
+
it 'no input or output specified' do
|
84
|
+
TestRDF2JSON.silence('option_parser').must_equal(2)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'input file does not exist' do
|
88
|
+
argv = [ [ '--input', @@dummy_file, '--output', '/dev/null' ] ]
|
89
|
+
TestRDF2JSON.silence('option_parser', argv).must_equal(6)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'input file format cannot be determined by extension' do
|
93
|
+
argv = [ [ '--input', @@dummy_file + '.unknown', '--output', '/dev/null' ] ]
|
94
|
+
TestRDF2JSON.silence('option_parser', argv).must_equal(4)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'both RDF N-Triples and RDF N-Quads specified as input format' do
|
98
|
+
argv = [ [ '--input', @@dummy_file, '--output', '/dev/null', '--triples', '--quads' ] ]
|
99
|
+
TestRDF2JSON.silence('option_parser', argv).must_equal(3)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'help requested' do
|
103
|
+
argv = [ [ '--help' ] ]
|
104
|
+
TestRDF2JSON.silence('option_parser', argv).must_equal(0)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'nonsense parameters provided' do
|
108
|
+
argv = [ [ '--hey', '--hello', '--wassup' ] ]
|
109
|
+
TestRDF2JSON.silence('option_parser', argv).must_equal(1)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# N-Triples to JSON/JSON-LD tests.
|
114
|
+
describe 'N-Triple conversion' do
|
115
|
+
before do
|
116
|
+
@input = TestRDF2JSON.create_input(:ntriples)
|
117
|
+
@output = Tempfile.new('rdf2json-converter-output')
|
118
|
+
end
|
119
|
+
|
120
|
+
after do
|
121
|
+
@input.unlink
|
122
|
+
@output.unlink
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'input: N-Triples; output: JSON-LD' do
|
126
|
+
converter = RDF2JSON::Converter.new(@input.path, @output.path, :ntriples, :jsonld, nil, nil)
|
127
|
+
converter.convert
|
128
|
+
|
129
|
+
json = TestRDF2JSON.get_json(@output)
|
130
|
+
TestRDF2JSON.test([
|
131
|
+
'{"@id":"s1","http://test/p1":[{"@id":"o1"}],"p2":[{"@value":"l1"}],"p3":[{"@id":"o3"},{"@id":"o4"}]}' + "\n",
|
132
|
+
'{"@id":"s2","p4":[{"@value":"l2"}]}' + "\n"
|
133
|
+
],
|
134
|
+
json)
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'input: N-Triples; output: JSON (minified JSON-LD)' do
|
138
|
+
converter = RDF2JSON::Converter.new(@input.path, @output.path, :ntriples, :json, nil, nil)
|
139
|
+
converter.convert
|
140
|
+
|
141
|
+
json = TestRDF2JSON.get_json(@output)
|
142
|
+
TestRDF2JSON.test([
|
143
|
+
'{"@id":"s1","http://test/p1":["o1"],"p2":["l1"],"p3":["o3","o4"]}' + "\n",
|
144
|
+
'{"@id":"s2","p4":["l2"]}' + "\n"
|
145
|
+
],
|
146
|
+
json)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'input: N-Triples; output: JSON (minified JSON-LD); namespace: primary_key' do
|
150
|
+
converter = RDF2JSON::Converter.new(@input.path, @output.path, :ntriples, :json, 'primary_key', nil)
|
151
|
+
converter.convert
|
152
|
+
|
153
|
+
json = TestRDF2JSON.get_json(@output)
|
154
|
+
TestRDF2JSON.test([
|
155
|
+
'{"http://test/p1":["o1"],"p2":["l1"],"p3":["o3","o4"],"primary_key":"s1"}' + "\n",
|
156
|
+
'{"p4":["l2"],"primary_key":"s2"}' + "\n"
|
157
|
+
],
|
158
|
+
json)
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'input: N-Triples; output: JSON (minified JSON-LD); prefix: http://test/' do
|
162
|
+
converter = RDF2JSON::Converter.new(@input.path, @output.path, :ntriples, :json, nil, 'http://test/')
|
163
|
+
converter.convert
|
164
|
+
|
165
|
+
json = TestRDF2JSON.get_json(@output)
|
166
|
+
TestRDF2JSON.test([
|
167
|
+
'{"@id":"s1","p2":["l1"],"p3":["o3","o4"],"p1":["o1"]}' + "\n",
|
168
|
+
'{"@id":"s2","p4":["l2"]}' + "\n"
|
169
|
+
],
|
170
|
+
json)
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'input: N-Triples; output: JSON (minified JSON-LD); namespace: primary_key, prefix: http://test/' do
|
174
|
+
converter = RDF2JSON::Converter.new(@input.path, @output.path, :ntriples, :json, 'primary_key', 'http://test/')
|
175
|
+
converter.convert
|
176
|
+
|
177
|
+
json = TestRDF2JSON.get_json(@output)
|
178
|
+
TestRDF2JSON.test([
|
179
|
+
'{"p2":["l1"],"p3":["o3","o4"],"primary_key":"s1","p1":["o1"]}' + "\n",
|
180
|
+
'{"p4":["l2"],"primary_key":"s2"}' + "\n"
|
181
|
+
],
|
182
|
+
json)
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
# N-Quads to JSON/JSON-LD tests; assumes that namespace and prefix handling are not affected
|
188
|
+
# by the change of input format (hence, not tested again).
|
189
|
+
describe 'N-Quads conversion' do
|
190
|
+
before do
|
191
|
+
@input = TestRDF2JSON.create_input(:nquads)
|
192
|
+
@output = Tempfile.new('rdf2json-converter-output')
|
193
|
+
end
|
194
|
+
|
195
|
+
after do
|
196
|
+
@input.unlink
|
197
|
+
@output.unlink
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'input: N-Quads; output: JSON-LD' do
|
201
|
+
converter = RDF2JSON::Converter.new(@input.path, @output.path, :nquads, :jsonld, nil, nil)
|
202
|
+
converter.convert
|
203
|
+
|
204
|
+
json = TestRDF2JSON.get_json(@output)
|
205
|
+
TestRDF2JSON.test([
|
206
|
+
'{"@id":"s1","http://test/p1":[{"@id":"o1"}],"p2":[{"@value":"l1"}],"p3":[{"@id":"o3"},{"@id":"o4"}]}' + "\n",
|
207
|
+
'{"@id":"s2","p4":[{"@value":"l2"}]}' + "\n"
|
208
|
+
],
|
209
|
+
json)
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'input: N-Quads; output: JSON (minified JSON-LD)' do
|
213
|
+
converter = RDF2JSON::Converter.new(@input.path, @output.path, :nquads, :json, nil, nil)
|
214
|
+
converter.convert
|
215
|
+
|
216
|
+
json = TestRDF2JSON.get_json(@output)
|
217
|
+
TestRDF2JSON.test([
|
218
|
+
'{"@id":"s1","http://test/p1":["o1"],"p2":["l1"],"p3":["o3","o4"]}' + "\n",
|
219
|
+
'{"@id":"s2","p4":["l2"]}' + "\n"
|
220
|
+
],
|
221
|
+
json)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf2json
|
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
|
- Joachim Baran
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdf
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.1.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: coveralls
|
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'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 5.3.4
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 5.3.4
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: shoulda
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,7 +156,7 @@ files:
|
|
128
156
|
- lib/rdf2json.rb
|
129
157
|
- lib/rdf2json/rdf2json.rb
|
130
158
|
- test/helper.rb
|
131
|
-
- test/
|
159
|
+
- test/test_rdf2json.rb
|
132
160
|
- bin/rdf2json
|
133
161
|
homepage: http://github.com/joejimbo/rdf2json
|
134
162
|
licenses:
|
data/test/test_bio-rdf2json.rb
DELETED