rdf 1.0.10.2 → 1.1.0.p0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +8 -8
  2. data/CREDITS +0 -2
  3. data/README +67 -20
  4. data/VERSION +1 -1
  5. data/etc/doap.nt +75 -75
  6. data/lib/rdf.rb +15 -64
  7. data/lib/rdf/format.rb +11 -20
  8. data/lib/rdf/mixin/countable.rb +4 -11
  9. data/lib/rdf/mixin/enumerable.rb +4 -8
  10. data/lib/rdf/mixin/mutable.rb +1 -4
  11. data/lib/rdf/mixin/queryable.rb +13 -60
  12. data/lib/rdf/model/graph.rb +46 -22
  13. data/lib/rdf/model/list.rb +27 -102
  14. data/lib/rdf/model/literal.rb +48 -100
  15. data/lib/rdf/model/literal/date.rb +1 -1
  16. data/lib/rdf/model/literal/datetime.rb +1 -35
  17. data/lib/rdf/model/literal/decimal.rb +0 -30
  18. data/lib/rdf/model/literal/double.rb +6 -14
  19. data/lib/rdf/model/literal/integer.rb +3 -11
  20. data/lib/rdf/model/literal/numeric.rb +0 -40
  21. data/lib/rdf/model/literal/time.rb +4 -3
  22. data/lib/rdf/model/node.rb +1 -3
  23. data/lib/rdf/model/statement.rb +7 -47
  24. data/lib/rdf/model/term.rb +9 -0
  25. data/lib/rdf/model/uri.rb +28 -68
  26. data/lib/rdf/model/value.rb +1 -31
  27. data/lib/rdf/nquads.rb +4 -7
  28. data/lib/rdf/ntriples.rb +2 -2
  29. data/lib/rdf/ntriples/format.rb +1 -2
  30. data/lib/rdf/ntriples/reader.rb +15 -68
  31. data/lib/rdf/ntriples/writer.rb +13 -53
  32. data/lib/rdf/query.rb +1 -8
  33. data/lib/rdf/query/pattern.rb +25 -7
  34. data/lib/rdf/query/solution.rb +3 -19
  35. data/lib/rdf/query/solutions.rb +4 -22
  36. data/lib/rdf/query/variable.rb +1 -3
  37. data/lib/rdf/reader.rb +8 -22
  38. data/lib/rdf/repository.rb +23 -5
  39. data/lib/rdf/transaction.rb +19 -8
  40. data/lib/rdf/util/aliasing.rb +3 -13
  41. data/lib/rdf/util/cache.rb +2 -3
  42. data/lib/rdf/util/file.rb +5 -15
  43. data/lib/rdf/vocab.rb +19 -20
  44. data/lib/rdf/writer.rb +5 -44
  45. metadata +12 -27
  46. data/lib/rdf/vocab/schema.rb +0 -652
@@ -4,13 +4,13 @@ module RDF; class Query
4
4
  #
5
5
  # @example Filtering solutions using a hash
6
6
  # solutions.filter(:author => RDF::URI("http://ar.to/#self"))
7
- # solutions.filter(:author => "Gregg Kellogg")
8
- # solutions.filter(:author => [RDF::URI("http://ar.to/#self"), "Gregg Kellogg"])
7
+ # solutions.filter(:author => "Arto Bendiken")
8
+ # solutions.filter(:author => [RDF::URI("http://ar.to/#self"), "Arto Bendiken"])
9
9
  # solutions.filter(:updated => RDF::Literal(Date.today))
10
10
  #
11
11
  # @example Filtering solutions using a block
12
12
  # solutions.filter { |solution| solution.author.literal? }
13
- # solutions.filter { |solution| solution.title.to_s =~ /^SPARQL/ }
13
+ # solutions.filter { |solution| solution.title =~ /^SPARQL/ }
14
14
  # solutions.filter { |solution| solution.price < 30.5 }
15
15
  # solutions.filter { |solution| solution.bound?(:date) }
16
16
  # solutions.filter { |solution| solution.age.datatype == RDF::XSD.integer }
@@ -93,11 +93,7 @@ module RDF; class Query
93
93
  self.reject! do |solution|
94
94
  solution = solution.is_a?(Solution) ? solution : Solution.new(solution)
95
95
  results = criteria.map do |name, value|
