lightrdf 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/lib/lightrdf/parser.rb +21 -14
- data/lib/lightrdf.rb +1 -2
- data/lightrdf.gemspec +2 -2
- data/test/test_lightrdf.rb +3 -3
- metadata +3 -3
data/History.txt
CHANGED
data/lib/lightrdf/parser.rb
CHANGED
@@ -20,28 +20,23 @@ module RDF
|
|
20
20
|
serialize_yarf(nodes, ns)
|
21
21
|
end
|
22
22
|
when :ejson
|
23
|
-
|
24
|
-
stdin.puts ActiveSupport::JSON.encode(serialize_ejson(nodes))
|
25
|
-
stdin.close
|
26
|
-
stdout.read
|
23
|
+
RDF::Parser.run "python -mjson.tool", ActiveSupport::JSON.encode(serialize_ejson(nodes))
|
27
24
|
when :png
|
28
25
|
dot = serialize(:dot)
|
29
26
|
ns = respond_to?(:ns) ? ID.ns.merge(self.ns) : ID.ns
|
30
27
|
ns.each { |k,v| dot.gsub!(v, "#{k}:") }
|
31
28
|
dot.gsub!(/label=\"\\n\\nModel:.*\)\";/, '')
|
32
|
-
|
33
|
-
|
34
|
-
stdin.close
|
35
|
-
stdout.read
|
29
|
+
|
30
|
+
RDF::Parser.run "dot -o/dev/stdout -Tpng", dot
|
36
31
|
when :rdf
|
37
32
|
serialize(:'rdfxml-abbrev')
|
38
33
|
else
|
39
34
|
namespaces = if [:rdfxml, :'rdfxml-abbrev'].include?(format)
|
40
35
|
ID.ns.map {|k,v| "-f 'xmlns:#{k}=#{v.inspect}'" } * " "
|
41
36
|
end
|
42
|
-
|
43
|
-
File.open(
|
44
|
-
%x[rapper -q -i ntriples #{namespaces} -o #{format} #{
|
37
|
+
tempfile = RDF::Parser.new_tempfile
|
38
|
+
File.open(tempfile, 'w') { |f| f.write(serialize(:ntriples)) }
|
39
|
+
%x[rapper -q -i ntriples #{namespaces} -o #{format} #{tempfile} 2> /dev/null]
|
45
40
|
end
|
46
41
|
end
|
47
42
|
|
@@ -75,9 +70,9 @@ module RDF
|
|
75
70
|
when :ejson
|
76
71
|
raise Exception, "eJSON format cannot be parsed (yet)"
|
77
72
|
else
|
78
|
-
|
79
|
-
File.open(
|
80
|
-
parse :ntriples, %x[rapper -q -i #{format} -o ntriples #{
|
73
|
+
tempfile = new_tempfile
|
74
|
+
File.open(tempfile, 'w') { |f| f.write text }
|
75
|
+
parse :ntriples, %x[rapper -q -i #{format} -o ntriples #{tempfile} 2> /dev/null]
|
81
76
|
end
|
82
77
|
end
|
83
78
|
|
@@ -219,5 +214,17 @@ module RDF
|
|
219
214
|
raise Exception, "Parsing error: #{c}"
|
220
215
|
end
|
221
216
|
end
|
217
|
+
|
218
|
+
def self.run program, input
|
219
|
+
tempfile = new_tempfile
|
220
|
+
File.open(tempfile, 'w') { |f| f.write(input) }
|
221
|
+
%x[#{program} < #{tempfile}]
|
222
|
+
end
|
223
|
+
|
224
|
+
def self.new_tempfile
|
225
|
+
@num_tempfile ||= 0
|
226
|
+
@num_tempfile += 1
|
227
|
+
File.join(Dir.tmpdir, "lightrdf-#{@num_tempfile}-#{$$}#{Thread.current.object_id}")
|
228
|
+
end
|
222
229
|
end
|
223
230
|
end
|
data/lib/lightrdf.rb
CHANGED
@@ -2,13 +2,12 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
4
|
module RDF
|
5
|
-
VERSION = '0.2.
|
5
|
+
VERSION = '0.2.2'
|
6
6
|
end
|
7
7
|
|
8
8
|
require 'rubygems'
|
9
9
|
require 'active_support'
|
10
10
|
require 'uri'
|
11
|
-
require 'open3'
|
12
11
|
require 'open-uri'
|
13
12
|
require 'tmpdir'
|
14
13
|
require 'rest-client'
|
data/lightrdf.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{lightrdf}
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Jose Ignacio"]
|
9
|
-
s.date = %q{2011-03-
|
9
|
+
s.date = %q{2011-03-10}
|
10
10
|
s.default_executable = %q{yarfp}
|
11
11
|
s.description = %q{RDF library}
|
12
12
|
s.email = %q{joseignacio.fernandez@gmail.com}
|
data/test/test_lightrdf.rb
CHANGED
@@ -94,7 +94,6 @@ class TestLightRDF < Test::Unit::TestCase
|
|
94
94
|
a = Node('ex:bob')
|
95
95
|
a.foaf::weblog = Node('http://www.awesomeweblogfordummies.com')
|
96
96
|
g = RDF::Graph.new a.triples
|
97
|
-
p a.foaf::weblog
|
98
97
|
assert g[Node('ex:bob')].foaf::weblog?(Node('http://www.awesomeweblogfordummies.com'))
|
99
98
|
end
|
100
99
|
|
@@ -159,6 +158,7 @@ foaf: http://xmlns.com/foaf/0.1/
|
|
159
158
|
g = RDF::Graph.new
|
160
159
|
g << a
|
161
160
|
|
161
|
+
g.serialize(:ejson) # Just check that parsing doesn't crash
|
162
162
|
assert_equal 3, RDF::Parser.parse(:yarf, g.serialize(:yarf) ).triples.size
|
163
163
|
assert_equal 3, RDF::Parser.parse(:rdfxml, g.serialize(:rdfxml)).triples.size
|
164
164
|
assert_equal 3, RDF::Parser.parse(:rdf, g.serialize(:rdf) ).triples.size
|
@@ -166,9 +166,9 @@ foaf: http://xmlns.com/foaf/0.1/
|
|
166
166
|
|
167
167
|
def test_repository
|
168
168
|
repository = RDF::Repository.new
|
169
|
-
triple = [
|
169
|
+
triple = [ID("http://testuri.org"), ID('rdf:type'), ID('rdf:Class')]
|
170
170
|
graph = RDF::Graph.new [triple]
|
171
|
-
context = "http://
|
171
|
+
context = "http://test_context.org"
|
172
172
|
repository.data = graph, context
|
173
173
|
|
174
174
|
# Check if the added data is there
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jose Ignacio
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-03-
|
17
|
+
date: 2011-03-10 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|