rdfobjects 0.10.2 → 0.10.3
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.
- data/README +3 -1
- data/lib/rdf_objects/parsers.rb +44 -15
- data/lib/rdf_objects/rdf_resource.rb +2 -2
- metadata +2 -2
data/README
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
RDFObjects are intended to simplify working with RDF data by providing a (more) Ruby-like interface to resources (thanks to OpenStruct).
|
2
2
|
|
3
|
+
There is a Google Group at http://groups.google.com/group/rdfobjects to discuss problems, enhancements, changes, announcements, etc.
|
4
|
+
|
3
5
|
Installation:
|
4
|
-
The gem is currently hosted at http://gemcutter.org/gems/rdfobjects so you'll either need the gemcutter gem (and run "gem tumble") or add gemcutter.org to your sources manually (gem sources -a http://gemcutter.org)
|
6
|
+
The gem is currently hosted at http://gemcutter.org/gems/rdfobjects so you'll either need the gemcutter gem (and run "gem tumble") or add gemcutter.org to your sources manually (gem sources -a http://gemcutter.org).
|
5
7
|
|
6
8
|
$ sudo gem install rdfobjects
|
7
9
|
|
data/lib/rdf_objects/parsers.rb
CHANGED
@@ -290,6 +290,7 @@ module RDFObject
|
|
290
290
|
@parser = Nokogiri::XML::SAX::Parser.new(self)
|
291
291
|
@hierarchy = []
|
292
292
|
@xml_base = nil
|
293
|
+
@default_namespace = nil
|
293
294
|
end
|
294
295
|
|
295
296
|
def data=(xml)
|
@@ -314,19 +315,37 @@ module RDFObject
|
|
314
315
|
end
|
315
316
|
end
|
316
317
|
|
317
|
-
def attributes_to_hash(attributes)
|
318
|
+
def attributes_to_hash(attributes, namespaces, name, prefix)
|
318
319
|
hash = {}
|
319
320
|
attributes.each do | att |
|
320
|
-
|
321
|
+
ns = att.uri || @default_namespace
|
322
|
+
unless ns =~ /[#\/]$/
|
323
|
+
ns << "/"
|
324
|
+
end
|
325
|
+
hash["#{ns}#{att.localname}"] = att.value
|
321
326
|
end
|
322
327
|
hash
|
323
328
|
end
|
324
329
|
|
330
|
+
def attributes_as_assertions(attributes)
|
331
|
+
skip = ["http://www.w3.org/XML/1998/namespace/lang", "http://www.w3.org/XML/1998/namespace/base",
|
332
|
+
"http://www.w3.org/1999/02/22-rdf-syntax-ns#resource", "http://www.w3.org/1999/02/22-rdf-syntax-ns#about",
|
333
|
+
"http://www.w3.org/1999/02/22-rdf-syntax-ns#nodeID", "http://www.w3.org/1999/02/22-rdf-syntax-ns#datatype"]
|
334
|
+
attributes.each_pair do | uri, value |
|
335
|
+
next if skip.index(uri)
|
336
|
+
lit = Literal.new(value, {:data_type=>attributes["http://www.w3.org/1999/02/22-rdf-syntax-ns#datatype"],
|
337
|
+
:language=>attributes["http://www.w3.org/XML/1998/namespace/lang"]})
|
338
|
+
self.current_resource.assert(uri, lit)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
325
342
|
def add_layer name, attributes, prefix, uri, ns
|
326
343
|
layer = {:name=>"#{uri}#{name}"}
|
327
|
-
if attributes['about'] or
|
328
|
-
|
329
|
-
id =
|
344
|
+
if attributes['http://www.w3.org/1999/02/22-rdf-syntax-ns#about'] or
|
345
|
+
attributes['http://www.w3.org/1999/02/22-rdf-syntax-ns#nodeID']
|
346
|
+
id = attributes['http://www.w3.org/1999/02/22-rdf-syntax-ns#about'] ||
|
347
|
+
attributes['http://www.w3.org/1999/02/22-rdf-syntax-ns#nodeID']
|
348
|
+
id = sanitize_uri(id) if attributes['http://www.w3.org/1999/02/22-rdf-syntax-ns#about']
|
330
349
|
layer[:resource] = @collection.find_or_create(id)
|
331
350
|
unless "#{uri}#{name}" == "http://www.w3.org/1999/02/22-rdf-syntax-ns#Description"
|
332
351
|
layer[:resource].relate("http://www.w3.org/1999/02/22-rdf-syntax-ns#type", @collection.find_or_create("#{uri}#{name}"))
|
@@ -334,20 +353,21 @@ module RDFObject
|
|
334
353
|
if !@hierarchy.empty? && @hierarchy.last[:predicate]
|
335
354
|
self.current_resource.relate(self.current_predicate, layer[:resource])
|
336
355
|
end
|
337
|
-
elsif attributes["resource"]
|
338
|
-
self.current_resource.assert("#{uri}#{name}", @collection.find_or_create(sanitize_uri(attributes['resource'])))
|
356
|
+
elsif attributes["http://www.w3.org/1999/02/22-rdf-syntax-ns#resource"]
|
357
|
+
self.current_resource.assert("#{uri}#{name}", @collection.find_or_create(sanitize_uri(attributes['http://www.w3.org/1999/02/22-rdf-syntax-ns#resource'])))
|
339
358
|
layer[:predicate] = layer[:name]
|
340
359
|
else
|
341
360
|
unless layer[:name] == "http://www.w3.org/1999/02/22-rdf-syntax-ns#RDF"
|
342
361
|
layer[:predicate] = layer[:name]
|
343
362
|
end
|
344
363
|
end
|
345
|
-
if attributes["datatype"] || attributes["lang"]
|
346
|
-
layer[:datatype] = attributes["datatype"] if attributes["datatype"]
|
347
|
-
layer[:language] = attributes["lang"] if attributes["lang"]
|
364
|
+
if attributes["http://www.w3.org/1999/02/22-rdf-syntax-ns#datatype"] || attributes["http://www.w3.org/XML/1998/namespace/lang"]
|
365
|
+
layer[:datatype] = attributes["http://www.w3.org/1999/02/22-rdf-syntax-ns#datatype"] if attributes["http://www.w3.org/1999/02/22-rdf-syntax-ns#datatype"]
|
366
|
+
layer[:language] = attributes["http://www.w3.org/XML/1998/namespace/lang"] if attributes["http://www.w3.org/XML/1998/namespace/lang"]
|
348
367
|
end
|
349
|
-
layer[:base_uri] = URI.parse(attributes["base"]) if attributes["base"]
|
368
|
+
layer[:base_uri] = URI.parse(attributes["http://www.w3.org/XML/1998/namespace/base"]) if attributes["http://www.w3.org/XML/1998/namespace/base"]
|
350
369
|
@hierarchy << layer
|
370
|
+
attributes_as_assertions(attributes)
|
351
371
|
end
|
352
372
|
|
353
373
|
def remove_layer(name)
|
@@ -393,11 +413,20 @@ module RDFObject
|
|
393
413
|
end
|
394
414
|
|
395
415
|
def start_element_namespace name, attributes = [], prefix = nil, uri = nil, ns = {}
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
416
|
+
check_for_default_ns(ns)
|
417
|
+
attributes = attributes_to_hash(attributes, ns, name, prefix)
|
418
|
+
add_layer(name, attributes, prefix, uri, ns)
|
419
|
+
end
|
400
420
|
|
421
|
+
def check_for_default_ns(ns)
|
422
|
+
return unless self.current_resource.empty?
|
423
|
+
ns.each do | n |
|
424
|
+
if n.first.nil?
|
425
|
+
@default_namespace = n.last
|
426
|
+
end
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
401
430
|
def characters text
|
402
431
|
if self.current_literal && !text.strip.empty?
|
403
432
|
self.current_literal << text.strip
|
@@ -250,9 +250,9 @@ module RDFObject
|
|
250
250
|
|
251
251
|
class BlankNode < OpenStruct
|
252
252
|
include RDFObject::Node
|
253
|
-
require 'md5'
|
253
|
+
require 'digest/md5'
|
254
254
|
def initialize(node_id = nil)
|
255
|
-
super(:node_id=>sanitize_bnode_id(node_id||MD5.
|
255
|
+
super(:node_id=>sanitize_bnode_id(node_id||Digest::MD5.hexdigest(self.object_id.to_s + "/" + DateTime.now.to_s).to_s))
|
256
256
|
end
|
257
257
|
|
258
258
|
def describe; end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdfobjects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ross Singer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-03-01 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|