96
- case value
97
- when Array then value.any? {|v| solution[name] == v}
98
- when Regexp then solution[name].to_s.match(value)
99
- else solution[name] == value
100
- end
96
+ solution[name] == value
101
97
  end
102
98
  !results.all?
103
99
  end
@@ -106,20 +102,6 @@ module RDF; class Query
106
102
  end
107
103
  alias_method :filter!, :filter
108
104
 
109
- ##
110
- # Difference between solution sets, from SPARQL 1.1.
111
- #
112
- # The `minus` operation on solutions returns those solutions which either have no compatible solution in `other`, or the solution domains are disjoint.
113
- #
114
- # @param [RDF::Query::Solutions] other
115
- # @return [RDF::Query::Solutions] a new solution set
116
- # @see http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#defn_algMinus
117
- def minus(other)
118
- self.dup.filter! do |soln|
119
- !other.any? {|soln2| soln.compatible?(soln2) && !soln.disjoint?(soln2)}
120
- end
121
- end
122
-
123
105
  ##
124
106
  # Reorders this solution sequence by the given `variables`.
125
107
  #
@@ -12,7 +12,7 @@ class RDF::Query
12
12
  # var.name #=> :g2166151240
13
13
  #
14
14
  # @example Unbound variables match any value
15
- # var === RDF::Literal(42) #=> true
15
+ # var === 42 #=> true
16
16
  #
17
17
  # @example Creating a bound variable
18
18
  # var = RDF::Query::Variable.new(:y, 123)
@@ -20,12 +20,10 @@ class RDF::Query
20
20
  # var.value #=> 123
21
21
  #
22
22
  # @example Bound variables match only their actual value
23
- # var = RDF::Query::Variable.new(:y, 123)
24
23
  # var === 42 #=> false
25
24
  # var === 123 #=> true
26
25
  #
27
26
  # @example Getting the variable name
28
- # var = RDF::Query::Variable.new(:y, 123)
29
27
  # var.named? #=> true
30
28
  # var.name #=> :y
31
29
  # var.to_sym #=> :y
@@ -168,7 +168,7 @@ module RDF
168
168
  # @param [Hash{Symbol => Object}] options
169
169
  # any additional options
170
170
  # @option options [Encoding] :encoding (Encoding::UTF_8)
171
- # the encoding of the input stream (Ruby 1.9+)
171
+ # the encoding of the input stream
172
172
  # @option options [Boolean] :validate (false)
173
173
  # whether to validate the parsed statements and values
174
174
  # @option options [Boolean] :canonicalize (false)
@@ -189,7 +189,6 @@ module RDF
189
189
  @options[:canonicalize] ||= false
190
190
  @options[:intern] ||= true
191
191
  @options[:prefixes] ||= Hash.new
192
- @options[:base_uri] ||= input.base_uri if input.respond_to?(:base_uri)
193
192
 
194
193
  @input = case input
195
194
  when String then StringIO.new(input)
@@ -363,13 +362,6 @@ module RDF
363
362
  end
364
363
  alias_method :close!, :close
365
364
 
366
- ##
367
- # Current line number being processed. For formats that can associate generated {Statement} with a particular line number from input, this value reflects that line number.
368
- # @return [Integer]
369
- def lineno
370
- @input.lineno
371
- end
372
-
373
365
  protected
374
366
 
375
367
  ##
@@ -422,8 +414,6 @@ module RDF
422
414
  ##
423
415
  # Returns the encoding of the input stream.
424
416
  #
425
- # _Note: this method requires Ruby 1.9 or newer._
426
- #
427
417
  # @return [Encoding]
428
418
  def encoding
429
419
  case @options[:encoding]
@@ -475,6 +465,12 @@ module RDF
475
465
  super
476
466
  end
477
467
 
468
+ ##
469
+ # @return [Integer]
470
+ def lineno
471
+ @input.lineno
472
+ end
473
+
478
474
  ##
479
475
  # @private
480
476
  # @return [String] The most recently read line of the input
@@ -488,17 +484,7 @@ module RDF
488
484
  @line = @line_rest || @input.readline
489
485
  @line, @line_rest = @line.split("\r", 2)
490
486
  @line = @line.to_s.chomp
