openlogic-rdf 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/AUTHORS +3 -0
  2. data/CREDITS +9 -0
  3. data/README +361 -0
  4. data/UNLICENSE +24 -0
  5. data/VERSION +1 -0
  6. data/bin/rdf +18 -0
  7. data/etc/doap.nt +62 -0
  8. data/lib/df.rb +1 -0
  9. data/lib/rdf/cli.rb +200 -0
  10. data/lib/rdf/format.rb +383 -0
  11. data/lib/rdf/mixin/countable.rb +39 -0
  12. data/lib/rdf/mixin/durable.rb +31 -0
  13. data/lib/rdf/mixin/enumerable.rb +637 -0
  14. data/lib/rdf/mixin/indexable.rb +26 -0
  15. data/lib/rdf/mixin/inferable.rb +5 -0
  16. data/lib/rdf/mixin/mutable.rb +191 -0
  17. data/lib/rdf/mixin/queryable.rb +265 -0
  18. data/lib/rdf/mixin/readable.rb +15 -0
  19. data/lib/rdf/mixin/type_check.rb +21 -0
  20. data/lib/rdf/mixin/writable.rb +152 -0
  21. data/lib/rdf/model/graph.rb +263 -0
  22. data/lib/rdf/model/list.rb +731 -0
  23. data/lib/rdf/model/literal/boolean.rb +121 -0
  24. data/lib/rdf/model/literal/date.rb +73 -0
  25. data/lib/rdf/model/literal/datetime.rb +72 -0
  26. data/lib/rdf/model/literal/decimal.rb +86 -0
  27. data/lib/rdf/model/literal/double.rb +189 -0
  28. data/lib/rdf/model/literal/integer.rb +126 -0
  29. data/lib/rdf/model/literal/numeric.rb +184 -0
  30. data/lib/rdf/model/literal/time.rb +87 -0
  31. data/lib/rdf/model/literal/token.rb +47 -0
  32. data/lib/rdf/model/literal/xml.rb +39 -0
  33. data/lib/rdf/model/literal.rb +373 -0
  34. data/lib/rdf/model/node.rb +156 -0
  35. data/lib/rdf/model/resource.rb +28 -0
  36. data/lib/rdf/model/statement.rb +296 -0
  37. data/lib/rdf/model/term.rb +77 -0
  38. data/lib/rdf/model/uri.rb +570 -0
  39. data/lib/rdf/model/value.rb +133 -0
  40. data/lib/rdf/nquads.rb +152 -0
  41. data/lib/rdf/ntriples/format.rb +48 -0
  42. data/lib/rdf/ntriples/reader.rb +239 -0
  43. data/lib/rdf/ntriples/writer.rb +219 -0
  44. data/lib/rdf/ntriples.rb +104 -0
  45. data/lib/rdf/query/pattern.rb +329 -0
  46. data/lib/rdf/query/solution.rb +252 -0
  47. data/lib/rdf/query/solutions.rb +237 -0
  48. data/lib/rdf/query/variable.rb +221 -0
  49. data/lib/rdf/query.rb +404 -0
  50. data/lib/rdf/reader.rb +511 -0
  51. data/lib/rdf/repository.rb +389 -0
  52. data/lib/rdf/transaction.rb +161 -0
  53. data/lib/rdf/util/aliasing.rb +63 -0
  54. data/lib/rdf/util/cache.rb +139 -0
  55. data/lib/rdf/util/file.rb +38 -0
  56. data/lib/rdf/util/uuid.rb +36 -0
  57. data/lib/rdf/util.rb +6 -0
  58. data/lib/rdf/version.rb +19 -0
  59. data/lib/rdf/vocab/cc.rb +18 -0
  60. data/lib/rdf/vocab/cert.rb +13 -0
  61. data/lib/rdf/vocab/dc.rb +63 -0
  62. data/lib/rdf/vocab/dc11.rb +23 -0
  63. data/lib/rdf/vocab/doap.rb +45 -0
  64. data/lib/rdf/vocab/exif.rb +168 -0
  65. data/lib/rdf/vocab/foaf.rb +69 -0
  66. data/lib/rdf/vocab/geo.rb +13 -0
  67. data/lib/rdf/vocab/http.rb +26 -0
  68. data/lib/rdf/vocab/owl.rb +59 -0
  69. data/lib/rdf/vocab/rdfs.rb +17 -0
  70. data/lib/rdf/vocab/rsa.rb +12 -0
  71. data/lib/rdf/vocab/rss.rb +14 -0
  72. data/lib/rdf/vocab/sioc.rb +93 -0
  73. data/lib/rdf/vocab/skos.rb +36 -0
  74. data/lib/rdf/vocab/wot.rb +21 -0
  75. data/lib/rdf/vocab/xhtml.rb +9 -0
  76. data/lib/rdf/vocab/xsd.rb +58 -0
  77. data/lib/rdf/vocab.rb +215 -0
  78. data/lib/rdf/writer.rb +475 -0
  79. data/lib/rdf.rb +192 -0
  80. metadata +173 -0
