rdf-rdfa 0.3.12 → 0.3.13

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -161,6 +161,72 @@ This is an alternate way of adding data using the `@value` property. Similar to
161
161
  The `data` element is described in the WHATWG version of the [HTML5 spec](http://www.whatwg.org/specs/web-apps/current-work/multipage/text-level-semantics.html#the-data-element).
162
162
  This is related to [RDFa ISSUE-113](http://www.w3.org/2010/02/rdfa/track/issues/113)
163
163
 
164
+ ### Support for embedded RDF/XML
165
+ If the document includes embedded RDF/XML, as is the case with many SVG documents, and the RDF::RDFXML gem is installed, the reader will add extracted triples to the default graph.
166
+
167
+ For example:
168
+
169
+ <?xml version="1.0" encoding="UTF-8"?>
170
+ <svg width="12cm" height="4cm" viewBox="0 0 1200 400"
171
+ xmlns:dc="http://purl.org/dc/terms/"
172
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
173
+ xml:base="http://example.net/"
174
+ xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny">
175
+ <desc property="dc:description">A yellow rectangle with sharp corners.</desc>
176
+ <metadata>
177
+ <rdf:RDF>
178
+ <rdf:Description rdf:about="">
179
+ <dc:title>Test 0304</dc:title>
180
+ </rdf:Description>
181
+ </rdf:RDF>
182
+ </metadata>
183
+ <!-- Show outline of canvas using 'rect' element -->
184
+ <rect x="1" y="1" width="1198" height="398"
185
+ fill="none" stroke="blue" stroke-width="2"/>
186
+ <rect x="400" y="100" width="400" height="200"
187
+ fill="yellow" stroke="navy" stroke-width="10" />
188
+ </svg>
189
+
190
+ generates the following turtle:
191
+
192
+ @prefix dc: <http://purl.org/dc/terms/> .
193
+
194
+ <http://example.net/> dc:title "Test 0304" ;
195
+ dc:description "A yellow rectangle with sharp corners." .
196
+
197
+ ### Support for embedded N-Triples or Turtle
198
+ If the document includes a `&lt;script&gt;` element having an `@type` attribute whose value matches that of a loaded RDF reader (text/ntriples and text/turtle are loaded if they are availble), the data will be extracted and added to the default graph.
199
+
200
+ Additionally, if the `&lt;script&gt;` element has an `@id` attribute, the triples will be placed into a graph named by appending the value of `@id` as a frament of the base IRI of the input document. For example:
201
+
202
+ <html>
203
+ <body>
204
+ <script type="text/turtle" id="graph1"><![CDATA[
205
+ @prefix foo: <http://www.example.com/xyz#> .
206
+ @prefix gr: <http://purl.org/goodrelations/v1#> .
207
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
208
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
209
+
210
+ foo:myCompany
211
+ a gr:BusinessEntity ;
212
+ rdfs:seeAlso <http://www.example.com/xyz> ;
213
+ gr:hasLegalName "Hepp Industries Ltd."^^xsd:string .
214
+ ]]></script>
215
+ </body>
216
+ </html>
217
+
218
+ generates the following TriG:
219
+
220
+ @prefix gr: <http://purl.org/goodrelations/v1#> .
221
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
222
+
223
+ <http://www.example.com/xyz#graph1> {
224
+ <http://www.example.com/xyz#myCompany> a gr:BusinessEntity ;
225
+ rdfs:seeAlso <http://www.example.com/xyz> ;
226
+ gr:hasLegalName "Hepp Industries Ltd." .
227
+ }
228
+
229
+
164
230
  ## Usage
165
231
 
166
232
  ### Reading RDF data in the RDFa format
@@ -338,7 +404,8 @@ Full documentation available on [Rubydoc.info][RDFa doc]
338
404
  * {RDF::RDFa::Reader}
339
405
  * {RDF::RDFa::Reader::Nokogiri}
340
406
  * {RDF::RDFa::Reader::REXML}
341
- * {RDF::RDFa::Profile}
407
+ * {RDF::RDFa::Context}
408
+ * {RDF::RDFa::Expansion}
342
409
  * {RDF::RDFa::Writer}
343
410
 
344
411
  ### Additional vocabularies
@@ -393,7 +460,7 @@ see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
393
460
  * <http://github.com/ruby-rdf/rdf-rdfa>
394
461
  * <http://lists.w3.org/Archives/Public/public-rdf-ruby/>
395
462
 
396
- [RDF.rb]: http://rdf.rubyforge.org/
463
+ [RDF.rb]: http://rubygems.org/gems/rdf
397
464
  [YARD]: http://yardoc.org/
398
465
  [YARD-GS]: http://rubydoc.info/docs/yard/file/docs/GettingStarted.md
399
466
  [PDD]: http://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.12
1
+ 0.3.13
data/lib/rdf/rdfa.rb CHANGED
@@ -15,7 +15,7 @@ module RDF
15
15
  # end
16
16
  # end
17
17
  #
18
- # @see http://rdf.rubyforge.org/
18
+ # @see http://rubygems.org/gems/rdf
19
19
  # @see http://www.w3.org/TR/rdfa-syntax/#s_model RDFa 1.0
20
20
  # @see http://www.w3.org/TR/2012/CR-rdfa-core-20120313/
21
21
  # @see http://www.w3.org/TR/2012/CR-xhtml-rdfa-20120313/
@@ -149,7 +149,7 @@ module RDF::RDFa
149
149
  ##
150
150
  # Extract vocabulary, prefix mappings and terms from a enumerable object into an instance
151
151
  #
152
- # @param [RDF::Enumerable, Enumerator] queryable
152
+ # @param [RDF::Enumerable, Enumerator] enumerable
153
153
  # @return [void] ignored
154
154
  def parse(enumerable)
155
155
  STDERR.puts("process_context: parse context <#{uri}>") if RDF::RDFa.debug?
@@ -333,6 +333,7 @@ module RDF::RDFa
333
333
  # @yieldparam [RDF::Statement] statement
334
334
  # @return [void]
335
335
  def each_statement(&block)
336
+
336
337
  if @options[:vocab_expansion]
337
338
  @options[:vocab_expansion] = false
338
339
  expand.each_statement(&block)
@@ -349,7 +350,61 @@ module RDF::RDFa
349
350
  end
350
351
 
351
352
  # parse
353
+ return unless @root
352
354
  parse_whole_document(@doc, RDF::URI(base_uri))
355
+
356
+ def extract_script(el, input, type, options, &block)
357
+ add_debug(el, "script element of type #{type}")
358
+ begin
359
+ # Formats don't exist unless they've been required
360
+ case type
361
+ when 'application/rdf+xml' then require 'rdf/rdfxml'
362
+ when 'text/ntriples' then require 'rdf/ntriples'
363
+ when 'text/turtle' then require 'text/turtle'
364
+ end
365
+ rescue
366
+ end
367
+
368
+ if reader = RDF::Reader.for(:content_type => type)
369
+ add_debug(el, "=> reader #{reader.to_sym}")
370
+ reader.new(input, options).each(&block)
371
+ end
372
+ end
373
+
374
+ # Look for Embedded Turtle and RDF/XML
375
+ unless @root.xpath("//rdf:RDF", "xmlns:rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#").empty?
376
+ extract_script(@root, @doc, "application/rdf+xml", @options) do |statement|
377
+ block.call(statement)
378
+ end
379
+ end
380
+
381
+ # # Look for Embedded RDF/XML
382
+ # unless @root.xpath("//rdf:RDF", "xmlns:rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#").empty?
383
+ # extract_script(@root, @doc, "application/rdf+xml", @options) do |statement|
384
+ # block.call(statement)
385
+ # end
386
+ # end
387
+
388
+ # Look for Embedded scripts
389
+ @root.css("script[type]") do |el|
390
+ ctx = RDF::URI(el.attribute("id")) if el.attribute("id")
391
+ type = el.attribute("type")
392
+
393
+ extract_script(el, el.inner_text, type, @options) do |statement|
394
+ statement.context = ctx if ctx
395
+ block.call(statement)
396
+ end
397
+ end
398
+
399
+ # Just incase root is a <script> element
400
+ if @root.name == 'script' && type = root.attribute('type')
401
+ ctx = RDF::URI(@root.attribute("id")) if @root.attribute("id")
402
+
403
+ extract_script(@root, @root.inner_text, type, @options) do |statement|
404
+ statement.context = ctx if ctx
405
+ block.call(statement)
406
+ end
407
+ end
353
408
  end
354
409
  end
355
410
 
@@ -382,8 +437,8 @@ module RDF::RDFa
382
437
 
383
438
  # Add debug event to debug array, if specified
384
439
  #
385
- # @param [#display_path, #to_s] node:: XML Node or string for showing context
386
- # @param [String] message::
440
+ # @param [#display_path, #to_s] node XML Node or string for showing context
441
+ # @param [String] message
387
442
  # @yieldreturn [String] appended to message, to allow for lazy-evaulation of message
388
443
  def add_debug(node, message = "")
389
444
  return unless ::RDF::RDFa.debug? || @debug
@@ -439,15 +494,17 @@ module RDF::RDFa
439
494
  end
440
495
  end
441
496
 
497
+ ##
442
498
  # add a statement, object can be literal or URI or bnode
499
+ # Yields {RDF::Statement} to the saved callback
443
500
  #
444
- # @param [#display_path, #to_s] node:: XML Node or string for showing context
445
- # @param [RDF::URI, RDF::BNode] subject:: the subject of the statement
446
- # @param [RDF::URI] predicate:: the predicate of the statement
447
- # @param [URI, RDF::BNode, RDF::Literal] object:: the object of the statement
448
- # @return [RDF::Statement]:: Added statement
449
- # @raise [RDF::ReaderError]:: Checks parameter types and raises if they are incorrect if parsing mode is _validate_.
450
- def add_triple(node, subject, predicate, object)
501
+ # @param [#display_path, #to_s] node XML Node or string for showing context
502
+ # @param [RDF::Resource] subject the subject of the statement
503
+ # @param [RDF::URI] predicate the predicate of the statement
504
+ # @param [RDF::Value] object the object of the statement
505
+ # @param [RDF::Value] context the context of the statement
506
+ # @raise [RDF::ReaderError] Checks parameter types and raises if they are incorrect if parsing mode is _validate_.
507
+ def add_triple(node, subject, predicate, object, context = nil)
451
508
  statement = RDF::Statement.new(subject, predicate, object)
452
509
  add_info(node, "statement: #{RDF::NTriples.serialize(statement)}")
453
510
  @callback.call(statement) if @options[:rdfagraph].include?(:output) && statement.valid?
@@ -91,6 +91,34 @@ module RDF::RDFa
91
91
  NodeSetProxy.new(@node.children, self)
92
92
  end
93
93
 
94
+ # Ancestors of this element, in order
95
+ def ancestors
96
+ @ancestors ||= parent ? parent.ancestors + [parent] : []
97
+ end
98
+
99
+ ##
100
+ # Inner text of an element. Decode Entities
101
+ #
102
+ # @return [String]
103
+ #def inner_text
104
+ # coder = HTMLEntities.new
105
+ # coder.decode(@node.inner_text)
106
+ #end
107
+
108
+ def attribute_nodes
109
+ @attribute_nodes ||= NodeSetProxy.new(@node.attribute_nodes, self)
110
+ end
111
+
112
+ def xpath(*args)
113
+ @node.xpath(*args).map do |n|
114
+ # Get node ancestors
115
+ parent = n.ancestors.reverse.inject(nil) do |p,node|
116
+ NodeProxy.new(node, p)
117
+ end
118
+ NodeProxy.new(n, parent)
119
+ end
120
+ end
121
+
94
122
  ##
95
123
  # Proxy for everything else to @node
96
124
  def method_missing(method, *args)
@@ -94,6 +94,11 @@ module RDF::RDFa
94
94
  NodeSetProxy.new(@node.children, self)
95
95
  end
96
96
 
97
+ # Ancestors of this element, in order
98
+ def ancestors
99
+ @ancestors ||= parent ? parent.ancestors + [parent] : []
100
+ end
101
+
97
102
  ##
98
103
  # Inner text of an element
99
104
  #
@@ -123,13 +128,33 @@ module RDF::RDFa
123
128
  @node.is_a?(::REXML::Element)
124
129
  end
125
130
 
131
+ def attribute_nodes
132
+ @attribute_nodes ||= NodeSetProxy.new(@node.children.select {|n| n.is_a?(::REXML::Attribute)}, self)
133
+ end
134
+
135
+ def xpath(*args)
136
+ #NodeSetProxy.new(::REXML::XPath.match(@node, path, namespaces), self)
137
+ ::REXML::XPath.match(@node, *args).map do |n|
138
+ # Get node ancestors
139
+ parent = n.ancestors.reverse.inject(nil) do |p,node|
140
+ NodeProxy.new(node, p)
141
+ end rescue nil
142
+ NodeProxy.new(n, parent)
143
+ end
144
+ end
145
+
146
+ # Simple case for <script>
147
+ def css(path)
148
+ xpath("//script[@type]")
149
+ end
150
+
126
151
  ##
127
152
  # Proxy for everything else to @node
128
153
  def method_missing(method, *args)
129
154
  @node.send(method, *args)
130
155
  end
131
156
  end
132
-
157
+
133
158
  ##
134
159
  # NodeSet proxy
135
160
  class NodeSetProxy
@@ -642,7 +642,7 @@ module RDF::RDFa
642
642
 
643
643
  # Haml rendering helper. Return CURIE for the literal datatype, if the literal is a typed literal.
644
644
  #
645
- # @param [RDF::Resource] resource
645
+ # @param [RDF::Resource] literal
646
646
  # @return [String, nil]
647
647
  # @raise [RDF::WriterError]
648
648
  def get_dt_curie(literal)
@@ -835,7 +835,7 @@ module RDF::RDFa
835
835
 
836
836
  # Add debug event to debug array, if specified
837
837
  #
838
- # @param [String] message::
838
+ # @param [String] message
839
839
  # @yieldreturn [String] appended to message, to allow for lazy-evaulation of message
840
840
  def add_debug(message = "")
841
841
  return unless ::RDF::RDFa.debug? || @debug
@@ -172,7 +172,7 @@ module RDF::RDFa
172
172
  - subjects.each do |subject|
173
173
  != yield(subject)
174
174
  %footer
175
- %p= "Written by <a href='http://rdf.rubyforge.org/rdfa'>RDF::RDFa</a> version #{RDF::RDFa::VERSION}"
175
+ %p= "Written by <a href='http://rubygems.org/gems/rdf-rdfa'>RDF::RDFa</a> version #{RDF::RDFa::VERSION}"
176
176
  ),