491
- begin
492
- @line.encode!(encoding) if @line.respond_to?(:encode!)
493
- rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError, Encoding::ConverterNotFoundError
494
- # It is likely the persisted line was not encoded on initial write
495
- # (i.e. persisted via RDF <= 1.0.9 and read via RDF >= 1.0.10)
496
- #
497
- # Encoding::UndefinedConversionError is raised by MRI.
498
- # Encoding::InvalidByteSequenceError is raised by jruby >= 1.7.5
499
- # Encoding::ConverterNotFoundError is raised by jruby < 1.7.5
500
- @line = RDF::NTriples::Reader.unescape(@line).encode(encoding)
501
- end
487
+ @line.force_encoding(encoding)
502
488
  @line
503
489
  end
504
490
 
@@ -77,7 +77,7 @@ module RDF
77
77
  # @return [void]
78
78
  def self.load(filenames, options = {}, &block)
79
79
  self.new(options) do |repository|
80
- Array(filenames).each do |filename|
80
+ [filenames].flatten.each do |filename|
81
81
  repository.load(filename, options)
82
82
  end
83
83
 
@@ -96,10 +96,13 @@ module RDF
96
96
  # @param [Hash{Symbol => Object}] options
97
97
  # @option options [URI, #to_s] :uri (nil)
98
98
  # @option options [String, #to_s] :title (nil)
99
+ # @option options [Boolean] :with_context (true)
100
+ # Indicates that the repository supports named graphs, otherwise,
101
+ # only the default graph is supported.
99
102
  # @yield [repository]
100
103
  # @yieldparam [Repository] repository
101
104
  def initialize(options = {}, &block)
102
- @options = options.dup
105
+ @options = {:with_context => true}.merge(options)
103
106
  @uri = @options.delete(:uri)
104
107
  @title = @options.delete(:title)
105
108
 
@@ -141,6 +144,8 @@ module RDF
141
144
  # end
142
145
  #
143
146
  # @param [RDF::Resource] context
147
+ # Context on which to run the transaction, use `false` for the default
148
+ # context and `nil` the entire Repository
144
149
  # @yield [tx]
145
150
  # @yieldparam [RDF::Transaction] tx
146
151
  # @yieldreturn [void] ignored
@@ -176,7 +181,7 @@ module RDF
176
181
  # @return [RDF::Transaction]
177
182
  # @since 0.3.0
178
183
  def begin_transaction(context)
179
- RDF::Transaction.new(:context => context)
184
+ RDF::Transaction.new(:graph => context)
180
185
  end
181
186
 
182
187
  ##
@@ -221,10 +226,11 @@ module RDF
221
226
 
222
227
  ##
223
228
  # @private
224
- # @see RDF::Readable#supports?
229
+ # @see RDF::Enumerable#supports?
225
230
  def supports?(feature)
226
231
  case feature.to_sym
227
- when :context then true # statement contexts / named graphs
232
+ # statement contexts / named graphs
233
+ when :context then @options[:with_context]
228
234
  when :inference then false # forward-chaining inference
229
235
  else false
230
236
  end
@@ -237,6 +243,13 @@ module RDF
237
243
  false
238
244
  end
239
245
 
246
+ ##
247
+ # @private
248
+ # @see RDF::Countable#empty?
249
+ def empty?
250
+ @data.empty?
251
+ end
252
+
240
253
  ##
241
254
  # @private
242
255
  # @see RDF::Countable#count
@@ -344,6 +357,7 @@ module RDF
344
357
  def insert_statement(statement)
345
358
  unless has_statement?(statement)
346
359
  s, p, o, c = statement.to_quad
360
+ c = DEFAULT_CONTEXT unless supports?(:context)
347
361
  c ||= DEFAULT_CONTEXT
348
362
  @data[c] ||= {}
349
363
  @data[c][s] ||= {}
@@ -358,6 +372,7 @@ module RDF
358
372
  def delete_statement(statement)
359
373
  if has_statement?(statement)
360
374
  s, p, o, c = statement.to_quad
375
+ c = DEFAULT_CONTEXT unless supports?(:context)
361
376
  c ||= DEFAULT_CONTEXT
362
377
  @data[c][s][p].delete(o)
363
378
  @data[c][s].delete(p) if @data[c][s][p].empty?
@@ -379,4 +394,7 @@ module RDF
379
394
  protected :clear_statements
