rdf-raptor 1.99.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5ae888c81773bd00155b708856b8120550a8d4a
4
- data.tar.gz: 585cb977bc2f5850249bc4874de401a2864d17f8
3
+ metadata.gz: 1f524bedbbad075002013ef85da611107b1fbc9c
4
+ data.tar.gz: c6588defdb51badb022569508b072cc6e16e1482
5
5
  SHA512:
6
- metadata.gz: 322d066746c0bf42d28c804e36c86ea9bea5269bbcdf2378054c7c454501e0d25953887373cf53f003a453dddc9c4614e495c31e1bea105a164d5443702f08e5
7
- data.tar.gz: c07b84899ecbcfa949d06c4a589b5effa63eadb7a4656499defaec1622ec4f51633a9b80f45481ddc0ce1154cf8c5dd570682521eeb5db4de4fbccb11e5756a8
6
+ metadata.gz: 0253224a82c7202453af159b3fba9941791a4647a5314bdbbe6e5a6eb7ba325a61ddc8e7420d03de46eb2f1998ae833fd35bbd3314833f30acbb4b19723618e9
7
+ data.tar.gz: 0d5b7581ad861980985e47905d4470c2be745d4f644270a258443a07cb65656dcbae1ed0e8a758496bf29264e5131ef4a32bac9a2b1c2e5ea25a64bfb136c777
data/README CHANGED
@@ -20,7 +20,7 @@ Features
20
20
  * Serializes RDF statements into Graphviz format.
21
21
  * Provides serialization format autodetection for RDF/XML, Turtle and RDFa.
22
22
  * Compatible with any operating system supported by Raptor and Ruby.
23
- * Compatible with MRI 1.8.x, 1.9.x, 2.x, REE, JRuby and Rubinius (1.8 and 1.9 mode).
23
+ * Compatible with MRI 2.x, REE, JRuby and Rubinius.
24
24
 
25
25
  Examples
26
26
  --------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.99.0
1
+ 2.0.0
@@ -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
  #
@@ -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
- raise RDF::ReaderError, line > -1 ? "Line #{line}: #{message}" : message
59
+ log_error(message, lineno: line)
58
60
  end
59
61
 
60
62
  WARNING_HANDLER = Proc.new do |user_data, locator, message|
61
- # line = V2.raptor_locator_line(locator)
62
- # $stderr.puts line > -1 ? "Line #{line}: #{message}" : message
63
+ line = V2.raptor_locator_line(locator)
64
+ log_warn(message, lineno: line)
63
65
  end
64
66
 
65
67
  ##
@@ -85,6 +87,10 @@ 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
95
  enum_for(:each_statement, options)
90
96
  end
@@ -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
- parse(@input) do |parser, statement|
101
- block.call(V2::Statement.new(statement, self).to_triple)
106
+ each_statement do |statement|
107
+ block.call(*statement.to_triple)
102
108
  end
103
109
  end
104
110
  enum_for(:each_triple)
@@ -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
  #
@@ -151,18 +159,18 @@ module RDF::Raptor
151
159
  def initialize(output = $stdout, options = {}, &block)
152
160
  @format = self.class.format.rapper_format
153
161
  @serializer = V2::Serializer.new(@format)
154
- #@serializer.error_handler = ERROR_HANDLER
155
- #@serializer.warning_handler = WARNING_HANDLER
162
+ @serializer.error_handler = ERROR_HANDLER
163
+ @serializer.warning_handler = WARNING_HANDLER
156
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
- raise RDF::WriterError, message
169
+ log_error(message)
162
170
  end
163
171
 
164
172
  WARNING_HANDLER = Proc.new do |user_data, locator, message|
165
- # $stderr.puts "warning"
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
@@ -28,6 +28,7 @@ module RDF::Raptor::FFI
28
28
  # @see http://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
@@ -77,6 +78,7 @@ 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
83
  # @see http://librdf.org/raptor/api/raptor2-section-xml-namespace.html
82
84
  typedef :pointer, :raptor_namespace
@@ -106,7 +108,6 @@ module RDF::Raptor::FFI
106
108
  attach_function :raptor_free_parser, [:raptor_parser], :void
107
109
 
108
110
  # @see http://librdf.org/raptor/api/raptor2-section-iostream.html
109
- typedef :pointer, :raptor_iostream
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
@@ -7,6 +7,8 @@ module RDF::Raptor::FFI::V2
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
  ##
@@ -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
@@ -27,11 +27,32 @@ module RDF::Raptor
27
27
  class Format < RDF::Format
28
28
  extend RDF::Raptor::Format
29
29
 
30
- content_type 'application/xhtml+xml', aliases: ['text/html'], extension: :html
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
  ##
@@ -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
  ##
@@ -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
  ##
@@ -14,6 +14,6 @@ module RDF; module Raptor
14
14
 
15
15
  ##
16
16
  # @return [Array(Integer, Integer, Integer)]
17
- def self.to_a() [MAJOR, MINOR, TINY] end
17
+ def self.to_a() STRING.split(".") end
18
18
  end
19
19
  end; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-raptor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.99.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arto Bendiken
@@ -9,106 +9,106 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-30 00:00:00.000000000 Z
12
+ date: 2016-04-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 1.9.3
20
+ version: 1.9.10
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 1.9.3
27
+ version: 1.9.10
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rdf
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ">="
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '1.99'
34
+ version: '2.0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">="
39
+ - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '1.99'
41
+ version: '2.0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: yard
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: 0.8.6
48
+ version: '0.8'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: 0.8.6
55
+ version: '0.8'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rspec
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ">="
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: 2.14.0
62
+ version: '3.2'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ">="
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: 2.14.0
69
+ version: '3.2'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rspec-its
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ">="
74
+ - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '0'
76
+ version: '1.2'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ">="
81
+ - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '0'
83
+ version: '1.2'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: rdf-spec
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - ">="
88
+ - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: '1.99'
90
+ version: '2.0'
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - ">="
95
+ - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '1.99'
97
+ version: '2.0'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: rake
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ">="
102
+ - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '0'
104
+ version: '10.0'
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - ">="
109
+ - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: '0'
111
+ version: '10.0'
112
112
  description: RDF.rb plugin for parsing/serializing NTriples, RDF/XML, Turtle and RDFa
113
113
  data using the Raptor RDF Parser library.
114
114
  email: public-rdf-ruby@w3.org
@@ -163,7 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
- version: 1.9.3
166
+ version: '2.0'
167
167
  required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  requirements:
169
169
  - - ">="
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
172
  requirements:
173
173
  - libraptor2 (>= 2.0)
174
174
  rubyforge_project: rdf
175
- rubygems_version: 2.4.5.1
175
+ rubygems_version: 2.4.8
176
176
  signing_key:
177
177
  specification_version: 4
178
178
  summary: Raptor RDF Parser plugin for RDF.rb.