177
177
 
178
178
  # Output for non-leaf resources
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-rdfa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.12
4
+ version: 0.3.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-05-14 00:00:00.000000000Z
13
+ date: 2012-05-17 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rdf
17
- requirement: &70222279575740 !ruby/object:Gem::Requirement
17
+ requirement: &70096958854220 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.3.3
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70222279575740
25
+ version_requirements: *70096958854220
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: haml
28
- requirement: &70222279575260 !ruby/object:Gem::Requirement
28
+ requirement: &70096958853760 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 3.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70222279575260
36
+ version_requirements: *70096958853760
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rdf-xsd
39
- requirement: &70222279574780 !ruby/object:Gem::Requirement
39
+ requirement: &70096958853260 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 0.3.5
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70222279574780
47
+ version_requirements: *70096958853260
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: htmlentities
50
- requirement: &70222279574300 !ruby/object:Gem::Requirement
50
+ requirement: &70096958852780 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 4.3.0
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *70222279574300
58
+ version_requirements: *70096958852780
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: nokogiri
61
- requirement: &70222279573780 !ruby/object:Gem::Requirement
61
+ requirement: &70096958852240 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 1.4.4
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70222279573780
69
+ version_requirements: *70096958852240
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: equivalent-xml
72
- requirement: &70222279573320 !ruby/object:Gem::Requirement
72
+ requirement: &70096958851780 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: 0.2.8
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70222279573320
80
+ version_requirements: *70096958851780
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: open-uri-cached
83
- requirement: &70222279572820 !ruby/object:Gem::Requirement
83
+ requirement: &70096958851320 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: 0.0.4
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *70222279572820
91
+ version_requirements: *70096958851320
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: spira
94
- requirement: &70222279572240 !ruby/object:Gem::Requirement
94
+ requirement: &70096958850860 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: 0.0.12
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *70222279572240
102
+ version_requirements: *70096958850860
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: rspec
105
- requirement: &70222279571660 !ruby/object:Gem::Requirement
105
+ requirement: &70096958850320 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ! '>='
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: 2.8.0
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *70222279571660
113
+ version_requirements: *70096958850320
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: rdf-spec
116
- requirement: &70222279571120 !ruby/object:Gem::Requirement
116
+ requirement: &70096958849800 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ! '>='
@@ -121,10 +121,10 @@ dependencies:
121
121
  version: 0.3.2
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *70222279571120
124
+ version_requirements: *70096958849800
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rdf-turtle
127
- requirement: &70222279570640 !ruby/object:Gem::Requirement
127
+ requirement: &70096958849340 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ! '>='
@@ -132,10 +132,10 @@ dependencies:
132
132
  version: 0.1.0