380
395
  end # Implementation
381
396
  end # Repository
397
+
398
+ # RDF::Dataset is a synonym for RDF::Repository
399
+ Dataset = Repository
382
400
  end # RDF
@@ -5,6 +5,10 @@ module RDF
5
5
  # Transactions consist of a sequence of RDF statements to delete from and
6
6
  # a sequence of RDF statements to insert into a given named graph.
7
7
  #
8
+ # Repository implementations may choose to sub-class this class
9
+ # to provide transactional support for repository updates, when
10
+ # accessed through {RDF::Repository#begin_transaction}.
11
+ #
8
12
  # @example Executing a transaction against a repository
9
13
  # repository = ...
10
14
  # RDF::Transaction.execute(repository) do |tx|
@@ -30,10 +34,14 @@ module RDF
30
34
  end
31
35
 
32
36
  ##
33
- # RDF graph to modify when executed.
34
- #
37
+ # Name of this graph, if it is part of an {RDF::Repository}
38
+ # @!attribute [rw] context
35
39
  # @return [RDF::Resource]
36
- attr_reader :graph
40
+ # @since 1.1.0
41
+ attr_accessor :context
42
+
43
+ alias_method :graph, :context
44
+ alias_method :graph=, :context=
37
45
 
38
46
  ##
39
47
  # RDF statements to delete when executed.
@@ -57,14 +65,18 @@ module RDF
57
65
  # Initializes this transaction.
58
66
  #
59
67
  # @param [Hash{Symbol => Object}] options
68
+ # @option options [RDF::Resource] :context (nil)
69
+ # Name of named graph to be affected if `inserts` or `deletes`
70
+ # do not have a `context`.
60
71
  # @option options [RDF::Resource] :graph (nil)
72
+ # Alias for `:context`.
61
73
  # @option options [RDF::Enumerable] :insert (RDF::Graph.new)
62
74
  # @option options [RDF::Enumerable] :delete (RDF::Graph.new)
63
75
  # @yield [tx]
64
76
  # @yieldparam [RDF::Transaction] tx
65
77
  def initialize(options = {}, &block)
66
78
  @options = options.dup
67
- @graph = @options.delete(:graph) || @options.delete(:context)
79
+ @context = @options.delete(:graph) || @options.delete(:context)
68
80
  @inserts = @options.delete(:insert) || RDF::Graph.new
69
81
  @deletes = @options.delete(:delete) || RDF::Graph.new
70
82
  @inserts.extend(RDF::Enumerable) unless @inserts.kind_of?(RDF::Enumerable)
@@ -102,13 +114,13 @@ module RDF
102
114
 
103
115
  deletes.each_statement do |statement|
104
116
  statement = statement.dup
105
- statement.context = graph
117
+ statement.context ||= graph
106
118
  repository.delete(statement)
107
119
  end
108
120
 
109
121
  inserts.each_statement do |statement|
110
122
  statement = statement.dup
111
- statement.context = graph
123
+ statement.context ||= graph
112
124
  repository.insert(statement)
113
125
  end
114
126
 
@@ -134,6 +146,7 @@ module RDF
134
146
  warn(inspect)
135
147
  end
136
148
 
149
+ protected
137
150
  ##
138
151
  # Appends an RDF statement to the sequence to insert when executed.
139
152
  #
@@ -155,7 +168,5 @@ module RDF
155
168
  end
156
169
 
157
170
  undef_method :load, :update, :clear
158
- protected :insert_statement
159
- protected :delete_statement
160
171
  end # Transaction
161
172
  end # RDF
@@ -42,19 +42,9 @@ module RDF; module Util
42
42
  def alias_method(new_name, old_name)
43
43
  new_name, old_name = new_name.to_sym, old_name.to_sym
44
44
 
45
- class_eval(<<-EOF)
46
- def #{new_name}(*args, &block)
47
- #{old_name}(*args, &block)
48
- end
49
- EOF
50
-
51
- # NOTE: the following eval-less (and hence slightly less evil)
52
- # implementation only works on Ruby 1.8.7+ due to the |&block|
53
- # syntax that was introduced in 1.9 and then backported to 1.8.7;
54
- # it is a syntax error in earlier versions of Ruby:
55
- #self.__send__(:define_method, new_name) do |*args, &block|
56
- # __send__(old_name, *args, &block)
57
- #end
45
+ self.__send__(:define_method, new_name) do |*args, &block|
46
+ __send__(old_name, *args, &block)
47
+ end
58
48
 