data/lib/rdf/writer.rb ADDED
@@ -0,0 +1,475 @@
1
+ module RDF
2
+ ##
3
+ # The base class for RDF serializers.
4
+ #
5
+ # @example Loading an RDF writer implementation
6
+ # require 'rdf/ntriples'
7
+ #
8
+ # @example Iterating over known RDF writer classes
9
+ # RDF::Writer.each { |klass| puts klass.name }
10
+ #
11
+ # @example Obtaining an RDF writer class
12
+ # RDF::Writer.for(:ntriples) #=> RDF::NTriples::Writer
13
+ # RDF::Writer.for("spec/data/output.nt")
14
+ # RDF::Writer.for(:file_name => "spec/data/output.nt")
15
+ # RDF::Writer.for(:file_extension => "nt")
16
+ # RDF::Writer.for(:content_type => "text/plain")
17
+ #
18
+ # @example Instantiating an RDF writer class
19
+ # RDF::Writer.for(:ntriples).new($stdout) { |writer| ... }
20
+ #
21
+ # @example Serializing RDF statements into a file
22
+ # RDF::Writer.open("spec/data/output.nt") do |writer|
23
+ # graph.each_statement do |statement|
24
+ # writer << statement
25
+ # end
26
+ # end
27
+ #
28
+ # @example Serializing RDF statements into a string
29
+ # RDF::Writer.for(:ntriples).buffer do |writer|
30
+ # graph.each_statement do |statement|
31
+ # writer << statement
32
+ # end
33
+ # end
34
+ #
35
+ # @abstract
36
+ # @see RDF::Format
37
+ # @see RDF::Reader
38
+ class Writer
39
+ extend ::Enumerable
40
+ extend RDF::Util::Aliasing::LateBound
41
+ include RDF::Writable
42
+
43
+ ##
44
+ # Enumerates known RDF writer classes.
45
+ #
46
+ # @yield [klass]
47
+ # @yieldparam [Class] klass
48
+ # @yieldreturn [void] ignored
49
+ # @return [Enumerator]
50
+ def self.each(&block)
51
+ @@subclasses.each(&block)
52
+ end
53
+
54
+ ##
55
+ # Finds an RDF writer class based on the given criteria.
56
+ #
57
+ # @overload for(format)
58
+ # Finds an RDF writer class based on a symbolic name.
59
+ #
60
+ # @param [Symbol] format
61
+ # @return [Class]
62
+ #
63
+ # @overload for(filename)
64
+ # Finds an RDF writer class based on a file name.
65
+ #
66
+ # @param [String] filename
67
+ # @return [Class]
68
+ #
69
+ # @overload for(options = {})
70
+ # Finds an RDF writer class based on various options.
71
+ #
72
+ # @param [Hash{Symbol => Object}] options
73
+ # @option options [String, #to_s] :file_name (nil)
74
+ # @option options [Symbol, #to_sym] :file_extension (nil)
75
+ # @option options [String, #to_s] :content_type (nil)
76
+ # @return [Class]
77
+ #
78
+ # @return [Class]
79
+ def self.for(options = {})
80
+ options = options.merge(:has_writer => true) if options.is_a?(Hash)
81
+ if format = self.format || Format.for(options)
82
+ format.writer
83
+ end
84
+ end
85
+
86
+ ##
87
+ # Retrieves the RDF serialization format class for this writer class.
88
+ #
89
+ # @return [Class]
90
+ def self.format(klass = nil)
91
+ if klass.nil?
92
+ Format.each do |format|
93
+ if format.writer == self
94
+ return format
95
+ end
96
+ end
97
+ nil # not found
98
+ end
99
+ end
100
+
101
+ class << self
102
+ alias_method :format_class, :format
103
+ end
104
+
105
+ ##
106
+ # @param [RDF::Enumerable, #each] data
107
+ # the graph or repository to dump
108
+ # @param [IO, File] io
109
+ # the output stream or file to write to
110
+ # @param [Hash{Symbol => Object}] options
111
+ # passed to {RDF::Writer#initialize} or {RDF::Writer.buffer}
112
+ # @return [void]
113
+ def self.dump(data, io = nil, options = {})
114
+ io = File.open(io, 'w') if io.is_a?(String)
115
+ method = data.respond_to?(:each_statement) ? :each_statement : :each
116
+ if io
117
+ new(io, options) do |writer|
118
+ data.send(method) do |statement|
119
+ writer << statement
120
+ end
121
+ writer.flush
122
+ end
123
+ else
124
+ buffer(options) do |writer|
125
+ data.send(method) do |statement|
126
+ writer << statement
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+ ##
133
+ # Buffers output into a string buffer.
134
+ #
135
+ # @yield [writer]
136
+ # @yieldparam [RDF::Writer] writer
137
+ # @yieldreturn [void]
138
+ # @return [String]
139
+ def self.buffer(*args, &block)
140
+ StringIO.open do |buffer|
141
+ self.new(buffer, *args) { |writer| block.call(writer) }
142
+ buffer.string
143
+ end
144
+ end
145
+
146
+ ##
147
+ # Writes output to the given `filename`.
148
+ #
149
+ # @param [String, #to_s] filename
150
+ # @param [Hash{Symbol => Object}] options
151
+ # any additional options (see {RDF::Writer#initialize} and {RDF::Format.for})
152
+ # @option options [Symbol] :format (nil)
153
+ # @return [RDF::Writer]
154
+ def self.open(filename, options = {}, &block)
155
+ File.open(filename, 'wb') do |file|
156
+ format_options = options.dup
157
+ format_options[:file_name] ||= filename
158
+ self.for(options[:format] || format_options).new(file, options, &block)
159
+ end
160
+ end
161
+
162
+ ##
163
+ # Returns a symbol appropriate to use with RDF::Writer.for()
164
+ # @return [Symbol]
165
+ def self.to_sym
166
+ elements = self.to_s.split("::")
167
+ sym = elements.pop
168
+ sym = elements.pop if sym == 'Writer'
169
+ sym.downcase.to_s.to_sym
170
+ end
171
+
172
+ ##
173
+ # Returns a symbol appropriate to use with RDF::Writer.for()
174
+ # @return [Symbol]
175
+ def to_sym
176
+ self.class.to_sym
177
+ end
178
+
179
+ ##
180
+ # Initializes the writer.
181
+ #
182
+ # @param [IO, File] output
183
+ # the output stream
184
+ # @param [Hash{Symbol => Object}] options
185
+ # any additional options
186
+ # @option options [Encoding] :encoding (Encoding::UTF_8)
187
+ # the encoding to use on the output stream (Ruby 1.9+)
188
+ # @option options [Boolean] :canonicalize (false)
189
+ # whether to canonicalize literals when serializing
190
+ # @option options [Hash] :prefixes (Hash.new)
191
+ # the prefix mappings to use (not supported by all writers)
192
+ # @option options [#to_s] :base_uri (nil)
193
+ # the base URI to use when constructing relative URIs (not supported
194
+ # by all writers)
195
+ # @yield [writer] `self`
196
+ # @yieldparam [RDF::Writer] writer
197
+ # @yieldreturn [void]
198
+ def initialize(output = $stdout, options = {}, &block)
199
+ @output, @options = output, options.dup
200
+ @nodes, @node_id = {}, 0
201
+
202
+ if block_given?
203
+ write_prologue
204
+ case block.arity
205
+ when 1 then block.call(self)
206
+ else instance_eval(&block)
207
+ end
208
+ write_epilogue
209
+ end
210
+ end
211
+
212
+ ##
213
+ # Any additional options for this writer.
214
+ #
215
+ # @return [Hash]
216
+ # @since 0.2.2
217
+ attr_reader :options
218
+
219
+ ##
220
+ # Returns the base URI used for this writer.
221
+ #
222
+ # @example
223
+ # reader.prefixes[:dc] #=> RDF::URI('http://purl.org/dc/terms/')
224
+ #
225
+ # @return [Hash{Symbol => RDF::URI}]
226
+ # @since 0.3.4
227
+ def base_uri
228
+ @options[:base_uri]
229
+ end
230
+
231
+ ##
232
+ # Returns the URI prefixes currently defined for this writer.
233
+ #
234
+ # @example
235
+ # writer.prefixes[:dc] #=> RDF::URI('http://purl.org/dc/terms/')
236
+ #
237
+ # @return [Hash{Symbol => RDF::URI}]
238
+ # @since 0.2.2
239
+ def prefixes
240
+ @options[:prefixes] ||= {}
241
+ end
242
+
243
+ ##
244
+ # Defines the given URI prefixes for this writer.
245
+ #
246
+ # @example
247
+ # writer.prefixes = {
248
+ # :dc => RDF::URI('http://purl.org/dc/terms/'),
249
+ # }
250
+ #
251
+ # @param [Hash{Symbol => RDF::URI}] prefixes
252
+ # @return [Hash{Symbol => RDF::URI}]
253
+ # @since 0.3.0
254
+ def prefixes=(prefixes)
255
+ @options[:prefixes] = prefixes
256
+ end
257
+
258
+ ##
259
+ # Defines the given named URI prefix for this writer.
260
+ #
261
+ # @example Defining a URI prefix
262
+ # writer.prefix :dc, RDF::URI('http://purl.org/dc/terms/')
263
+ #
264
+ # @example Returning a URI prefix
265
+ # writer.prefix(:dc) #=> RDF::URI('http://purl.org/dc/terms/')
266
+ #
267
+ # @overload prefix(name, uri)
268
+ # @param [Symbol, #to_s] name
269
+ # @param [RDF::URI, #to_s] uri
270
+ #
271
+ # @overload prefix(name)
272
+ # @param [Symbol, #to_s] name
273
+ #
274
+ # @return [RDF::URI]
275
+ def prefix(name, uri = nil)
276
+ name = name.to_s.empty? ? nil : (name.respond_to?(:to_sym) ? name.to_sym : name.to_s.to_sym)
277
+ uri.nil? ? prefixes[name] : prefixes[name] = uri
278
+ end
279
+ alias_method :prefix!, :prefix
280
+
281
+ ##
282
+ # Flushes the underlying output buffer.
283
+ #
284
+ # @return [void] `self`
285
+ def flush
286
+ @output.flush if @output.respond_to?(:flush)
287
+ self
288
+ end
289
+ alias_method :flush!, :flush
290
+
291
+ ##
292
+ # @return [void] `self`
293
+ # @abstract
294
+ def write_prologue
295
+ self
296
+ end
297
+
298
+ ##
299
+ # @return [void] `self`
300
+ # @abstract
301
+ def write_epilogue
302
+ self
303
+ end
304
+
305
+ ##
306
+ # @param [String] text
307
+ # @return [void] `self`
308
+ # @abstract
309
+ def write_comment(text)
310
+ self
311
+ end
312
+
313
+ ##
314
+ # @param [RDF::Graph] graph
315
+ # @return [void] `self`
316
+ # @deprecated replace by `RDF::Writable#insert_graph`
317
+ def write_graph(graph)
318
+ graph.each_triple { |*triple| write_triple(*triple) }
319
+ self
320
+ end
321
+
322
+ ##
323
+ # @param [Array<RDF::Statement>] statements
324
+ # @return [void] `self`
325
+ # @deprecated replace by `RDF::Writable#insert_statements`
326
+ def write_statements(*statements)
327
+ statements.flatten.each { |statement| write_statement(statement) }
328
+ self
329
+ end
330
+
331
+ ##
332
+ # @param [RDF::Statement] statement
333
+ # @return [void] `self`
334
+ def write_statement(statement)
335
+ write_triple(*statement.to_triple)
336
+ self
337
+ end
338
+ alias_method :insert_statement, :write_statement # support the RDF::Writable interface
339
+
340
+ ##
341
+ # @param [Array<Array(RDF::Resource, RDF::URI, RDF::Term)>] triples
342
+ # @return [void] `self`
343
+ def write_triples(*triples)
344
+ triples.each { |triple| write_triple(*triple) }
345
+ self
346
+ end
347
+
348
+ ##
349
+ # @param [RDF::Resource] subject
350
+ # @param [RDF::URI] predicate
351
+ # @param [RDF::Term] object
352
+ # @return [void] `self`
353
+ # @raise [NotImplementedError] unless implemented in subclass
354
+ # @abstract
355
+ def write_triple(subject, predicate, object)
356
+ raise NotImplementedError.new("#{self.class}#write_triple") # override in subclasses
357
+ end
358
+
359
+ ##
360
+ # @param [RDF::Term] term
361
+ # @return [String]
362
+ # @since 0.3.0
363
+ def format_term(term, options = {})
364
+ case term
365
+ when String then format_literal(RDF::Literal(term, options), options)
366
+ when RDF::List then format_list(term, options)
367
+ when RDF::Literal then format_literal(term, options)
368
+ when RDF::URI then format_uri(term, options)
369
+ when RDF::Node then format_node(term, options)
370
+ else nil
371
+ end
372
+ end
373
+ alias_method :format_value, :format_term # @deprecated
374
+
375
+ ##
376
+ # @param [RDF::Node] value
377
+ # @param [Hash{Symbol => Object}] options
378
+ # @return [String]
379
+ # @raise [NotImplementedError] unless implemented in subclass
380
+ # @abstract
381
+ def format_node(value, options = {})
382
+ raise NotImplementedError.new("#{self.class}#format_node") # override in subclasses
383
+ end
384
+
385
+ ##
386
+ # @param [RDF::URI] value
387
+ # @param [Hash{Symbol => Object}] options
388
+ # @return [String]
389
+ # @raise [NotImplementedError] unless implemented in subclass
390
+ # @abstract
391
+ def format_uri(value, options = {})
392
+ raise NotImplementedError.new("#{self.class}#format_uri") # override in subclasses
393
+ end
394
+
395
+ ##
396
+ # @param [RDF::Literal, String, #to_s] value
397
+ # @param [Hash{Symbol => Object}] options
398
+ # @return [String]
399
+ # @raise [NotImplementedError] unless implemented in subclass
400
+ # @abstract
401
+ def format_literal(value, options = {})
402
+ raise NotImplementedError.new("#{self.class}#format_literal") # override in subclasses
403
+ end
404
+
405
+ ##
406
+ # @param [RDF::List] value
407
+ # @param [Hash{Symbol => Object}] options
408
+ # @return [String]
409
+ # @abstract
410
+ # @since 0.2.3
411
+ def format_list(value, options = {})
412
+ format_term(value.subject, options)
413
+ end
414
+
415
+ protected
416
+
417
+ ##
418
+ # @return [void]
419
+ def puts(*args)
420
+ @output.puts(*args)
421
+ end
422
+
423
+ ##
424
+ # @param [RDF::Resource] uriref
425
+ # @return [String]
426
+ def uri_for(uriref)
427
+ case
428
+ when uriref.is_a?(RDF::Node)
429
+ @nodes[uriref]
430
+ when uriref.respond_to?(:to_uri)
431
+ uriref.to_uri.to_s
432
+ else
433
+ uriref.to_s
434
+ end
435
+ end
436
+
437
+ ##
438
+ # @return [String]
439
+ def node_id
440
+ "_:n#{@node_id += 1}"
441
+ end
442
+
443
+ ##
444
+ # @param [String] string
445
+ # @return [String]
446
+ def escaped(string)
447
+ string.gsub('\\', '\\\\').gsub("\t", '\\t').
448
+ gsub("\n", '\\n').gsub("\r", '\\r').gsub('"', '\\"')
449
+ end
450
+
451
+ ##
452
+ # @param [String] string
453
+ # @return [String]
454
+ def quoted(string)
455
+ "\"#{string}\""
456
+ end
457
+
458
+ private
459
+
460
+ @@subclasses = [] # @private
461
+
462
+ ##
463
+ # @private
464
+ # @return [void]
465
+ def self.inherited(child)
466
+ @@subclasses << child
467
+ super
468
+ end
469
+ end # Writer
470
+
471
+ ##
472
+ # The base class for RDF serialization errors.
473
+ class WriterError < IOError
474
+ end # WriterError
475
+ end # RDF
data/lib/rdf.rb ADDED
@@ -0,0 +1,192 @@
1
+ require 'enumerator'
2
+ require 'open-uri'
3
+ require 'stringio'
4
+ require 'bigdecimal'
5
+ require 'date'
6
+ require 'time'
7
+
8
+ if RUBY_VERSION < '1.8.7'
9
+ # @see http://rubygems.org/gems/backports
10
+ begin
11
+ require 'backports/1.8.7'
12
+ rescue LoadError
13
+ begin
14
+ require 'rubygems'
15
+ require 'backports/1.8.7'
16
+ rescue LoadError
17
+ abort "RDF.rb requires Ruby 1.8.7 or the Backports gem (hint: `gem install backports')."
18
+ end
19
+ end
20
+ end
21
+
22
+ require 'rdf/version'
23
+
24
+ module RDF
25
+ # For compatibility with both Ruby 1.8.x and Ruby 1.9.x:
26
+ Enumerator = defined?(::Enumerator) ? ::Enumerator : ::Enumerable::Enumerator
27
+
28
+ # RDF mixins
29
+ autoload :Countable, 'rdf/mixin/countable'
30
+ autoload :Durable, 'rdf/mixin/durable'
31
+ autoload :Enumerable, 'rdf/mixin/enumerable'
32
+ autoload :Indexable, 'rdf/mixin/indexable'
33
+ autoload :Inferable, 'rdf/mixin/inferable'
34
+ autoload :Mutable, 'rdf/mixin/mutable'
35
+ autoload :Queryable, 'rdf/mixin/queryable'
36
+ autoload :Readable, 'rdf/mixin/readable'
37
+ autoload :TypeCheck, 'rdf/mixin/type_check'
38
+ autoload :Writable, 'rdf/mixin/writable'
39
+
40
+ # RDF objects
41
+ autoload :Graph, 'rdf/model/graph'
42
+ autoload :Literal, 'rdf/model/literal'
43
+ autoload :Node, 'rdf/model/node'
44
+ autoload :Resource, 'rdf/model/resource'
45
+ autoload :Statement, 'rdf/model/statement'
46
+ autoload :URI, 'rdf/model/uri'
47
+ autoload :Value, 'rdf/model/value'
48
+ autoload :Term, 'rdf/model/term'
49
+
50
+ # RDF collections
51
+ autoload :List, 'rdf/model/list'
52
+
53
+ # RDF serialization
54
+ autoload :Format, 'rdf/format'
55
+ autoload :Reader, 'rdf/reader'
56
+ autoload :ReaderError, 'rdf/reader'
57
+ autoload :Writer, 'rdf/writer'
58
+ autoload :WriterError, 'rdf/writer'
59
+
60
+ # RDF serialization formats
61
+ autoload :NTriples, 'rdf/ntriples'
62
+ autoload :NQuads, 'rdf/nquads'
63
+
64
+ # RDF storage
65
+ autoload :Repository, 'rdf/repository'
66
+ autoload :Transaction, 'rdf/transaction'
67
+
68
+ # RDF querying
69
+ autoload :Query, 'rdf/query'
70
+
71
+ # RDF vocabularies
72
+ autoload :Vocabulary, 'rdf/vocab'
73
+ VOCABS = Dir.glob(File.join(File.dirname(__FILE__), 'rdf', 'vocab', '*.rb')).map { |f| File.basename(f)[0...-(File.extname(f).size)].to_sym } rescue []
74
+ VOCABS.each { |v| autoload v.to_s.upcase.to_sym, "rdf/vocab/#{v}" unless v == :rdf }
75
+
76
+ # Utilities
77
+ autoload :Util, 'rdf/util'
78
+
79
+ ##
80
+ # Alias for `RDF::Resource.new`.
81
+ #
82
+ # @return [RDF::Resource]
83
+ def self.Resource(*args, &block)
84
+ Resource.new(*args, &block)
85
+ end
86
+
87
+ ##
88
+ # Alias for `RDF::Node.new`.
89
+ #
90
+ # @return [RDF::Node]
91
+ def self.Node(*args, &block)
92
+ Node.new(*args, &block)
93
+ end
94
+
95
+ ##
96
+ # Alias for `RDF::URI.new`.
97
+ #
98
+ # @overload URI(uri)
99
+ # @param [URI, String, #to_s] uri
100
+ #
101
+ # @overload URI(options = {})
102
+ # @param [Hash{Symbol => Object} options
103
+ #
104
+ # @return [RDF::URI]
105
+ def self.URI(*args, &block)
106
+ case uri = args.first
107
+ when RDF::URI then uri
108
+ else case
109
+ when uri.respond_to?(:to_uri) then uri.to_uri
110
+ else URI.new(*args, &block)
111
+ end
112
+ end
113
+ end
114
+
115
+ ##
116
+ # Alias for `RDF::Literal.new`.
117
+ #
118
+ # @return [RDF::Literal]
119
+ def self.Literal(*args, &block)
120
+ case literal = args.first
121
+ when RDF::Literal then literal
122
+ else Literal.new(*args, &block)
123
+ end
124
+ end
125
+
126
+ ##
127
+ # Alias for `RDF::Graph.new`.
128
+ #
129
+ # @return [RDF::Graph]
130
+ def self.Graph(*args, &block)
131
+ Graph.new(*args, &block)
132
+ end
133
+
134
+ ##
135
+ # Alias for `RDF::Statement.new`.
136
+ #
137
+ # @return [RDF::Statement]
138
+ def self.Statement(*args, &block)
139
+ Statement.new(*args, &block)
140
+ end
141
+
142
+ ##
143
+ # Alias for `RDF::Vocabulary.create`.
144
+ #
145
+ # @param [String] uri
146
+ # @return [Class]
147
+ def self.Vocabulary(uri)
148
+ Vocabulary.create(uri)
149
+ end
150
+
151
+ ##
152
+ # @return [URI]
153
+ def self.type
154
+ self[:type]
155
+ end
156
+
157
+ ##
158
+ # @return [#to_s] property
159
+ # @return [URI]
160
+ def self.[](property)
161
+ RDF::URI.intern([to_uri.to_s, property.to_s].join)
162
+ end
163
+
164
+ ##
165
+ # @param [Symbol] property
166
+ # @return [URI]
167
+ # @raise [NoMethodError]
168
+ def self.method_missing(property, *args, &block)
169
+ if args.empty?
170
+ self[property]
171
+ else
172
+ super
173
+ end
174
+ end
175
+
176
+ ##
177
+ # @return [URI]
178
+ def self.to_rdf
179
+ to_uri
180
+ end
181
+
182
+ ##
183
+ # @return [URI]
184
+ def self.to_uri
185
+ RDF::URI.intern("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
186
+ end
187
+
188
+ class << self
189
+ # For compatibility with `RDF::Vocabulary.__name__`:
190
+ alias_method :__name__, :name
191
+ end
192
+ end