rdf-raptor 1.99.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CONTRIBUTING.md +38 -0
- data/{README → README.md} +22 -24
- data/UNLICENSE +1 -1
- data/VERSION +1 -1
- data/etc/doap.ttl +30 -25
- data/lib/rdf/raptor/cli.rb +10 -10
- data/lib/rdf/raptor/ffi/v1/iostream.rb +2 -2
- data/lib/rdf/raptor/ffi/v1/iostream_handler.rb +1 -1
- data/lib/rdf/raptor/ffi/v1/parser.rb +14 -14
- data/lib/rdf/raptor/ffi/v1/serializer.rb +6 -6
- data/lib/rdf/raptor/ffi/v1/statement.rb +1 -1
- data/lib/rdf/raptor/ffi/v1/uri.rb +1 -1
- data/lib/rdf/raptor/ffi/v1.rb +10 -10
- data/lib/rdf/raptor/ffi/v2/iostream.rb +2 -2
- data/lib/rdf/raptor/ffi/v2/iostream_handler.rb +1 -1
- data/lib/rdf/raptor/ffi/v2/namespace.rb +1 -1
- data/lib/rdf/raptor/ffi/v2/parser.rb +10 -10
- data/lib/rdf/raptor/ffi/v2/serializer.rb +11 -9
- data/lib/rdf/raptor/ffi/v2/statement.rb +1 -1
- data/lib/rdf/raptor/ffi/v2/term.rb +1 -1
- data/lib/rdf/raptor/ffi/v2/uri.rb +1 -1
- data/lib/rdf/raptor/ffi/v2.rb +12 -11
- data/lib/rdf/raptor/ffi.rb +45 -16
- data/lib/rdf/raptor/graphviz.rb +1 -10
- data/lib/rdf/raptor/ntriples.rb +6 -1
- data/lib/rdf/raptor/rdfa.rb +23 -2
- data/lib/rdf/raptor/rdfxml.rb +5 -1
- data/lib/rdf/raptor/turtle.rb +32 -1
- data/lib/rdf/raptor/version.rb +1 -1
- data/lib/rdf/raptor.rb +6 -6
- metadata +38 -39
@@ -3,7 +3,7 @@ module RDF::Raptor::FFI::V2
|
|
3
3
|
# This class provides the functionality of turning syntaxes into RDF
|
4
4
|
# triples - RDF parsing.
|
5
5
|
#
|
6
|
-
# @see
|
6
|
+
# @see https://librdf.org/raptor/api/raptor2-section-parser.html
|
7
7
|
class Parser < ::FFI::ManagedStruct
|
8
8
|
include RDF::Raptor::FFI
|
9
9
|
layout :world, :pointer # the actual layout is private
|
@@ -82,16 +82,16 @@ module RDF::Raptor::FFI::V2
|
|
82
82
|
# @yieldparam [FFI::Pointer] statement
|
83
83
|
# @yieldreturn [void] ignored
|
84
84
|
# @return [void]
|
85
|
-
def parse(input, options
|
85
|
+
def parse(input, **options, &block)
|
86
86
|
case input
|
87
87
|
when RDF::URI, URI, %r(^(file|https|http|ftp)://)
|
88
|
-
parse_url(input, options, &block)
|
88
|
+
parse_url(input, **options, &block)
|
89
89
|
when File, Tempfile
|
90
|
-
parse_file(input, options, &block)
|
90
|
+
parse_file(input, **options, &block)
|
91
91
|
when IO, StringIO
|
92
|
-
parse_stream(input, options, &block)
|
92
|
+
parse_stream(input, **options, &block)
|
93
93
|
when String
|
94
|
-
parse_buffer(input, options, &block)
|
94
|
+
parse_buffer(input, **options, &block)
|
95
95
|
else
|
96
96
|
raise ArgumentError, "don't know how to parse #{input.inspect}"
|
97
97
|
end
|
@@ -108,7 +108,7 @@ module RDF::Raptor::FFI::V2
|
|
108
108
|
# @yieldparam [FFI::Pointer] statement
|
109
109
|
# @yieldreturn [void] ignored
|
110
110
|
# @return [void]
|
111
|
-
def parse_url(url, options
|
111
|
+
def parse_url(url, **options, &block)
|
112
112
|
self.statement_handler = block if block_given?
|
113
113
|
|
114
114
|
data_url = V2::URI.new((url.respond_to?(:to_uri) ? url.to_uri : url).to_s)
|
@@ -130,7 +130,7 @@ module RDF::Raptor::FFI::V2
|
|
130
130
|
# @yieldparam [FFI::Pointer] statement
|
131
131
|
# @yieldreturn [void] ignored
|
132
132
|
# @return [void]
|
133
|
-
def parse_file(file, options
|
133
|
+
def parse_file(file, **options, &block)
|
134
134
|
self.statement_handler = block if block_given?
|
135
135
|
|
136
136
|
data_url = V2::URI.new("file://#{File.expand_path(file.path)}")
|
@@ -151,7 +151,7 @@ module RDF::Raptor::FFI::V2
|
|
151
151
|
# @yieldparam [FFI::Pointer] statement
|
152
152
|
# @yieldreturn [void] ignored
|
153
153
|
# @return [void]
|
154
|
-
def parse_stream(stream, options
|
154
|
+
def parse_stream(stream, **options, &block)
|
155
155
|
self.statement_handler = block if block_given?
|
156
156
|
|
157
157
|
begin
|
@@ -175,7 +175,7 @@ module RDF::Raptor::FFI::V2
|
|
175
175
|
# @yieldparam [FFI::Pointer] statement
|
176
176
|
# @yieldreturn [void] ignored
|
177
177
|
# @return [void]
|
178
|
-
def parse_buffer(buffer, options
|
178
|
+
def parse_buffer(buffer, **options, &block)
|
179
179
|
self.statement_handler = block if block_given?
|
180
180
|
|
181
181
|
parse_start!((options[:base_uri] || BASE_URI).to_s)
|
@@ -3,10 +3,12 @@ module RDF::Raptor::FFI::V2
|
|
3
3
|
# This class provides the functionality of turning RDF triples into
|
4
4
|
# syntaxes - RDF serializing.
|
5
5
|
#
|
6
|
-
# @see
|
6
|
+
# @see https://librdf.org/raptor/api-1.4/raptor-section-serializer.html
|
7
7
|
class Serializer < ::FFI::ManagedStruct
|
8
8
|
include RDF::Raptor::FFI
|
9
9
|
|
10
|
+
attr_reader :iostream
|
11
|
+
|
10
12
|
# Note this layout is private
|
11
13
|
layout :world, :pointer,
|
12
14
|
:locator, :pointer,
|
@@ -49,14 +51,14 @@ module RDF::Raptor::FFI::V2
|
|
49
51
|
# @param [Proc] handler
|
50
52
|
# @return [void]
|
51
53
|
def error_handler=(handler)
|
52
|
-
V2.raptor_serializer_set_error_handler(self, self, handler)
|
54
|
+
V2.raptor_serializer_set_error_handler(self, self, handler) if V2.respond_to?(:raptor_serializer_set_error_handler)
|
53
55
|
end
|
54
56
|
|
55
57
|
##
|
56
58
|
# @param [Proc] handler
|
57
59
|
# @return [void]
|
58
60
|
def warning_handler=(handler)
|
59
|
-
V2.raptor_serializer_set_warning_handler(self, self, handler)
|
61
|
+
V2.raptor_serializer_set_warning_handler(self, self, handler) if V2.respond_to?(:raptor_serializer_set_warning_handler)
|
60
62
|
end
|
61
63
|
|
62
64
|
##
|
@@ -67,9 +69,9 @@ module RDF::Raptor::FFI::V2
|
|
67
69
|
# @option options [String, #to_s] :base_uri (nil)
|
68
70
|
# the base URI to use when resolving relative URIs
|
69
71
|
# @return [void]
|
70
|
-
def start_to(output, options
|
72
|
+
def start_to(output, **options)
|
71
73
|
if output.respond_to?(:write)
|
72
|
-
start_to_stream(output, options)
|
74
|
+
start_to_stream(output, **options)
|
73
75
|
else
|
74
76
|
raise ArgumentError, "don't know how to serialize to #{output.inspect}"
|
75
77
|
end
|
@@ -80,9 +82,9 @@ module RDF::Raptor::FFI::V2
|
|
80
82
|
# @param [Hash{Symbol => Object}] options
|
81
83
|
# any additional options for serializing (see {#start_to})
|
82
84
|
# @return [void]
|
83
|
-
def start_to_stream(stream, options
|
85
|
+
def start_to_stream(stream, **options)
|
84
86
|
iostream = V2::IOStream.new(V2::IOStreamHandler.new(stream), free_iostream: self[:free_iostream_on_end])
|
85
|
-
start_to_iostream(iostream, options)
|
87
|
+
start_to_iostream(iostream, **options)
|
86
88
|
end
|
87
89
|
|
88
90
|
##
|
@@ -90,9 +92,9 @@ module RDF::Raptor::FFI::V2
|
|
90
92
|
# @param [Hash{Symbol => Object}] options
|
91
93
|
# any additional options for serializing (see {#start_to})
|
92
94
|
# @return [void]
|
93
|
-
def start_to_iostream(iostream,
|
95
|
+
def start_to_iostream(iostream, base_uri: nil, **options)
|
94
96
|
@iostream = iostream # prevents premature GC
|
95
|
-
@base_uri =
|
97
|
+
@base_uri = base_uri.to_s.empty? ? nil : V2::URI.new(base_uri.to_s)
|
96
98
|
if V2.raptor_serializer_start_to_iostream(self, @base_uri, @iostream).nonzero?
|
97
99
|
raise RDF::WriterError, "raptor_serialize_start_to_iostream() failed"
|
98
100
|
end
|
@@ -4,7 +4,7 @@ module RDF::Raptor::FFI::V2
|
|
4
4
|
# passing URI references. The default internal implementation uses `char*`
|
5
5
|
# strings for URIs, manipulating them and constructing them.
|
6
6
|
#
|
7
|
-
# @see
|
7
|
+
# @see https://librdf.org/raptor/api-1.4/raptor-section-uri.html
|
8
8
|
class URI < ::FFI::ManagedStruct
|
9
9
|
include RDF::Raptor::FFI
|
10
10
|
include RDF::Resource
|
data/lib/rdf/raptor/ffi/v2.rb
CHANGED
@@ -2,7 +2,7 @@ module RDF::Raptor::FFI
|
|
2
2
|
##
|
3
3
|
# A foreign-function interface (FFI) to `libraptor` 2.x.
|
4
4
|
#
|
5
|
-
# @see
|
5
|
+
# @see https://librdf.org/raptor/libraptor.html
|
6
6
|
module V2
|
7
7
|
autoload :IOStream, 'rdf/raptor/ffi/v2/iostream'
|
8
8
|
autoload :IOStreamHandler, 'rdf/raptor/ffi/v2/iostream_handler'
|
@@ -25,22 +25,23 @@ module RDF::Raptor::FFI
|
|
25
25
|
RAPTOR_TERM_TYPE_LITERAL = 2
|
26
26
|
RAPTOR_TERM_TYPE_BLANK = 4
|
27
27
|
|
28
|
-
# @see
|
28
|
+
# @see https://librdf.org/raptor/api/tutorial-initialising-finishing.html
|
29
29
|
typedef :pointer, :raptor_world
|
30
30
|
typedef :int, :raptor_version
|
31
|
+
typedef :pointer, :raptor_iostream
|
31
32
|
attach_function :raptor_new_world_internal, [:raptor_version], :raptor_world
|
32
33
|
attach_function :raptor_free_world, [], :void
|
33
34
|
attach_function :raptor_alloc_memory, [:size_t], :pointer
|
34
35
|
attach_function :raptor_calloc_memory, [:size_t, :size_t], :pointer
|
35
36
|
attach_function :raptor_free_memory, [:pointer], :void
|
36
37
|
|
37
|
-
# @see
|
38
|
+
# @see https://librdf.org/raptor/api-1.4/raptor-section-locator.html
|
38
39
|
typedef :pointer, :raptor_locator
|
39
40
|
attach_function :raptor_locator_line, [:raptor_locator], :int
|
40
41
|
attach_function :raptor_locator_column, [:raptor_locator], :int
|
41
42
|
attach_function :raptor_locator_byte, [:raptor_locator], :int
|
42
43
|
|
43
|
-
# @see
|
44
|
+
# @see https://librdf.org/raptor/api/raptor2-section-general.html
|
44
45
|
attach_variable :raptor_version_string, :string
|
45
46
|
attach_variable :raptor_version_major, :int
|
46
47
|
attach_variable :raptor_version_minor, :int
|
@@ -48,7 +49,7 @@ module RDF::Raptor::FFI
|
|
48
49
|
attach_variable :raptor_version_decimal, :int
|
49
50
|
callback :raptor_message_handler, [:pointer, :raptor_locator, :string], :void
|
50
51
|
|
51
|
-
# @see
|
52
|
+
# @see https://librdf.org/raptor/api-1.4/raptor-section-uri.html
|
52
53
|
typedef :pointer, :raptor_uri
|
53
54
|
attach_function :raptor_new_uri, [:raptor_world, :string], :raptor_uri
|
54
55
|
attach_function :raptor_uri_copy, [:raptor_uri], :raptor_uri
|
@@ -58,7 +59,7 @@ module RDF::Raptor::FFI
|
|
58
59
|
attach_function :raptor_uri_print, [:raptor_uri, :pointer], :void
|
59
60
|
attach_function :raptor_free_uri, [:raptor_uri], :void
|
60
61
|
|
61
|
-
# @see
|
62
|
+
# @see https://librdf.org/raptor/api/raptor2-section-triples.html
|
62
63
|
typedef :int, :raptor_identifier_type
|
63
64
|
typedef :pointer, :raptor_identifier
|
64
65
|
typedef :pointer, :raptor_statement
|
@@ -77,12 +78,13 @@ module RDF::Raptor::FFI
|
|
77
78
|
attach_function :raptor_new_term_from_literal, [:raptor_world, :literal, :datatype, :language], :raptor_term
|
78
79
|
attach_function :raptor_new_term_from_blank, [:raptor_world, :blank], :raptor_term
|
79
80
|
attach_function :raptor_free_term, [:raptor_term], :void
|
81
|
+
attach_function :raptor_term_ntriples_write, [:raptor_term, :raptor_iostream], :int
|
80
82
|
|
81
|
-
# @see
|
83
|
+
# @see https://librdf.org/raptor/api/raptor2-section-xml-namespace.html
|
82
84
|
typedef :pointer, :raptor_namespace
|
83
85
|
attach_function :raptor_free_namespace, [:raptor_namespace], :void
|
84
86
|
|
85
|
-
# @see
|
87
|
+
# @see https://librdf.org/raptor/api/raptor2-section-parser.html
|
86
88
|
callback :raptor_statement_handler, [:pointer, :raptor_statement], :void
|
87
89
|
callback :raptor_namespace_handler, [:pointer, :raptor_namespace], :void
|
88
90
|
typedef :pointer, :raptor_parser
|
@@ -105,8 +107,7 @@ module RDF::Raptor::FFI
|
|
105
107
|
attach_function :raptor_parser_parse_abort, [], :void
|
106
108
|
attach_function :raptor_free_parser, [:raptor_parser], :void
|
107
109
|
|
108
|
-
# @see
|
109
|
-
typedef :pointer, :raptor_iostream
|
110
|
+
# @see https://librdf.org/raptor/api/raptor2-section-iostream.html
|
110
111
|
attach_function :raptor_new_iostream_from_handler, [:raptor_world, :pointer, :pointer], :raptor_iostream
|
111
112
|
attach_function :raptor_new_iostream_to_filename, [:raptor_world, :string], :raptor_iostream
|
112
113
|
attach_function :raptor_new_iostream_to_sink, [:raptor_world], :raptor_iostream
|
@@ -119,7 +120,7 @@ module RDF::Raptor::FFI
|
|
119
120
|
callback :raptor_iostream_read_bytes_func, [:pointer, :pointer, :size_t, :size_t], :int
|
120
121
|
callback :raptor_iostream_read_eof_func, [:pointer], :int
|
121
122
|
|
122
|
-
# @see
|
123
|
+
# @see https://librdf.org/raptor/api/raptor2-section-serializer.html
|
123
124
|
typedef :pointer, :raptor_serializer
|
124
125
|
typedef :string, :prefix
|
125
126
|
attach_function :raptor_new_serializer, [:raptor_world, :string], :raptor_serializer
|
data/lib/rdf/raptor/ffi.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'tempfile'
|
2
|
-
require 'ffi' # @see
|
2
|
+
require 'ffi' # @see https://rubygems.org/gems/ffi
|
3
3
|
|
4
4
|
module RDF::Raptor
|
5
5
|
##
|
@@ -28,6 +28,8 @@ module RDF::Raptor
|
|
28
28
|
##
|
29
29
|
# FFI reader implementation.
|
30
30
|
class Reader < RDF::Reader
|
31
|
+
include RDF::Util::Logger
|
32
|
+
|
31
33
|
##
|
32
34
|
# Initializes the FFI reader instance.
|
33
35
|
#
|
@@ -38,7 +40,7 @@ module RDF::Raptor
|
|
38
40
|
# @yield [reader] `self`
|
39
41
|
# @yieldparam [RDF::Reader] reader
|
40
42
|
# @yieldreturn [void] ignored
|
41
|
-
def initialize(input = $stdin, options
|
43
|
+
def initialize(input = $stdin, **options, &block)
|
42
44
|
@format = self.class.format.rapper_format
|
43
45
|
@parser = V2::Parser.new(@format)
|
44
46
|
@parser.error_handler = ERROR_HANDLER
|
@@ -54,12 +56,12 @@ module RDF::Raptor
|
|
54
56
|
|
55
57
|
ERROR_HANDLER = Proc.new do |user_data, locator, message|
|
56
58
|
line = V2.raptor_locator_line(locator)
|
57
|
-
|
59
|
+
log_error(message, lineno: line)
|
58
60
|
end
|
59
61
|
|
60
62
|
WARNING_HANDLER = Proc.new do |user_data, locator, message|
|
61
|
-
|
62
|
-
|
63
|
+
line = V2.raptor_locator_line(locator)
|
64
|
+
log_warn(message, lineno: line)
|
63
65
|
end
|
64
66
|
|
65
67
|
##
|
@@ -73,7 +75,7 @@ module RDF::Raptor
|
|
73
75
|
# @yieldparam [RDF::Statement] statement
|
74
76
|
# @yieldreturn [void] ignored
|
75
77
|
# @see RDF::Reader#each_statement
|
76
|
-
def each_statement(options
|
78
|
+
def each_statement(**options, &block)
|
77
79
|
if block_given?
|
78
80
|
if options[:raw]
|
79
81
|
# this is up to an order of magnitude faster...
|
@@ -85,8 +87,12 @@ module RDF::Raptor
|
|
85
87
|
block.call(V2::Statement.new(statement, self).to_rdf)
|
86
88
|
end
|
87
89
|
end
|
90
|
+
|
91
|
+
if validate? && log_statistics[:error]
|
92
|
+
raise RDF::ReaderError, "Errors found during processing"
|
93
|
+
end
|
88
94
|
end
|
89
|
-
enum_for(:each_statement, options)
|
95
|
+
enum_for(:each_statement, **options)
|
90
96
|
end
|
91
97
|
alias_method :each, :each_statement
|
92
98
|
|
@@ -97,8 +103,8 @@ module RDF::Raptor
|
|
97
103
|
# @see RDF::Reader#each_triple
|
98
104
|
def each_triple(&block)
|
99
105
|
if block_given?
|
100
|
-
|
101
|
-
block.call(
|
106
|
+
each_statement do |statement|
|
107
|
+
block.call(*statement.to_triple)
|
102
108
|
end
|
103
109
|
end
|
104
110
|
enum_for(:each_triple)
|
@@ -115,7 +121,7 @@ module RDF::Raptor
|
|
115
121
|
# @yieldreturn [void] ignored
|
116
122
|
# @return [void]
|
117
123
|
def parse(input, &block)
|
118
|
-
@parser.parse(input,
|
124
|
+
@parser.parse(input, **@options, &block)
|
119
125
|
end
|
120
126
|
|
121
127
|
GENID = /^genid\d+$/
|
@@ -139,6 +145,8 @@ module RDF::Raptor
|
|
139
145
|
##
|
140
146
|
# FFI writer implementation.
|
141
147
|
class Writer < RDF::Writer
|
148
|
+
include RDF::Util::Logger
|
149
|
+
|
142
150
|
##
|
143
151
|
# Initializes the FFI writer instance.
|
144
152
|
#
|
@@ -148,21 +156,21 @@ module RDF::Raptor
|
|
148
156
|
# @yield [writer] `self`
|
149
157
|
# @yieldparam [RDF::Writer] writer
|
150
158
|
# @yieldreturn [void] ignored
|
151
|
-
def initialize(output = $stdout, options
|
159
|
+
def initialize(output = $stdout, **options, &block)
|
152
160
|
@format = self.class.format.rapper_format
|
153
161
|
@serializer = V2::Serializer.new(@format)
|
154
|
-
|
155
|
-
|
156
|
-
@serializer.start_to(output, options)
|
162
|
+
@serializer.error_handler = ERROR_HANDLER
|
163
|
+
@serializer.warning_handler = WARNING_HANDLER
|
164
|
+
@serializer.start_to(output, **options)
|
157
165
|
super
|
158
166
|
end
|
159
167
|
|
160
168
|
ERROR_HANDLER = Proc.new do |user_data, locator, message|
|
161
|
-
|
169
|
+
log_error(message)
|
162
170
|
end
|
163
171
|
|
164
172
|
WARNING_HANDLER = Proc.new do |user_data, locator, message|
|
165
|
-
|
173
|
+
log_warn(message)
|
166
174
|
end
|
167
175
|
|
168
176
|
##
|
@@ -171,6 +179,23 @@ module RDF::Raptor
|
|
171
179
|
# @return [V2::Serializer]
|
172
180
|
attr_reader :serializer
|
173
181
|
|
182
|
+
def self.serialize(value)
|
183
|
+
output = StringIO.new
|
184
|
+
writer = new(output)
|
185
|
+
case value
|
186
|
+
when nil then nil
|
187
|
+
when FalseClass then value.to_s
|
188
|
+
when RDF::Statement
|
189
|
+
writer.write_triple(statement.subject, statement.predicate, statement.object)
|
190
|
+
when RDF::Term
|
191
|
+
writer.write_term(value)
|
192
|
+
else
|
193
|
+
raise ArgumentError, "expected an RDF::Statement or RDF::Term, but got #{value.inspect}"
|
194
|
+
end
|
195
|
+
|
196
|
+
output.to_s
|
197
|
+
end
|
198
|
+
|
174
199
|
##
|
175
200
|
# @param [RDF::Resource] subject
|
176
201
|
# @param [RDF::URI] predicate
|
@@ -181,6 +206,10 @@ module RDF::Raptor
|
|
181
206
|
@serializer.serialize_triple(subject, predicate, object)
|
182
207
|
end
|
183
208
|
|
209
|
+
def write_term(value)
|
210
|
+
raise NotImplementedError
|
211
|
+
end
|
212
|
+
|
184
213
|
##
|
185
214
|
# @return [void]
|
186
215
|
# @see RDF::Writer#write_prologue
|
data/lib/rdf/raptor/graphviz.rb
CHANGED
@@ -23,7 +23,7 @@ module RDF::Raptor
|
|
23
23
|
# RDF::Format.for(file_extension: "dot")
|
24
24
|
# RDF::Format.for(content_type: "text/vnd.graphviz")
|
25
25
|
#
|
26
|
-
# @see
|
26
|
+
# @see https://www.iana.org/assignments/media-types/text/vnd.graphviz
|
27
27
|
class Format < RDF::Format
|
28
28
|
extend RDF::Raptor::Format
|
29
29
|
|
@@ -32,7 +32,6 @@ module RDF::Raptor
|
|
32
32
|
rapper_format :dot
|
33
33
|
|
34
34
|
writer { RDF::Raptor::Graphviz::Writer }
|
35
|
-
reader { RDF::Raptor::Graphviz::Reader }
|
36
35
|
end # Format
|
37
36
|
|
38
37
|
##
|
@@ -55,13 +54,5 @@ module RDF::Raptor
|
|
55
54
|
class Writer < RDF::Raptor::Writer
|
56
55
|
format RDF::Raptor::Graphviz::Format
|
57
56
|
end # Writer
|
58
|
-
|
59
|
-
##
|
60
|
-
# Raptor does not implement a Graphviz reader, but we need one in
|
61
|
-
# order for the Format to pass specs. This class should always
|
62
|
-
# raise a NoMethodError to indicate it shouldn't be used.
|
63
|
-
#
|
64
|
-
class Reader
|
65
|
-
end
|
66
57
|
end # Graphviz
|
67
58
|
end # RDF::Raptor
|
data/lib/rdf/raptor/ntriples.rb
CHANGED
@@ -19,7 +19,7 @@ module RDF::Raptor
|
|
19
19
|
# end
|
20
20
|
# end
|
21
21
|
#
|
22
|
-
# @see
|
22
|
+
# @see https://www.w3.org/TR/rdf-testcases/#ntriples
|
23
23
|
module NTriples
|
24
24
|
##
|
25
25
|
# N-Triples format specification.
|
@@ -86,7 +86,12 @@ module RDF::Raptor
|
|
86
86
|
# end
|
87
87
|
#
|
88
88
|
class Writer < RDF::Raptor::Writer
|
89
|
+
include RDF::Raptor::FFI
|
89
90
|
format RDF::Raptor::NTriples::Format
|
91
|
+
|
92
|
+
def write_term(value)
|
93
|
+
V2.raptor_term_ntriples_write(value, @serializer.iostream)
|
94
|
+
end
|
90
95
|
end # Writer
|
91
96
|
end # NTriples
|
92
97
|
end # RDF::Raptor
|
data/lib/rdf/raptor/rdfa.rb
CHANGED
@@ -12,7 +12,7 @@ module RDF::Raptor
|
|
12
12
|
# end
|
13
13
|
# end
|
14
14
|
#
|
15
|
-
# @see
|
15
|
+
# @see https://rdfa.info/
|
16
16
|
module RDFa
|
17
17
|
##
|
18
18
|
# RDFa format specification.
|
@@ -27,11 +27,32 @@ module RDF::Raptor
|
|
27
27
|
class Format < RDF::Format
|
28
28
|
extend RDF::Raptor::Format
|
29
29
|
|
30
|
-
content_type '
|
30
|
+
content_type 'text/html',
|
31
|
+
aliases: %w(application/xhtml+xml image/svg+xml),
|
32
|
+
extensions: [:html, :xhtml, :svg]
|
31
33
|
content_encoding 'utf-8'
|
32
34
|
rapper_format :rdfa
|
33
35
|
|
34
36
|
reader { RDF::Raptor::RDFa::Reader }
|
37
|
+
|
38
|
+
##
|
39
|
+
# Sample detection to see if it matches RDFa (not RDF/XML or Microdata)
|
40
|
+
#
|
41
|
+
# Use a text sample to detect the format of an input file. Sub-classes implement
|
42
|
+
# a matcher sufficient to detect probably format matches, including disambiguating
|
43
|
+
# between other similar formats.
|
44
|
+
#
|
45
|
+
# @param [String] sample Beginning several bytes (~ 1K) of input.
|
46
|
+
# @return [Boolean]
|
47
|
+
def self.detect(sample)
|
48
|
+
(sample.match(/<[^>]*(about|resource|prefix|typeof|property|vocab)\s*="[^>]*>/m) ||
|
49
|
+
sample.match(/<[^>]*DOCTYPE\s+html[^>]*>.*xmlns:/im)
|
50
|
+
) && !sample.match(/<(\w+:)?(RDF)/)
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.symbols
|
54
|
+
[:rdfa, :lite, :html, :xhtml, :svg]
|
55
|
+
end
|
35
56
|
end # Format
|
36
57
|
|
37
58
|
##
|
data/lib/rdf/raptor/rdfxml.rb
CHANGED
@@ -19,7 +19,7 @@ module RDF::Raptor
|
|
19
19
|
# end
|
20
20
|
# end
|
21
21
|
#
|
22
|
-
# @see
|
22
|
+
# @see https://www.w3.org/TR/REC-rdf-syntax/
|
23
23
|
module RDFXML
|
24
24
|
##
|
25
25
|
# RDF/XML format specification.
|
@@ -45,6 +45,10 @@ module RDF::Raptor
|
|
45
45
|
# Raptor guess is not fully supported
|
46
46
|
sample.match(/<(\w+:)?(RDF)/)
|
47
47
|
end
|
48
|
+
|
49
|
+
def self.symbols
|
50
|
+
[:rdfxml, :rdf]
|
51
|
+
end
|
48
52
|
end # Format
|
49
53
|
|
50
54
|
##
|
data/lib/rdf/raptor/turtle.rb
CHANGED
@@ -19,7 +19,7 @@ module RDF::Raptor
|
|
19
19
|
# end
|
20
20
|
# end
|
21
21
|
#
|
22
|
-
# @see
|
22
|
+
# @see https://www.w3.org/TeamSubmission/turtle/
|
23
23
|
module Turtle
|
24
24
|
##
|
25
25
|
# Turtle format specification.
|
@@ -40,6 +40,37 @@ module RDF::Raptor
|
|
40
40
|
|
41
41
|
reader { RDF::Raptor::Turtle::Reader }
|
42
42
|
writer { RDF::Raptor::Turtle::Writer }
|
43
|
+
|
44
|
+
##
|
45
|
+
# Sample detection to see if it matches Turtle (or N-Triples)
|
46
|
+
#
|
47
|
+
# Use a text sample to detect the format of an input file. Sub-classes implement
|
48
|
+
# a matcher sufficient to detect probably format matches, including disambiguating
|
49
|
+
# between other similar formats.
|
50
|
+
#
|
51
|
+
# @param [String] sample Beginning several bytes (~ 1K) of input.
|
52
|
+
# @return [Boolean]
|
53
|
+
def self.detect(sample)
|
54
|
+
!!sample.match(%r(
|
55
|
+
(?:@(base|prefix)) | # Turtle keywords
|
56
|
+
["']{3} | # STRING_LITERAL_LONG_SINGLE_QUOTE/2
|
57
|
+
"[^"]*"^^ | "[^"]*"@ | # Typed/Language literals
|
58
|
+
(?:
|
59
|
+
(?:\s*(?:(?:<[^>]*>) | (?:\w*:\w+) | (?:"[^"]*"))\s*[,;]) ||
|
60
|
+
(?:\s*(?:(?:<[^>]*>) | (?:\w*:\w+) | (?:"[^"]*"))){3}
|
61
|
+
)
|
62
|
+
)mx) && !(
|
63
|
+
sample.match(%r([{}])) || # TriG
|
64
|
+
sample.match(%r(@keywords|=>|\{)) || # N3
|
65
|
+
sample.match(%r(<(?:\/|html|rdf))i) || # HTML, RDF/XML
|
66
|
+
sample.match(%r(^(?:\s*<[^>]*>){4}.*\.\s*$)) || # N-Quads
|
67
|
+
sample.match(%r("@(context|subject|iri)")) # JSON-LD
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.symbols
|
72
|
+
[:turtle, :ttl]
|
73
|
+
end
|
43
74
|
end # Format
|
44
75
|
|
45
76
|
##
|
data/lib/rdf/raptor/version.rb
CHANGED
data/lib/rdf/raptor.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'rdf' # @see
|
1
|
+
require 'rdf' # @see https://rubygems.org/gems/rdf
|
2
2
|
require 'rdf/raptor/format'
|
3
3
|
|
4
4
|
module RDF
|
@@ -72,12 +72,12 @@ module RDF
|
|
72
72
|
# `RDF_RAPTOR_BINPATH` environment variables appropriately before
|
73
73
|
# requiring `rdf/raptor`.
|
74
74
|
#
|
75
|
-
# @see
|
76
|
-
# @see
|
77
|
-
# @see
|
75
|
+
# @see https://www.rubydoc.info/github/ruby-rdf/rdf/
|
76
|
+
# @see https://librdf.org/raptor/
|
77
|
+
# @see https://wiki.github.com/ffi/ffi/
|
78
78
|
#
|
79
|
-
# @author [Arto Bendiken](
|
80
|
-
# @author [John Fieber](
|
79
|
+
# @author [Arto Bendiken](https://github.com/artob)
|
80
|
+
# @author [John Fieber](https://github.com/jfieber)
|
81
81
|
module Raptor
|
82
82
|
LIBRAPTOR = ENV['RDF_RAPTOR_LIBPATH'] || ['libraptor2', 'libraptor2.so.0'] unless const_defined?(:LIBRAPTOR)
|
83
83
|
RAPPER = ENV['RDF_RAPTOR_BINPATH'] || 'rapper' unless const_defined?(:RAPPER)
|