59
49
  return self
60
50
  end
@@ -56,7 +56,7 @@ module RDF; module Util
56
56
 
57
57
  ##
58
58
  # This implementation relies on `ObjectSpace#_id2ref` and performs
59
- # optimally on Ruby 1.8.x and 1.9.x; however, it does not work on JRuby
59
+ # optimally on Ruby >= 1.9.x; however, it does not work on JRuby
60
60
  # by default since much `ObjectSpace` functionality on that platform is
61
61
  # disabled unless the `-X+O` startup option is given.
62
62
  #
@@ -89,8 +89,7 @@ module RDF; module Util
89
89
 
90
90
  ##
91
91
  # This implementation uses the `WeakRef` class from Ruby's standard
92
- # library, and provides adequate performance on JRuby and on Ruby 1.9.x;
93
- # however, it performs very suboptimally on Ruby 1.8.x.
92
+ # library, and provides adequate performance on JRuby and on Ruby 1.9.x.
94
93
  #
95
94
  # @see http://ruby-doc.org/ruby-1.9/classes/WeakRef.html
96
95
  class WeakRefCache < Cache
@@ -27,26 +27,16 @@ module RDF; module Util
27
27
  # @param [Hash{Symbol => Object}] options
28
28
  # options are ignored in this implementation. Applications are encouraged
29
29
  # to override this implementation to provide more control over HTTP
30
- # headers and redirect following. If opening as a file,
31
- # options are passed to `Kernel.open`.
30
+ # headers and redirect following.
32
31
  # @option options [Array, String] :headers
33
- # HTTP Request headers, passed to Kernel.open. (Ruby >= 1.9 only)
32
+ # HTTP Request headers, passed to Kernel.open.
34
33
  # @return [IO] File stream
35
34
  # @yield [IO] File stream
36
- # @note HTTP headers not passed to `Kernel.open` for Ruby versions < 1.9.
37
35
  def self.open_file(filename_or_url, options = {}, &block)
38
36
  filename_or_url = $1 if filename_or_url.to_s.match(/^file:(.*)$/)
39
- if RUBY_VERSION < "1.9"
40
- Kernel.open(filename_or_url.to_s, &block)
41
- elsif filename_or_url.to_s =~ /^#{RDF::URI::SCHEME}/
42
- # Open as a URL
43
- headers = options.fetch(:headers, {})
44
- headers['Accept'] ||= (RDF::Format.reader_types + %w(*/*;q=0.1)).join(", ")
45
- Kernel.open(filename_or_url.to_s, headers, &block)
46
- else
47
- # Open as a file, passing any options
48
- Kernel.open(filename_or_url, "r", options, &block)
49
- end
37
+ options[:headers] ||= {}
38
+ options[:headers]['Accept'] ||= (RDF::Format.reader_types + %w(*/*;q=0.1)).join(", ")
39
+ Kernel.open(filename_or_url.to_s, options[:headers], &block)
50
40
  end
51
41
  end # File
52
42
  end; end # RDF::Util
@@ -6,26 +6,25 @@ module RDF
6
6
  #
7
7
  # The following vocabularies are pre-defined for your convenience:
8
8
  #