133
133
  type: :development
134
134
  prerelease: false
135
- version_requirements: *70222279570640
135
+ version_requirements: *70096958849340
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: rdf-rdfxml
138
- requirement: &70222279570180 !ruby/object:Gem::Requirement
138
+ requirement: &70096958848840 !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
141
141
  - - ! '>='
@@ -143,10 +143,10 @@ dependencies:
143
143
  version: 0.3.4
144
144
  type: :development
145
145
  prerelease: false
146
- version_requirements: *70222279570180
146
+ version_requirements: *70096958848840
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: rdf-isomorphic
149
- requirement: &70222279569420 !ruby/object:Gem::Requirement
149
+ requirement: &70096958848340 !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements:
152
152
  - - ! '>='
@@ -154,10 +154,10 @@ dependencies:
154
154
  version: 0.3.4
155
155
  type: :development
156
156
  prerelease: false
157
- version_requirements: *70222279569420
157
+ version_requirements: *70096958848340
158
158
  - !ruby/object:Gem::Dependency
159
159
  name: sparql
160
- requirement: &70222279568920 !ruby/object:Gem::Requirement
160
+ requirement: &70096958833200 !ruby/object:Gem::Requirement
161
161
  none: false
162
162
  requirements:
163
163
  - - ! '>='
@@ -165,10 +165,10 @@ dependencies:
165
165
  version: 0.0.2
166
166
  type: :development
167
167
  prerelease: false
168
- version_requirements: *70222279568920
168
+ version_requirements: *70096958833200
169
169
  - !ruby/object:Gem::Dependency
170
170
  name: yard
171
- requirement: &70222279568440 !ruby/object:Gem::Requirement
171
+ requirement: &70096958832640 !ruby/object:Gem::Requirement
172
172
  none: false
173
173
  requirements:
174
174
  - - ! '>='
@@ -176,7 +176,7 @@ dependencies:
176
176
  version: 0.6.0
177
177
  type: :development
178
178
  prerelease: false
179
- version_requirements: *70222279568440
179
+ version_requirements: *70096958832640
180
180
  description: RDF::RDFa is an RDFa reader/writer for Ruby using the RDF.rb library
181
181
  suite.
182
182
  email: public-rdf-ruby@w3.org