rdf-raptor 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +1 -0
- data/CONTRIBUTORS +1 -0
- data/README +11 -3
- data/VERSION +1 -1
- data/etc/doap.ttl +45 -0
- data/lib/rdf/raptor.rb +34 -30
- data/lib/rdf/raptor/cli.rb +75 -19
- data/lib/rdf/raptor/ffi.rb +334 -67
- data/lib/rdf/raptor/graphviz.rb +56 -0
- data/lib/rdf/raptor/turtle.rb +2 -1
- data/lib/rdf/raptor/version.rb +2 -3
- metadata +32 -28
data/AUTHORS
CHANGED
data/CONTRIBUTORS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* Ben Lavender <blavender@gmail.com>
|
data/README
CHANGED
@@ -2,11 +2,11 @@ Raptor RDF Parser Wrapper for RDF.rb
|
|
2
2
|
====================================
|
3
3
|
|
4
4
|
This is an [RDF.rb][] plugin that adds support for parsing/serializing
|
5
|
-
[RDF/XML][] and [
|
5
|
+
[RDF/XML][], [Turtle][] and [RDFa][] data using the [Raptor RDF Parser][Raptor]
|
6
6
|
library.
|
7
7
|
|
8
8
|
* <http://github.com/bendiken/rdf-raptor>
|
9
|
-
* <http://
|
9
|
+
* <http://blog.datagraph.org/2010/04/parsing-rdf-with-ruby>
|
10
10
|
|
11
11
|
Features
|
12
12
|
--------
|
@@ -106,11 +106,12 @@ Documentation
|
|
106
106
|
* {RDF::Raptor::RDFXML}
|
107
107
|
* {RDF::Raptor::Turtle}
|
108
108
|
* {RDF::Raptor::RDFa}
|
109
|
+
* {RDF::Raptor::Graphviz}
|
109
110
|
|
110
111
|
Dependencies
|
111
112
|
------------
|
112
113
|
|
113
|
-
* [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.
|
114
|
+
* [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.2.0)
|
114
115
|
* [Raptor][] (>= 1.4.16), specifically the `rapper` binary
|
115
116
|
|
116
117
|
Installation
|
@@ -152,6 +153,12 @@ Author
|
|
152
153
|
------
|
153
154
|
|
154
155
|
* [Arto Bendiken](mailto:arto.bendiken@gmail.com) - <http://ar.to/>
|
156
|
+
* [John Fieber](mailto:jrf@ursamaris.org) - <http://github.com/jfieber>
|
157
|
+
|
158
|
+
Contributors
|
159
|
+
------------
|
160
|
+
|
161
|
+
* [Ben Lavender](mailto:blavender@gmail.com) - <http://bhuga.net/>
|
155
162
|
|
156
163
|
License
|
157
164
|
-------
|
@@ -162,5 +169,6 @@ information, see <http://unlicense.org/> or the accompanying UNLICENSE file.
|
|
162
169
|
[RDF.rb]: http://rdf.rubyforge.org/
|
163
170
|
[RDF/XML]: http://www.w3.org/TR/REC-rdf-syntax/
|
164
171
|
[Turtle]: http://en.wikipedia.org/wiki/Turtle_(syntax)
|
172
|
+
[RDFa]: http://rdfa.info/
|
165
173
|
[Raptor]: http://librdf.org/raptor/
|
166
174
|
[rapper]: http://librdf.org/raptor/rapper.html
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/etc/doap.ttl
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
@base <http://rubygems.org/gems/rdf-json> .
|
2
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
3
|
+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
4
|
+
@prefix dc: <http://purl.org/dc/terms/> .
|
5
|
+
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
|
6
|
+
@prefix doap: <http://usefulinc.com/ns/doap#> .
|
7
|
+
|
8
|
+
<> a doap:Project ;
|
9
|
+
doap:name "RDF::Raptor" ;
|
10
|
+
doap:homepage <http://rdf.rubyforge.org/raptor/> ;
|
11
|
+
doap:license <http://creativecommons.org/licenses/publicdomain/> ;
|
12
|
+
doap:shortdesc "Raptor RDF Parser wrapper for RDF.rb."@en ;
|
13
|
+
doap:description "RDF.rb plugin for parsing/serializing RDF/XML, Turtle and RDFa data using the Raptor RDF Parser library."@en ;
|
14
|
+
doap:created "2010-03-23" ;
|
15
|
+
doap:platform "Ruby" ;
|
16
|
+
doap:download-page <http://rubyforge.org/projects/rdf/> ;
|
17
|
+
doap:bug-database <http://github.com/bendiken/rdf-raptor/issues> ;
|
18
|
+
doap:blog <http://ar.to/>, <http://blog.datagraph.org/> ;
|
19
|
+
doap:developer <http://ar.to/#self>, _:jfieber ;
|
20
|
+
doap:maintainer <http://ar.to/#self> ;
|
21
|
+
doap:documenter <http://ar.to/#self> ;
|
22
|
+
doap:helper <http://bhuga.net/#ben> ;
|
23
|
+
foaf:maker <http://ar.to/#self> ;
|
24
|
+
dc:creator <http://ar.to/#self> .
|
25
|
+
|
26
|
+
<http://ar.to/#self> a foaf:Person ;
|
27
|
+
foaf:name "Arto Bendiken" ;
|
28
|
+
foaf:mbox <mailto:arto.bendiken@gmail.com> ;
|
29
|
+
foaf:mbox_sha1sum "d0737cceb55eb7d740578d2db1bc0727e3ed49ce",
|
30
|
+
"a033f652c84a4d73b8c26d318c2395699dd2bdfb" ;
|
31
|
+
foaf:homepage <http://ar.to/> ;
|
32
|
+
rdfs:isDefinedBy <http://datagraph.org/bendiken/foaf> .
|
33
|
+
|
34
|
+
<http://bhuga.net/#ben> a foaf:Person ;
|
35
|
+
foaf:name "Ben Lavender" ;
|
36
|
+
foaf:mbox <mailto:blavender@gmail.com> ;
|
37
|
+
foaf:mbox_sha1sum "dbf45f4ffbd27b67aa84f02a6a31c144727d10af" ;
|
38
|
+
foaf:homepage <http://bhuga.net/> ;
|
39
|
+
rdfs:isDefinedBy <http://datagraph.org/bhuga/foaf> .
|
40
|
+
|
41
|
+
_:jfieber a foaf:Person ;
|
42
|
+
foaf:name "John Fieber" ;
|
43
|
+
foaf:mbox <mailto:jrf@ursamaris.org> ;
|
44
|
+
foaf:mbox_sha1sum "f7653fc1ac0e82ebb32f092389bd5fc728eaae12" ;
|
45
|
+
foaf:homepage <http://ursamaris.org/> .
|
data/lib/rdf/raptor.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'tempfile'
|
1
2
|
require 'rdf'
|
2
3
|
|
3
4
|
module RDF
|
@@ -10,6 +11,8 @@ module RDF
|
|
10
11
|
# human-readable Turtle format.
|
11
12
|
# * {RDF::Raptor::RDFa} provides support for extracting
|
12
13
|
# RDF statements from XHTML+RDFa documents.
|
14
|
+
# * {RDF::Raptor::Graphviz} provides support for serializing
|
15
|
+
# RDF statements to the Graphviz DOT format.
|
13
16
|
#
|
14
17
|
# @example Requiring the `RDF::Raptor` module
|
15
18
|
# require 'rdf/raptor'
|
@@ -20,6 +23,9 @@ module RDF
|
|
20
23
|
# @example Obtaining the Raptor version number
|
21
24
|
# RDF::Raptor.version #=> "1.4.21"
|
22
25
|
#
|
26
|
+
# @example Obtaining the Raptor engine
|
27
|
+
# RDF::Raptor::ENGINE #=> :ffi
|
28
|
+
#
|
23
29
|
# @example Obtaining an RDF/XML format class
|
24
30
|
# RDF::Format.for(:rdfxml) #=> RDF::Raptor::RDFXML::Format
|
25
31
|
# RDF::Format.for("input.rdf")
|
@@ -41,18 +47,42 @@ module RDF
|
|
41
47
|
# RDF::Format.for(:file_extension => "html")
|
42
48
|
# RDF::Format.for(:content_type => "application/xhtml+xml")
|
43
49
|
#
|
50
|
+
# {RDF::Raptor} includes an ffi implementation, which loads
|
51
|
+
# the libraptor library into the ruby process, and a cli
|
52
|
+
# implementation, which uses the rapper command line tool
|
53
|
+
# in a subprocess. The ffi implementation is used unless
|
54
|
+
# libraptor library is not found, or the RDF_RAPTOR_ENGINE
|
55
|
+
# environment variable is set to 'cli'.
|
56
|
+
#
|
57
|
+
# If the libraptor library is in the standard library search
|
58
|
+
# path, and the rapper command is in the standard command
|
59
|
+
# search path, all should be well. If either is in a
|
60
|
+
# non-standard location, set the RDF_RAPTOR_LIBPATH and/or
|
61
|
+
# RDF_RAPTOR_BINPATH appropriately before requiring rdf/raptor.
|
62
|
+
#
|
44
63
|
# @see http://rdf.rubyforge.org/
|
45
64
|
# @see http://librdf.org/raptor/
|
65
|
+
# @see http://wiki.github.com/ffi/ffi/
|
46
66
|
#
|
47
67
|
# @author [Arto Bendiken](http://ar.to/)
|
68
|
+
# @author [John Fieber](http://github.com/jfieber)
|
48
69
|
module Raptor
|
49
|
-
ENGINE = (ENV['RDF_RAPTOR_ENGINE'] || :cli).to_sym unless const_defined?(:ENGINE)
|
50
70
|
LIBRAPTOR = ENV['RDF_RAPTOR_LIBPATH'] || 'libraptor' unless const_defined?(:LIBRAPTOR)
|
51
71
|
RAPPER = ENV['RDF_RAPTOR_BINPATH'] || 'rapper' unless const_defined?(:RAPPER)
|
52
72
|
|
53
73
|
require 'rdf/raptor/version'
|
54
|
-
|
55
|
-
|
74
|
+
begin
|
75
|
+
# Try ffi implementation
|
76
|
+
raise LoadError if ENV['RDF_RAPTOR_ENGINE'] == 'cli' # override
|
77
|
+
require 'rdf/raptor/ffi'
|
78
|
+
include RDF::Raptor::FFI
|
79
|
+
extend RDF::Raptor::FFI
|
80
|
+
rescue LoadError => e
|
81
|
+
# cli fallback
|
82
|
+
require 'rdf/raptor/cli'
|
83
|
+
include RDF::Raptor::CLI
|
84
|
+
extend RDF::Raptor::CLI
|
85
|
+
end
|
56
86
|
|
57
87
|
##
|
58
88
|
# Returns `true` if the `rapper` binary is available.
|
@@ -65,20 +95,6 @@ module RDF
|
|
65
95
|
!!version
|
66
96
|
end
|
67
97
|
|
68
|
-
##
|
69
|
-
# Returns the installed `rapper` version number, or `nil` if `rapper` is
|
70
|
-
# not available.
|
71
|
-
#
|
72
|
-
# @example
|
73
|
-
# RDF::Raptor.version #=> "1.4.21"
|
74
|
-
#
|
75
|
-
# @return [String]
|
76
|
-
def self.version
|
77
|
-
if `#{RAPPER} --version 2>/dev/null` =~ /^(\d+)\.(\d+)\.(\d+)/
|
78
|
-
[$1, $2, $3].join('.')
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
98
|
##
|
83
99
|
# Format base class.
|
84
100
|
class Format < RDF::Format
|
@@ -98,21 +114,9 @@ module RDF
|
|
98
114
|
end
|
99
115
|
end
|
100
116
|
|
101
|
-
##
|
102
|
-
# Reader base class.
|
103
|
-
class Reader < RDF::Reader
|
104
|
-
include RDF::Raptor::CLI::Reader if ENGINE == :cli
|
105
|
-
include RDF::Raptor::FFI::Reader if ENGINE == :ffi
|
106
|
-
end
|
107
|
-
|
108
|
-
##
|
109
|
-
# Writer base class.
|
110
|
-
class Writer < RDF::Writer
|
111
|
-
include RDF::Raptor::CLI::Writer
|
112
|
-
end
|
113
|
-
|
114
117
|
require 'rdf/raptor/rdfxml'
|
115
118
|
require 'rdf/raptor/turtle'
|
116
119
|
require 'rdf/raptor/rdfa'
|
120
|
+
require 'rdf/raptor/graphviz'
|
117
121
|
end # module Raptor
|
118
122
|
end # module RDF
|
data/lib/rdf/raptor/cli.rb
CHANGED
@@ -2,9 +2,26 @@ module RDF::Raptor
|
|
2
2
|
##
|
3
3
|
# A command-line interface to Raptor's `rapper` utility.
|
4
4
|
module CLI
|
5
|
+
|
6
|
+
ENGINE = :cli
|
7
|
+
|
8
|
+
##
|
9
|
+
# Returns the installed `rapper` version number, or `nil` if `rapper` is
|
10
|
+
# not available.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# RDF::Raptor.version #=> "1.4.21"
|
14
|
+
#
|
15
|
+
# @return [String]
|
16
|
+
def version
|
17
|
+
if `#{RAPPER} --version 2>/dev/null` =~ /^(\d+)\.(\d+)\.(\d+)/
|
18
|
+
[$1, $2, $3].join('.')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
5
22
|
##
|
6
23
|
# Reader implementation.
|
7
|
-
|
24
|
+
class Reader < RDF::Reader
|
8
25
|
##
|
9
26
|
# @param [IO, File, RDF::URI, String] input
|
10
27
|
# @param [Hash{Symbol => Object}] options
|
@@ -17,18 +34,35 @@ module RDF::Raptor
|
|
17
34
|
format = self.class.format.rapper_format
|
18
35
|
case input
|
19
36
|
when RDF::URI, %r(^(file|http|https|ftp)://)
|
20
|
-
@command = "#{RAPPER} -q -i #{format} -o ntriples #{input}"
|
21
|
-
@command << " #{options[:base_uri]}" if options.has_key?(:base_uri)
|
37
|
+
@command = "#{RAPPER} -q -i #{format} -o ntriples '#{input}'"
|
38
|
+
@command << " '#{options[:base_uri]}'" if options.has_key?(:base_uri)
|
22
39
|
@rapper = IO.popen(@command, 'rb')
|
23
|
-
when File
|
24
|
-
@command = "#{RAPPER} -q -i #{format} -o ntriples #{File.expand_path(input.path)}"
|
25
|
-
@command << " #{options[:base_uri]}" if options.has_key?(:base_uri)
|
40
|
+
when File, Tempfile
|
41
|
+
@command = "#{RAPPER} -q -i #{format} -o ntriples '#{File.expand_path(input.path)}'"
|
42
|
+
@command << " '#{options[:base_uri]}'" if options.has_key?(:base_uri)
|
26
43
|
@rapper = IO.popen(@command, 'rb')
|
27
44
|
else # IO, String
|
28
45
|
@command = "#{RAPPER} -q -i #{format} -o ntriples file:///dev/stdin"
|
29
|
-
@command << " #{options[:base_uri]}" if options.has_key?(:base_uri)
|
46
|
+
@command << " '#{options[:base_uri]}'" if options.has_key?(:base_uri)
|
30
47
|
@rapper = IO.popen(@command, 'rb+')
|
31
|
-
|
48
|
+
pid = fork do
|
49
|
+
# process to feed rapper
|
50
|
+
begin
|
51
|
+
@rapper.close_read
|
52
|
+
if input.respond_to?(:read)
|
53
|
+
buf = String.new
|
54
|
+
while input.read(8192, buf)
|
55
|
+
@rapper.write(buf)
|
56
|
+
end
|
57
|
+
else
|
58
|
+
@rapper.write(input.to_s)
|
59
|
+
end
|
60
|
+
@rapper.close_write
|
61
|
+
ensure
|
62
|
+
Process.exit
|
63
|
+
end
|
64
|
+
end
|
65
|
+
Process.detach(pid)
|
32
66
|
@rapper.close_write
|
33
67
|
end
|
34
68
|
@reader = RDF::NTriples::Reader.new(@rapper, options, &block)
|
@@ -39,13 +73,21 @@ module RDF::Raptor
|
|
39
73
|
##
|
40
74
|
# @return [Array]
|
41
75
|
def read_triple
|
42
|
-
@
|
76
|
+
raise EOFError if @rapper.closed?
|
77
|
+
begin
|
78
|
+
triple = @reader.read_triple
|
79
|
+
rescue EOFError
|
80
|
+
@rapper.close
|
81
|
+
raise
|
82
|
+
end
|
83
|
+
triple
|
43
84
|
end
|
85
|
+
|
44
86
|
end
|
45
87
|
|
46
88
|
##
|
47
89
|
# Writer implementation.
|
48
|
-
|
90
|
+
class Writer < RDF::Writer
|
49
91
|
##
|
50
92
|
# @param [IO, File] output
|
51
93
|
# @param [Hash{Symbol => Object}] options
|
@@ -56,9 +98,9 @@ module RDF::Raptor
|
|
56
98
|
|
57
99
|
format = self.class.format.rapper_format
|
58
100
|
case output
|
59
|
-
when File, IO, StringIO
|
60
|
-
@command = "#{RAPPER} -q -i
|
61
|
-
@command << " #{options[:base_uri]}" if options.has_key?(:base_uri)
|
101
|
+
when File, IO, StringIO, Tempfile
|
102
|
+
@command = "#{RAPPER} -q -i turtle -o #{format} file:///dev/stdin"
|
103
|
+
@command << " '#{options[:base_uri]}'" if options.has_key?(:base_uri)
|
62
104
|
@rapper = IO.popen(@command, 'rb+')
|
63
105
|
else
|
64
106
|
raise ArgumentError.new("unsupported output type: #{output.inspect}")
|
@@ -81,22 +123,36 @@ module RDF::Raptor
|
|
81
123
|
# @param [RDF::Value] object
|
82
124
|
# @return [void]
|
83
125
|
def write_triple(subject, predicate, object)
|
126
|
+
output_transit(false)
|
84
127
|
@writer.write_triple(subject, predicate, object)
|
128
|
+
output_transit(false)
|
85
129
|
end
|
86
130
|
|
87
131
|
##
|
88
132
|
# @return [void]
|
89
133
|
def write_epilogue
|
90
|
-
@rapper.close_write
|
91
|
-
|
134
|
+
@rapper.close_write unless @rapper.closed?
|
135
|
+
output_transit(true)
|
136
|
+
end
|
137
|
+
|
138
|
+
##
|
139
|
+
# Feed any available rapper output to the destination.
|
140
|
+
# @return [void]
|
141
|
+
def output_transit(block)
|
142
|
+
unless @rapper.closed?
|
92
143
|
chunk_size = @options[:chunk_size] || 4096 # bytes
|
93
|
-
|
94
|
-
|
144
|
+
begin
|
145
|
+
loop do
|
146
|
+
@output.write(block ? @rapper.readpartial(chunk_size) : @rapper.read_nonblock(chunk_size))
|
147
|
+
end
|
148
|
+
rescue EOFError => e
|
149
|
+
@rapper.close
|
150
|
+
rescue Errno::EAGAIN, Errno::EINTR
|
151
|
+
# eat
|
95
152
|
end
|
96
|
-
rescue EOFError => e
|
97
|
-
# we're all done
|
98
153
|
end
|
99
154
|
end
|
155
|
+
|
100
156
|
end
|
101
157
|
end
|
102
158
|
end
|
data/lib/rdf/raptor/ffi.rb
CHANGED
@@ -7,9 +7,26 @@ module RDF::Raptor
|
|
7
7
|
# @see http://librdf.org/raptor/api/
|
8
8
|
# @see http://librdf.org/raptor/libraptor.html
|
9
9
|
module FFI
|
10
|
+
|
11
|
+
ENGINE = :ffi
|
12
|
+
|
13
|
+
##
|
14
|
+
# Returns the installed `rapper` version number, or `nil` if `rapper` is
|
15
|
+
# not available.
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
# RDF::Raptor.version #=> "1.4.21"
|
19
|
+
#
|
20
|
+
# @return [String]
|
21
|
+
def version
|
22
|
+
[ V1_4.raptor_version_major,
|
23
|
+
V1_4.raptor_version_minor,
|
24
|
+
V1_4.raptor_version_release ].join('.')
|
25
|
+
end
|
26
|
+
|
10
27
|
##
|
11
28
|
# Reader implementation.
|
12
|
-
|
29
|
+
class Reader < RDF::Reader
|
13
30
|
##
|
14
31
|
# @param [IO, File, RDF::URI, String] input
|
15
32
|
# @param [Hash{Symbol => Object}] options
|
@@ -21,6 +38,17 @@ module RDF::Raptor
|
|
21
38
|
super
|
22
39
|
end
|
23
40
|
|
41
|
+
ERROR_HANDLER = Proc.new do |user_data, locator, message|
|
42
|
+
line = V1_4.raptor_locator_line(locator)
|
43
|
+
raise RDF::ReaderError, line > -1 ? "Line #{line}: #{message}" : message
|
44
|
+
end
|
45
|
+
|
46
|
+
WARNING_HANDLER = Proc.new do |user_data, locator, message|
|
47
|
+
# line = V1_4.raptor_locator_line(locator)
|
48
|
+
# $stderr.puts line > -1 ? "Line #{line}: #{message}" : message
|
49
|
+
end
|
50
|
+
|
51
|
+
|
24
52
|
##
|
25
53
|
# @yield [statement]
|
26
54
|
# @yieldparam [RDF::Statement] statement
|
@@ -34,59 +62,130 @@ module RDF::Raptor
|
|
34
62
|
# @yield [triple]
|
35
63
|
# @yieldparam [Array(RDF::Resource, RDF::URI, RDF::Value)] triple
|
36
64
|
def each_triple(&block)
|
37
|
-
|
65
|
+
statement_handler = Proc.new do |user_data, statement|
|
38
66
|
triple = V1_4::Statement.new(statement).to_triple
|
39
67
|
block.call(triple)
|
40
68
|
end
|
41
69
|
|
42
|
-
V1_4.
|
43
|
-
V1_4.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
ensure
|
54
|
-
V1_4.raptor_free_uri(base_uri) if base_uri
|
55
|
-
V1_4.raptor_free_uri(data_url) if data_url
|
56
|
-
end
|
57
|
-
|
58
|
-
when File
|
59
|
-
begin
|
60
|
-
data_url = V1_4.raptor_new_uri("file://#{File.expand_path(@input.path)}")
|
61
|
-
base_uri = @options.has_key?(:base_uri) ? V1_4.raptor_new_uri(@options[:base_uri].to_s) : nil
|
62
|
-
unless (result = V1_4.raptor_parse_file(parser, data_url, base_uri)).zero?
|
63
|
-
# TODO: error handling
|
64
|
-
end
|
65
|
-
ensure
|
66
|
-
V1_4.raptor_free_uri(base_uri) if base_uri
|
67
|
-
V1_4.raptor_free_uri(data_url) if data_url
|
68
|
-
end
|
69
|
-
|
70
|
-
else # IO, String
|
71
|
-
base_uri = (@options[:base_uri] || 'file:///dev/stdin').to_s
|
72
|
-
unless (result = V1_4.raptor_start_parse(parser, base_uri)).zero?
|
70
|
+
V1_4.with_parser(:name => @format) do |parser|
|
71
|
+
V1_4.raptor_set_error_handler(parser, nil, ERROR_HANDLER)
|
72
|
+
V1_4.raptor_set_warning_handler(parser, nil, WARNING_HANDLER)
|
73
|
+
V1_4.raptor_set_statement_handler(parser, nil, statement_handler)
|
74
|
+
case @input
|
75
|
+
when RDF::URI, %r(^(file|http|https|ftp)://)
|
76
|
+
begin
|
77
|
+
data_url = V1_4.raptor_new_uri(@input.to_s)
|
78
|
+
base_uri = @options[:base_uri].to_s.empty? ? nil : V1_4.raptor_new_uri(@options[:base_uri].to_s)
|
79
|
+
unless (result = V1_4.raptor_parse_uri(parser, data_url, base_uri)).zero?
|
73
80
|
# TODO: error handling
|
74
81
|
end
|
75
|
-
|
76
|
-
|
82
|
+
ensure
|
83
|
+
V1_4.raptor_free_uri(base_uri) if base_uri
|
84
|
+
V1_4.raptor_free_uri(data_url) if data_url
|
85
|
+
end
|
86
|
+
|
87
|
+
when File, Tempfile
|
88
|
+
begin
|
89
|
+
data_url = V1_4.raptor_new_uri("file://#{File.expand_path(@input.path)}")
|
90
|
+
base_uri = @options[:base_uri].to_s.empty? ? nil : V1_4.raptor_new_uri(@options[:base_uri].to_s)
|
91
|
+
unless (result = V1_4.raptor_parse_file(parser, data_url, base_uri)).zero?
|
77
92
|
# TODO: error handling
|
78
93
|
end
|
79
|
-
|
80
|
-
|
94
|
+
ensure
|
95
|
+
V1_4.raptor_free_uri(base_uri) if base_uri
|
96
|
+
V1_4.raptor_free_uri(data_url) if data_url
|
97
|
+
end
|
98
|
+
|
99
|
+
else # IO, String
|
100
|
+
base_uri = (@options[:base_uri] || 'file:///dev/stdin').to_s
|
101
|
+
unless (result = V1_4.raptor_start_parse(parser, base_uri)).zero?
|
102
|
+
# TODO: error handling
|
103
|
+
end
|
104
|
+
# TODO: read in chunks instead of everything in one go:
|
105
|
+
unless (result = V1_4.raptor_parse_chunk(parser, buffer = @input.read, buffer.size, 0)).zero?
|
106
|
+
# TODO: error handling
|
107
|
+
end
|
108
|
+
V1_4.raptor_parse_chunk(parser, nil, 0, 1) # EOF
|
81
109
|
end
|
82
110
|
end
|
83
111
|
|
84
|
-
@parser = nil
|
85
112
|
end
|
86
113
|
|
87
114
|
alias_method :each, :each_statement
|
88
115
|
end
|
89
116
|
|
117
|
+
##
|
118
|
+
# Writer implementation.
|
119
|
+
class Writer < RDF::Writer
|
120
|
+
|
121
|
+
ERROR_HANDLER = Proc.new do |user_data, locator, message|
|
122
|
+
raise RDF::WriterError, message
|
123
|
+
end
|
124
|
+
|
125
|
+
WARNING_HANDLER = Proc.new do |user_data, locator, message|
|
126
|
+
# $stderr.puts "warning"
|
127
|
+
end
|
128
|
+
|
129
|
+
def initialize(output = $stdout, options = {}, &block)
|
130
|
+
raise ArgumentError, "Block required" unless block_given? # Can we work without this?
|
131
|
+
@format = self.class.format.rapper_format
|
132
|
+
begin
|
133
|
+
# make a serializer
|
134
|
+
@serializer = V1_4.raptor_new_serializer((@format || :rdfxml).to_s)
|
135
|
+
raise RDF::WriterError, "raptor_new_serializer failed" if @serializer.nil?
|
136
|
+
V1_4.raptor_serializer_set_error_handler(@serializer, nil, ERROR_HANDLER)
|
137
|
+
V1_4.raptor_serializer_set_warning_handler(@serializer, nil, WARNING_HANDLER)
|
138
|
+
base_uri = options[:base_uri].to_s.empty? ? nil : V1_4.raptor_new_uri(options[:base_uri].to_s)
|
139
|
+
|
140
|
+
# make an iostream
|
141
|
+
handler = V1_4::IOStreamHandler.new
|
142
|
+
handler.rubyio = output
|
143
|
+
raptor_iostream = V1_4.raptor_new_iostream_from_handler2(nil, handler)
|
144
|
+
|
145
|
+
# connect the two
|
146
|
+
unless V1_4.raptor_serialize_start_to_iostream(@serializer, base_uri, raptor_iostream).zero?
|
147
|
+
raise RDF::WriterError, "raptor_serialize_start_to_iostream failed"
|
148
|
+
end
|
149
|
+
super
|
150
|
+
ensure
|
151
|
+
V1_4.raptor_free_iostream(raptor_iostream) if raptor_iostream
|
152
|
+
V1_4.raptor_free_uri(base_uri) if base_uri
|
153
|
+
V1_4.raptor_free_serializer(@serializer) if @serializer
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
##
|
158
|
+
# @param [RDF::Resource] subject
|
159
|
+
# @param [RDF::URI] predicate
|
160
|
+
# @param [RDF::Value] object
|
161
|
+
# @return [void]
|
162
|
+
def write_triple(subject, predicate, object)
|
163
|
+
raptor_statement = V1_4::Statement.new
|
164
|
+
raptor_statement.subject = subject
|
165
|
+
raptor_statement.predicate = predicate
|
166
|
+
raptor_statement.object = object
|
167
|
+
begin
|
168
|
+
unless V1_4.raptor_serialize_statement(@serializer, raptor_statement.to_ptr).zero?
|
169
|
+
raise RDF::WriterError, "raptor_serialize_statement failed"
|
170
|
+
end
|
171
|
+
ensure
|
172
|
+
raptor_statement.release
|
173
|
+
raptor_statement = nil
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
##
|
178
|
+
# @return [void]
|
179
|
+
def write_epilogue
|
180
|
+
unless V1_4.raptor_serialize_end(@serializer).zero?
|
181
|
+
raise RDF::WriterError, "raptor_serialize_end failed"
|
182
|
+
end
|
183
|
+
super
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
|
90
189
|
##
|
91
190
|
# Helper methods for FFI modules.
|
92
191
|
module Base
|
@@ -100,23 +199,6 @@ module RDF::Raptor
|
|
100
199
|
#
|
101
200
|
# @see http://librdf.org/raptor/libraptor.html
|
102
201
|
module V1_4
|
103
|
-
##
|
104
|
-
# @param [Hash{Symbol => Object}] options
|
105
|
-
# @option (options) [Boolean] :init (true)
|
106
|
-
# @yield [world]
|
107
|
-
# @yieldparam [FFI::Pointer] world
|
108
|
-
# @return [void]
|
109
|
-
def self.with_world(options = {}, &block)
|
110
|
-
options = {:init => true}.merge(options)
|
111
|
-
begin
|
112
|
-
raptor_init if options[:init]
|
113
|
-
raptor_world_open(world = raptor_new_world)
|
114
|
-
block.call(world)
|
115
|
-
ensure
|
116
|
-
raptor_free_world(world) if world
|
117
|
-
raptor_finish if options[:init]
|
118
|
-
end
|
119
|
-
end
|
120
202
|
|
121
203
|
##
|
122
204
|
# @param [Hash{Symbol => Object}] options
|
@@ -133,6 +215,7 @@ module RDF::Raptor
|
|
133
215
|
end
|
134
216
|
end
|
135
217
|
|
218
|
+
|
136
219
|
extend Base
|
137
220
|
extend ::FFI::Library
|
138
221
|
ffi_lib LIBRAPTOR
|
@@ -153,19 +236,62 @@ module RDF::Raptor
|
|
153
236
|
:object, :pointer,
|
154
237
|
:object_type, :int,
|
155
238
|
:object_literal_datatype, :pointer,
|
156
|
-
:object_literal_language, :
|
239
|
+
:object_literal_language, :pointer
|
240
|
+
|
241
|
+
def initialize(*args)
|
242
|
+
super
|
243
|
+
# Objects we need to keep a Ruby reference
|
244
|
+
# to so they don't get garbage collected out from under
|
245
|
+
# the C code we pass them to.
|
246
|
+
@mp = {}
|
247
|
+
|
248
|
+
# Raptor object references we we need to explicitly free
|
249
|
+
# when release is called
|
250
|
+
@raptor_uri_list = []
|
251
|
+
end
|
252
|
+
|
253
|
+
##
|
254
|
+
# Release raptor memory associated with this struct.
|
255
|
+
# Use of the object after calling this will most likely
|
256
|
+
# cause a crash. This is kind of ugly.
|
257
|
+
def release
|
258
|
+
if pointer.kind_of?(::FFI::MemoryPointer) && !pointer.null?
|
259
|
+
pointer.free
|
260
|
+
end
|
261
|
+
while uri = @raptor_uri_list.pop
|
262
|
+
V1_4.raptor_free_uri(uri) unless uri.nil? || uri.null?
|
263
|
+
end
|
264
|
+
end
|
157
265
|
|
158
266
|
##
|
159
267
|
# @return [RDF::Resource]
|
160
268
|
def subject
|
161
269
|
@subject ||= case self[:subject_type]
|
162
270
|
when RAPTOR_IDENTIFIER_TYPE_RESOURCE
|
163
|
-
RDF::URI.
|
271
|
+
RDF::URI.intern(V1_4.raptor_uri_to_string(self[:subject]))
|
164
272
|
when RAPTOR_IDENTIFIER_TYPE_ANONYMOUS
|
165
273
|
RDF::Node.new(self[:subject].read_string)
|
166
274
|
end
|
167
275
|
end
|
168
276
|
|
277
|
+
##
|
278
|
+
# Set the subject from an RDF::Resource
|
279
|
+
# @param [RDF::Resource] value
|
280
|
+
def subject=(resource)
|
281
|
+
@subject = nil
|
282
|
+
case resource
|
283
|
+
when RDF::Node
|
284
|
+
self[:subject] = @mp[:subject] = ::FFI::MemoryPointer.from_string(resource.id.to_s)
|
285
|
+
self[:subject_type] = RAPTOR_IDENTIFIER_TYPE_ANONYMOUS
|
286
|
+
when RDF::URI
|
287
|
+
self[:subject] = @mp[:subject] = @raptor_uri_list.push(V1_4.raptor_new_uri(resource.to_s)).last
|
288
|
+
self[:subject_type] = RAPTOR_IDENTIFIER_TYPE_RESOURCE
|
289
|
+
else
|
290
|
+
raise ArgumentError, "subject must be of kind RDF::Node or RDF::URI"
|
291
|
+
end
|
292
|
+
@subject = resource
|
293
|
+
end
|
294
|
+
|
169
295
|
##
|
170
296
|
# @return [String]
|
171
297
|
def subject_as_string
|
@@ -180,10 +306,21 @@ module RDF::Raptor
|
|
180
306
|
def predicate
|
181
307
|
@predicate ||= case self[:predicate_type]
|
182
308
|
when RAPTOR_IDENTIFIER_TYPE_RESOURCE
|
183
|
-
RDF::URI.
|
309
|
+
RDF::URI.intern(V1_4.raptor_uri_to_string(self[:predicate]))
|
184
310
|
end
|
185
311
|
end
|
186
312
|
|
313
|
+
##
|
314
|
+
# Set the predicate from an RDF::URI
|
315
|
+
# @param [RDF::URI] value
|
316
|
+
def predicate=(uri)
|
317
|
+
@predicate = nil
|
318
|
+
raise ArgumentError, "predicate must be a kind of RDF::URI" unless uri.kind_of?(RDF::URI)
|
319
|
+
self[:predicate] = @raptor_uri_list.push(V1_4.raptor_new_uri(uri.to_s)).last
|
320
|
+
self[:predicate_type] = RAPTOR_IDENTIFIER_TYPE_RESOURCE
|
321
|
+
@predicate = uri
|
322
|
+
end
|
323
|
+
|
187
324
|
##
|
188
325
|
# @return [String]
|
189
326
|
def predicate_as_string
|
@@ -198,13 +335,13 @@ module RDF::Raptor
|
|
198
335
|
def object
|
199
336
|
@object ||= case self[:object_type]
|
200
337
|
when RAPTOR_IDENTIFIER_TYPE_RESOURCE
|
201
|
-
RDF::URI.
|
338
|
+
RDF::URI.intern(V1_4.raptor_uri_to_string(self[:object]))
|
202
339
|
when RAPTOR_IDENTIFIER_TYPE_ANONYMOUS
|
203
340
|
RDF::Node.new(self[:object].read_string)
|
204
341
|
when RAPTOR_IDENTIFIER_TYPE_LITERAL
|
205
342
|
case
|
206
|
-
when self[:object_literal_language]
|
207
|
-
RDF::Literal.new(self[:object].read_string, :language => self[:object_literal_language])
|
343
|
+
when self[:object_literal_language] && !self[:object_literal_language].null?
|
344
|
+
RDF::Literal.new(self[:object].read_string, :language => self[:object_literal_language].read_string)
|
208
345
|
when self[:object_literal_datatype] && !self[:object_literal_datatype].null?
|
209
346
|
RDF::Literal.new(self[:object].read_string, :datatype => V1_4.raptor_uri_to_string(self[:object_literal_datatype]))
|
210
347
|
else
|
@@ -213,6 +350,38 @@ module RDF::Raptor
|
|
213
350
|
end
|
214
351
|
end
|
215
352
|
|
353
|
+
##
|
354
|
+
# Set the object from an RDF::Value.
|
355
|
+
# Value must be one of RDF::Resource or RDF::Literal.
|
356
|
+
# @param [RDF::Value] value
|
357
|
+
def object=(value)
|
358
|
+
@object = nil
|
359
|
+
case value
|
360
|
+
when RDF::Node
|
361
|
+
self[:object] = @mp[:object] = ::FFI::MemoryPointer.from_string(value.id.to_s)
|
362
|
+
self[:object_type] = RAPTOR_IDENTIFIER_TYPE_ANONYMOUS
|
363
|
+
when RDF::URI
|
364
|
+
self[:object] = @mp[:object] = @raptor_uri_list.push(V1_4.raptor_new_uri(value.to_s)).last
|
365
|
+
self[:object_type] = RAPTOR_IDENTIFIER_TYPE_RESOURCE
|
366
|
+
when RDF::Literal
|
367
|
+
self[:object_type] = RAPTOR_IDENTIFIER_TYPE_LITERAL
|
368
|
+
self[:object] = @mp[:object] = ::FFI::MemoryPointer.from_string(value.value)
|
369
|
+
self[:object_literal_datatype] = if value.datatype
|
370
|
+
@raptor_uri_list.push(V1_4.raptor_new_uri(value.datatype.to_s)).last
|
371
|
+
else
|
372
|
+
nil
|
373
|
+
end
|
374
|
+
self[:object_literal_language] = @mp[:object_literal_language] = if value.language?
|
375
|
+
::FFI::MemoryPointer.from_string(value.language.to_s)
|
376
|
+
else
|
377
|
+
nil
|
378
|
+
end
|
379
|
+
else
|
380
|
+
raise ArgumentError, "object must be of type RDF::Node, RDF::URI or RDF::Literal"
|
381
|
+
end
|
382
|
+
@object = value
|
383
|
+
end
|
384
|
+
|
216
385
|
##
|
217
386
|
# @return [String]
|
218
387
|
def object_as_string
|
@@ -234,17 +403,25 @@ module RDF::Raptor
|
|
234
403
|
def to_quad
|
235
404
|
[subject, predicate, object, nil]
|
236
405
|
end
|
406
|
+
|
237
407
|
end
|
238
408
|
|
239
409
|
# @see http://librdf.org/raptor/api/tutorial-initialising-finishing.html
|
240
410
|
attach_function :raptor_init, [], :void
|
241
411
|
attach_function :raptor_finish, [], :void
|
242
412
|
|
243
|
-
# @see http://librdf.org/raptor/api/raptor-section-
|
244
|
-
define_pointer :
|
245
|
-
attach_function :
|
246
|
-
attach_function :
|
247
|
-
attach_function :
|
413
|
+
# @see http://librdf.org/raptor/api/raptor-section-locator.html
|
414
|
+
define_pointer :raptor_locator
|
415
|
+
attach_function :raptor_locator_line, [raptor_locator], :int
|
416
|
+
attach_function :raptor_locator_column, [raptor_locator], :int
|
417
|
+
attach_function :raptor_locator_byte, [raptor_locator], :int
|
418
|
+
|
419
|
+
# @see http://librdf.org/raptor/api/raptor-section-general.html
|
420
|
+
attach_variable :raptor_version_major, :int
|
421
|
+
attach_variable :raptor_version_minor, :int
|
422
|
+
attach_variable :raptor_version_release, :int
|
423
|
+
attach_variable :raptor_version_decimal, :int
|
424
|
+
callback :raptor_message_handler, [:pointer, raptor_locator, :string], :void
|
248
425
|
|
249
426
|
# @see http://librdf.org/raptor/api/raptor-section-uri.html
|
250
427
|
define_pointer :raptor_uri
|
@@ -255,6 +432,7 @@ module RDF::Raptor
|
|
255
432
|
attach_function :raptor_free_uri, [raptor_uri], :void
|
256
433
|
|
257
434
|
# @see http://librdf.org/raptor/api/raptor-section-triples.html
|
435
|
+
define_pointer :raptor_identifier
|
258
436
|
define_pointer :raptor_statement
|
259
437
|
attach_function :raptor_statement_compare, [raptor_statement, raptor_statement], :int
|
260
438
|
attach_function :raptor_print_statement, [raptor_statement, :pointer], :void
|
@@ -265,6 +443,8 @@ module RDF::Raptor
|
|
265
443
|
callback :raptor_statement_handler, [:pointer, raptor_statement], :void
|
266
444
|
define_pointer :raptor_parser
|
267
445
|
attach_function :raptor_new_parser, [:string], raptor_parser
|
446
|
+
attach_function :raptor_set_error_handler, [raptor_parser, :pointer, :raptor_message_handler], :void
|
447
|
+
attach_function :raptor_set_warning_handler, [raptor_parser, :pointer, :raptor_message_handler], :void
|
268
448
|
attach_function :raptor_set_statement_handler, [raptor_parser, :pointer, :raptor_statement_handler], :void
|
269
449
|
attach_function :raptor_parse_file, [raptor_parser, raptor_uri, raptor_uri], :int
|
270
450
|
attach_function :raptor_parse_file_stream, [raptor_parser, :pointer, :string, raptor_uri], :int
|
@@ -274,8 +454,95 @@ module RDF::Raptor
|
|
274
454
|
attach_function :raptor_get_mime_type, [raptor_parser], :string
|
275
455
|
attach_function :raptor_set_parser_strict, [raptor_parser, :int], :void
|
276
456
|
attach_function :raptor_get_need_base_uri, [raptor_parser], :int
|
277
|
-
attach_function :raptor_parser_get_world, [raptor_parser], raptor_world
|
278
457
|
attach_function :raptor_free_parser, [raptor_parser], :void
|
458
|
+
|
459
|
+
# @see http://librdf.org/raptor/api/raptor-section-iostream.html
|
460
|
+
define_pointer :raptor_iostream
|
461
|
+
callback :raptor_iostream_init_func, [:pointer], :int
|
462
|
+
callback :raptor_iostream_finish_func, [:pointer], :void
|
463
|
+
callback :raptor_iostream_write_byte_func, [:pointer, :int], :int
|
464
|
+
callback :raptor_iostream_write_bytes_func, [:pointer, :pointer, :size_t, :size_t], :int
|
465
|
+
callback :raptor_iostream_write_end_func, [:pointer], :void
|
466
|
+
callback :raptor_iostream_read_bytes_func, [:pointer, :pointer, :size_t, :size_t], :int
|
467
|
+
callback :raptor_iostream_read_eof_func, [:pointer], :int
|
468
|
+
attach_function :raptor_new_iostream_from_handler2, [:pointer, :pointer], raptor_iostream
|
469
|
+
attach_function :raptor_free_iostream, [raptor_iostream], :void
|
470
|
+
|
471
|
+
class IOStreamHandler < ::FFI::Struct
|
472
|
+
layout :version, :int,
|
473
|
+
:init, :raptor_iostream_init_func,
|
474
|
+
:finish, :raptor_iostream_finish_func,
|
475
|
+
:write_byte, :raptor_iostream_write_byte_func,
|
476
|
+
:write_bytes, :raptor_iostream_write_bytes_func,
|
477
|
+
:write_end, :raptor_iostream_write_end_func,
|
478
|
+
:read_bytes, :raptor_iostream_read_bytes_func,
|
479
|
+
:read_eof, :raptor_iostream_read_eof_func
|
480
|
+
|
481
|
+
attr_accessor :rubyio
|
482
|
+
|
483
|
+
def initialize(*args)
|
484
|
+
super
|
485
|
+
# Keep a ruby land reference to our procs so they don't
|
486
|
+
# get snatched by GC.
|
487
|
+
@procs = {}
|
488
|
+
|
489
|
+
self[:version] = 2
|
490
|
+
|
491
|
+
# @procs[:init] = self[:init] = Proc.new do |context|
|
492
|
+
# $stderr.puts("#{self.class}: init")
|
493
|
+
# end
|
494
|
+
# @procs[:finish] = self[:finish] = Proc.new do |context|
|
495
|
+
# $stderr.puts("#{self.class}: finish")
|
496
|
+
# end
|
497
|
+
@procs[:write_byte] = self[:write_byte] = Proc.new do |context, byte|
|
498
|
+
begin
|
499
|
+
@rubyio.putc(byte)
|
500
|
+
rescue
|
501
|
+
return 1
|
502
|
+
end
|
503
|
+
0
|
504
|
+
end
|
505
|
+
@procs[:write_bytes] = self[:write_bytes] = Proc.new do |context, data, size, nmemb|
|
506
|
+
begin
|
507
|
+
@rubyio.write(data.read_string(size * nmemb))
|
508
|
+
rescue
|
509
|
+
return 1
|
510
|
+
end
|
511
|
+
0
|
512
|
+
end
|
513
|
+
# @procs[:write_end] = self[:write_end] = Proc.new do |context|
|
514
|
+
# $stderr.puts("#{self.class}: write_end")
|
515
|
+
# end
|
516
|
+
# @procs[:read_bytes] = self[:read_bytes] = Proc.new do |context, data, size, nmemb|
|
517
|
+
# $stderr.puts("#{self.class}: read_bytes")
|
518
|
+
# end
|
519
|
+
# @procs[:read_eof] = self[:read_eof] = Proc.new do |context|
|
520
|
+
# $stderr.puts("#{self.class}: read_eof")
|
521
|
+
# end
|
522
|
+
end
|
523
|
+
end
|
524
|
+
|
525
|
+
# @see http://librdf.org/raptor/api/raptor-section-xml-namespace.html
|
526
|
+
define_pointer :raptor_namespace
|
527
|
+
|
528
|
+
# @see http://librdf.org/raptor/api/raptor-section-serializer.html
|
529
|
+
define_pointer :raptor_serializer
|
530
|
+
attach_function :raptor_new_serializer, [:string], raptor_serializer
|
531
|
+
attach_function :raptor_free_serializer, [raptor_serializer], :void
|
532
|
+
attach_function :raptor_serialize_start_to_iostream, [raptor_serializer, raptor_uri, raptor_iostream], :int
|
533
|
+
attach_function :raptor_serialize_start_to_filename, [raptor_serializer, :string], :int
|
534
|
+
attach_function :raptor_serialize_statement, [raptor_serializer, raptor_statement], :int
|
535
|
+
attach_function :raptor_serialize_end, [raptor_serializer], :int
|
536
|
+
attach_function :raptor_serializer_set_error_handler, [raptor_serializer, :pointer, :raptor_message_handler], :void
|
537
|
+
attach_function :raptor_serializer_set_warning_handler, [raptor_serializer, :pointer, :raptor_message_handler], :void
|
538
|
+
|
539
|
+
# Initialize the world
|
540
|
+
# We do this exactly once and never release because we can't delegate
|
541
|
+
# any memory management to the ruby GC.
|
542
|
+
# Internally raptor_init/raptor_finish work with ref-counts.
|
543
|
+
raptor_init
|
544
|
+
|
279
545
|
end
|
280
546
|
end
|
281
547
|
end
|
548
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module RDF::Raptor
|
2
|
+
##
|
3
|
+
# Graphviz support.
|
4
|
+
#
|
5
|
+
# @example Requiring the `RDF::Raptor` module
|
6
|
+
# require 'rdf/raptor'
|
7
|
+
#
|
8
|
+
# @example Serializing RDF statements into a Graphviz file
|
9
|
+
# RDF::Writer.open("output.dot") do |writer|
|
10
|
+
# graph.each_statement do |statement|
|
11
|
+
# writer << statement
|
12
|
+
# end
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
module Graphviz
|
16
|
+
##
|
17
|
+
# Graphviz format specification.
|
18
|
+
#
|
19
|
+
# @example Obtaining a Graphviz format class
|
20
|
+
# RDF::Format.for(:graphviz) #=> RDF::Raptor::Graphviz::Format
|
21
|
+
# RDF::Format.for("output.dot")
|
22
|
+
# RDF::Format.for(:file_name => "output.dot")
|
23
|
+
# RDF::Format.for(:file_extension => "dot")
|
24
|
+
# RDF::Format.for(:content_type => "text/vnd.graphviz")
|
25
|
+
#
|
26
|
+
# @see http://www.iana.org/assignments/media-types/text/vnd.graphviz
|
27
|
+
class Format < RDF::Raptor::Format
|
28
|
+
content_type 'text/vnd.graphviz', :aliases => ['application/x-graphviz', 'text/x-graphviz'], :extension => :dot # TODO: also .gv
|
29
|
+
content_encoding 'utf-8'
|
30
|
+
rapper_format :dot
|
31
|
+
|
32
|
+
writer { RDF::Raptor::Graphviz::Writer }
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Graphviz serializer.
|
37
|
+
#
|
38
|
+
# @example Obtaining a Graphviz writer class
|
39
|
+
# RDF::Writer.for(:graphviz) #=> RDF::Raptor::Graphviz::Writer
|
40
|
+
# RDF::Writer.for("output.dot")
|
41
|
+
# RDF::Writer.for(:file_name => "output.dot")
|
42
|
+
# RDF::Writer.for(:file_extension => "dot")
|
43
|
+
# RDF::Writer.for(:content_type => "text/vnd.graphviz")
|
44
|
+
#
|
45
|
+
# @example Serializing RDF statements into a Graphviz file
|
46
|
+
# RDF::Writer.open("output.dot") do |writer|
|
47
|
+
# graph.each_statement do |statement|
|
48
|
+
# writer << statement
|
49
|
+
# end
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
class Writer < RDF::Raptor::Writer
|
53
|
+
format RDF::Raptor::Graphviz::Format
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/rdf/raptor/turtle.rb
CHANGED
@@ -23,6 +23,7 @@ module RDF::Raptor
|
|
23
23
|
module Turtle
|
24
24
|
##
|
25
25
|
# Turtle format specification.
|
26
|
+
# @see http://www.w3.org/TeamSubmission/turtle/
|
26
27
|
#
|
27
28
|
# @example Obtaining a Turtle format class
|
28
29
|
# RDF::Format.for(:turtle) #=> RDF::Raptor::Turtle::Format
|
@@ -32,7 +33,7 @@ module RDF::Raptor
|
|
32
33
|
# RDF::Format.for(:content_type => "text/turtle")
|
33
34
|
#
|
34
35
|
class Format < RDF::Raptor::Format
|
35
|
-
content_type 'text/turtle', :extension => :ttl
|
36
|
+
content_type 'text/turtle', :aliases => ['application/x-turtle', 'application/turtle'], :extension => :ttl
|
36
37
|
content_encoding 'utf-8'
|
37
38
|
rapper_format :turtle
|
38
39
|
|
data/lib/rdf/raptor/version.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
module RDF; module Raptor
|
2
2
|
module VERSION
|
3
3
|
MAJOR = 0
|
4
|
-
MINOR =
|
4
|
+
MINOR = 4
|
5
5
|
TINY = 0
|
6
6
|
EXTRA = nil
|
7
7
|
|
8
|
-
STRING = [MAJOR, MINOR, TINY].join('.')
|
9
|
-
STRING << ".#{EXTRA}" if EXTRA
|
8
|
+
STRING = [MAJOR, MINOR, TINY, EXTRA].compact.join('.')
|
10
9
|
|
11
10
|
##
|
12
11
|
# @return [String]
|
metadata
CHANGED
@@ -4,77 +4,78 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 4
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.4.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Arto Bendiken
|
13
|
+
- John Fieber
|
13
14
|
autorequire:
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-06-22 00:00:00 +02:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
|
-
name: rdf
|
22
|
+
name: rdf
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
25
|
requirements:
|
25
|
-
- -
|
26
|
+
- - ~>
|
26
27
|
- !ruby/object:Gem::Version
|
27
28
|
segments:
|
28
29
|
- 0
|
29
|
-
-
|
30
|
-
-
|
31
|
-
version: 0.
|
32
|
-
type: :
|
30
|
+
- 2
|
31
|
+
- 0
|
32
|
+
version: 0.2.0
|
33
|
+
type: :runtime
|
33
34
|
version_requirements: *id001
|
34
35
|
- !ruby/object:Gem::Dependency
|
35
|
-
name:
|
36
|
+
name: yard
|
36
37
|
prerelease: false
|
37
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
39
|
requirements:
|
39
40
|
- - ">="
|
40
41
|
- !ruby/object:Gem::Version
|
41
42
|
segments:
|
42
|
-
- 1
|
43
|
-
- 3
|
44
43
|
- 0
|
45
|
-
|
44
|
+
- 5
|
45
|
+
- 6
|
46
|
+
version: 0.5.6
|
46
47
|
type: :development
|
47
48
|
version_requirements: *id002
|
48
49
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
50
|
+
name: rspec
|
50
51
|
prerelease: false
|
51
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
52
53
|
requirements:
|
53
54
|
- - ">="
|
54
55
|
- !ruby/object:Gem::Version
|
55
56
|
segments:
|
56
|
-
-
|
57
|
-
- 5
|
57
|
+
- 1
|
58
58
|
- 3
|
59
|
-
|
59
|
+
- 0
|
60
|
+
version: 1.3.0
|
60
61
|
type: :development
|
61
62
|
version_requirements: *id003
|
62
63
|
- !ruby/object:Gem::Dependency
|
63
|
-
name: rdf
|
64
|
+
name: rdf-spec
|
64
65
|
prerelease: false
|
65
66
|
requirement: &id004 !ruby/object:Gem::Requirement
|
66
67
|
requirements:
|
67
|
-
- -
|
68
|
+
- - ~>
|
68
69
|
- !ruby/object:Gem::Version
|
69
70
|
segments:
|
70
71
|
- 0
|
71
|
-
-
|
72
|
-
-
|
73
|
-
version: 0.
|
74
|
-
type: :
|
72
|
+
- 2
|
73
|
+
- 0
|
74
|
+
version: 0.2.0
|
75
|
+
type: :development
|
75
76
|
version_requirements: *id004
|
76
|
-
description: RDF.rb plugin for parsing/serializing RDF/XML and
|
77
|
-
email:
|
77
|
+
description: RDF.rb plugin for parsing/serializing RDF/XML, Turtle and RDFa data using the Raptor RDF Parser library.
|
78
|
+
email: public-rdf-ruby@w3.org
|
78
79
|
executables: []
|
79
80
|
|
80
81
|
extensions: []
|
@@ -83,11 +84,14 @@ extra_rdoc_files: []
|
|
83
84
|
|
84
85
|
files:
|
85
86
|
- AUTHORS
|
87
|
+
- CONTRIBUTORS
|
86
88
|
- README
|
87
89
|
- UNLICENSE
|
88
90
|
- VERSION
|
91
|
+
- etc/doap.ttl
|
89
92
|
- lib/rdf/raptor/cli.rb
|
90
93
|
- lib/rdf/raptor/ffi.rb
|
94
|
+
- lib/rdf/raptor/graphviz.rb
|
91
95
|
- lib/rdf/raptor/rdfa.rb
|
92
96
|
- lib/rdf/raptor/rdfxml.rb
|
93
97
|
- lib/rdf/raptor/turtle.rb
|
@@ -109,8 +113,8 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
113
|
segments:
|
110
114
|
- 1
|
111
115
|
- 8
|
112
|
-
-
|
113
|
-
version: 1.8.
|
116
|
+
- 1
|
117
|
+
version: 1.8.1
|
114
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
119
|
requirements:
|
116
120
|
- - ">="
|
@@ -119,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
123
|
- 0
|
120
124
|
version: "0"
|
121
125
|
requirements:
|
122
|
-
-
|
126
|
+
- libraptor (>= 1.4.16)
|
123
127
|
rubyforge_project: rdf
|
124
128
|
rubygems_version: 1.3.6
|
125
129
|
signing_key:
|