9
- # * {RDF} - Resource Description Framework (RDF)
10
- # * {RDF::CC} - Creative Commons (CC)
11
- # * {RDF::CERT} - W3 Authentication Certificate (CERT)
12
- # * {RDF::DC} - Dublin Core (DC)
13
- # * {RDF::DC11} - Dublin Core 1.1 (DC11) _deprecated_
14
- # * {RDF::DOAP} - Description of a Project (DOAP)
15
- # * {RDF::EXIF} - Exchangeable Image File Format (EXIF)
16
- # * {RDF::FOAF} - Friend of a Friend (FOAF)
17
- # * {RDF::GEO} - WGS84 Geo Positioning (GEO)
18
- # * {RDF::HTTP} - Hypertext Transfer Protocol (HTTP)
19
- # * {RDF::OWL} - Web Ontology Language (OWL)
20
- # * {RDF::RDFS} - RDF Schema (RDFS)
21
- # * {RDF::RSA} - W3 RSA Keys (RSA)
22
- # * {RDF::RSS} - RDF Site Summary (RSS)
23
- # * {RDF::SCHEMA} - Schema.org
24
- # * {RDF::SIOC} - Semantically-Interlinked Online Communities (SIOC)
25
- # * {RDF::SKOS} - Simple Knowledge Organization System (SKOS)
26
- # * {RDF::WOT} - Web of Trust (WOT)
27
- # * {RDF::XHTML} - Extensible HyperText Markup Language (XHTML)
28
- # * {RDF::XSD} - XML Schema (XSD)
9
+ # * {RDF} - Resource Description Framework (RDF)
10
+ # * {RDF::CC} - Creative Commons (CC)
11
+ # * {RDF::CERT} - W3 Authentication Certificate (CERT)
12
+ # * {RDF::DC} - Dublin Core (DC)
13
+ # * {RDF::DC11} - Dublin Core 1.1 (DC11) _deprecated_
14
+ # * {RDF::DOAP} - Description of a Project (DOAP)
15
+ # * {RDF::EXIF} - Exchangeable Image File Format (EXIF)
16
+ # * {RDF::FOAF} - Friend of a Friend (FOAF)
17
+ # * {RDF::GEO} - WGS84 Geo Positioning (GEO)
18
+ # * {RDF::HTTP} - Hypertext Transfer Protocol (HTTP)
19
+ # * {RDF::OWL} - Web Ontology Language (OWL)
20
+ # * {RDF::RDFS} - RDF Schema (RDFS)
21
+ # * {RDF::RSA} - W3 RSA Keys (RSA)
22
+ # * {RDF::RSS} - RDF Site Summary (RSS)
23
+ # * {RDF::SIOC} - Semantically-Interlinked Online Communities (SIOC)
24
+ # * {RDF::SKOS} - Simple Knowledge Organization System (SKOS)
25
+ # * {RDF::WOT} - Web of Trust (WOT)
26
+ # * {RDF::XHTML} - Extensible HyperText Markup Language (XHTML)
27
+ # * {RDF::XSD} - XML Schema (XSD)
29
28
  #
30
29
  # @example Using pre-defined RDF vocabularies
31
30
  # include RDF
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  module RDF
3
2
  ##
4
3
  # The base class for RDF serializers.
@@ -106,18 +105,13 @@ module RDF
106
105
  ##
107
106
  # @param [RDF::Enumerable, #each] data
108
107
  # the graph or repository to dump
109
- # @param [IO, File, String] io
108
+ # @param [IO, File] io
110
109
  # the output stream or file to write to
111
110
  # @param [Hash{Symbol => Object}] options
112
111
  # passed to {RDF::Writer#initialize} or {RDF::Writer.buffer}
113
112
  # @return [void]
114
113
  def self.dump(data, io = nil, options = {})
115
- if io.is_a?(String)
116
- io = File.open(io, 'w')
117
- elsif io.respond_to?(:external_encoding) && io.external_encoding
118
- options = {:encoding => io.external_encoding}.merge(options)
119
- end
120
- io.set_encoding(options[:encoding]) if io.respond_to?(:set_encoding) && options[:encoding]
114
+ io = File.open(io, 'w') if io.is_a?(String)
121
115
  method = data.respond_to?(:each_statement) ? :each_statement : :each
122
116
  if io
123
117
  new(io, options) do |writer|
@@ -144,11 +138,9 @@ module RDF
144
138
  # @return [String]
145
139
  # @raise [ArgumentError] if no block is provided
146
140
  def self.buffer(*args, &block)
147
- options = args.last.is_a?(Hash) ? args.last : {}
148
141
  raise ArgumentError, "block expected" unless block_given?
149
142
 
150
143
  StringIO.open do |buffer|
151
- buffer.set_encoding(options[:encoding]) if buffer.respond_to?(:set_encoding) && options[:encoding]
152
144
  self.new(buffer, *args) { |writer| block.call(writer) }
153
145
  buffer.string
154
146
  end
@@ -164,7 +156,6 @@ module RDF
164
156
  # @return [RDF::Writer]
165
157
  def self.open(filename, options = {}, &block)
166
158
  File.open(filename, 'wb') do |file|
167
- file.set_encoding(options[:encoding]) if file.respond_to?(:set_encoding) && options[:encoding]
168
159
  format_options = options.dup
169
160
  format_options[:file_name] ||= filename
170
161
  self.for(options[:format] || format_options).new(file, options, &block)
@@ -196,12 +187,10 @@ module RDF
196
187
  # @param [Hash{Symbol => Object}] options
197
188
  # any additional options
198
189
  # @option options [Encoding, String, Symbol] :encoding
199
- # the encoding to use on the output stream (Ruby 1.9+).
190
+ # the encoding to use on the output stream.
200
191
  # Defaults to the format associated with `content_encoding`.
201
192
  # @option options [Boolean] :canonicalize (false)
202
- # whether to canonicalize terms when serializing
203
- # @option options [Boolean] :validate (false)
204
- # whether to validate terms when serializing
193
+ # whether to canonicalize literals when serializing
205
194
  # @option options [Hash] :prefixes (Hash.new)
206
195
  # the prefix mappings to use (not supported by all writers)
207
196
  # @option options [#to_s] :base_uri (nil)
@@ -296,11 +285,8 @@ module RDF
296
285
  ##
297
286
  # Returns the encoding of the output stream.
298
287
  #
299
- # _Note: this method requires Ruby 1.9 or newer._
300
- #
301
288
  # @return [Encoding]
302
289
  def encoding
303
- return nil unless "".respond_to?(:encode)
304
290
  case @options[:encoding]
305
291
  when String, Symbol
306
292
  Encoding.find(@options[:encoding].to_s)
@@ -311,24 +297,6 @@ module RDF
311
297
  end
312
298
  end
313
299
 
314
- ##
315
- # Returns `true` if statements and terms should be validated.
316
- #
317
- # @return [Boolean] `true` or `false`
318
- # @since 1.0.8
319
- def validate?
320
- @options[:validate]
321
- end
322
-
323
- ##
324
- # Returns `true` if terms should be canonicalized.
325
- #
326
- # @return [Boolean] `true` or `false`
327
- # @since 1.0.8
328
- def canonicalize?
329
- @options[:canonicalize]
330
- end
331
-
332
300
  ##
333
301
  # Flushes the underlying output buffer.
334
302
  #
@@ -382,21 +350,15 @@ module RDF
382
350
  ##
383
351
  # @param [RDF::Statement] statement
384
352
  # @return [void] `self`
385
- # @raise [RDF::WriterError] if validating and attempting to write an invalid {RDF::Statement} or if canonicalizing a statement which cannot be canonicalized.
386
353
  def write_statement(statement)
387
- statement = statement.canonicalize! if canonicalize?
388
- raise RDF::WriterError, "Statement #{statement.inspect} is invalid" if validate? && statement.invalid?
389
354
  write_triple(*statement.to_triple)
390
355
  self
391
- rescue ArgumentError => e
392
- raise WriterError, e.message
393
356
  end
394
357
  alias_method :insert_statement, :write_statement # support the RDF::Writable interface
395
358
 
396
359
  ##
397
360
  # @param [Array<Array(RDF::Resource, RDF::URI, RDF::Term)>] triples
398
361
  # @return [void] `self`
399
- # @raise [RDF::WriterError] if validating and attempting to write an invalid {RDF::Term}.
400
362
  def write_triples(*triples)
401
363
  triples.each { |triple| write_triple(*triple) }
402
364
  self
@@ -408,7 +370,6 @@ module RDF
408
370
  # @param [RDF::Term] object
409
371
  # @return [void] `self`
410
372
  # @raise [NotImplementedError] unless implemented in subclass
411
- # @raise [RDF::WriterError] if validating and attempting to write an invalid {RDF::Term}.
412
373
  # @abstract
413
374
  def write_triple(subject, predicate, object)
414
375
  raise NotImplementedError.new("#{self.class}#write_triple") # override in subclasses
@@ -475,7 +436,7 @@ module RDF
475
436
  ##
476
437
  # @return [void]
477
438
  def puts(*args)
478
- @output.puts(*args.map {|s| s.respond_to?(:encode) ? s.encode(encoding) : s})
439
+ @output.puts(*args)
479
440
  end
480
441
 
481
442
  ##