rdf-microdata 1.1.2 → 2.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: b6e7808ba9a859c54b20c2d1afab262c8a72f392
4
- data.tar.gz: d8444062fdb0099f152d89285dfe568aae19cb48
3
+ metadata.gz: d7797313b5b2b13d2c97e2ca613839ca72525064
4
+ data.tar.gz: 6b955e34556a727e14b88a9b776b10b0d14f2f29
5
5
  SHA512:
6
- metadata.gz: 79400d78724736c4e8a147f7ecb042f1df956b8ace50157baab1be14a9531aa6a892546728a8085cc37b4a93e9376fbdfe3da069ecf23fd744bf6d6e9c64b97f
7
- data.tar.gz: 2e70ab743786160758ee287450f59e21946131001663577436e38bfc2361ffd9e6146d661c06dbc9e4eeb5da8ff88bcb4339c752c3523930193e892bc39e07ba
6
+ metadata.gz: 4a68bb3d267426ffaa041f84f5f1b6cf195f15546593701c95c9bcfc672903726c421bed60546d330d80437c23adcd264b1b2c0ac7b27baeb11422744d3c1d3e
7
+ data.tar.gz: da17e2b59b28bca0ca9c65476ef44486ce81058254655389bea7fa447860ec562100783c81d24b0597487def25443f135e132eb0b0148d6b6db1bd614dfb6f59
data/README CHANGED
@@ -29,8 +29,14 @@ The parser uses a build-in version of the [Microdata RDF][] registry.
29
29
 
30
30
  ### Reading RDF data in the Microdata format
31
31
 
32
- graph = RDF::Graph.load("etc/foaf.html", :format => :microdata)
32
+ require 'rdf/microdata'
33
+ graph = RDF::Graph.load("etc/doap.html", :format => :microdata)
33
34
 
35
+ ### Reading using content-negotation
36
+
37
+ require 'rdf/microdata'
38
+ graph = RDF::Graph.load("etc/doap.html", :content_type => "text/html")
39
+
34
40
  ## Note
35
41
  This spec is based on the W3C HTML Data Task Force specification and does not support
36
42
  GRDDL-type triple generation, such as for html>head>title anchor tags.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.2
1
+ 2.0
data/etc/doap.nt CHANGED
@@ -16,6 +16,3 @@
16
16
  <http://rubygems.org/gems/rdf-microdata> <http://usefulinc.com/ns/doap#homepage> <http://github.com/ruby-rdf/rdf-microdata> .
17
17
  <http://rubygems.org/gems/rdf-microdata> <http://usefulinc.com/ns/doap#license> <http://creativecommons.org/licenses/publicdomain/> .
18
18
  <http://rubygems.org/gems/rdf-microdata> <http://usefulinc.com/ns/doap#mailing-list> <http://lists.w3.org/Archives/Public/public-rdf-ruby/> .
19
- _:g2162899420 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://rubygems.org/gems/rdf-microdata> .
20
- _:g2162899420 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
21
- <http://example.com> <http://www.w3.org/ns/md#item> _:g2162899420 .
data/etc/registry.json CHANGED
@@ -1,46 +1,8 @@
1
1
  {
2
2
  "http://schema.org/": {
3
- "propertyURI": "vocabulary",
4
- "multipleValues": "unordered",
5
3
  "properties": {
6
- "additionalType": {"subPropertyOf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"},
7
- "blogPosts": {"multipleValues": "list"},
8
- "blogPosts": {"multipleValues": "list"},
9
- "breadcrumb": {"multipleValues": "list"},
10
- "byArtist": {"multipleValues": "list"},
11
- "creator": {"multipleValues": "list"},
12
- "episode": {"multipleValues": "list"},
13
- "episodes": {"multipleValues": "list"},
14
- "event": {"multipleValues": "list"},
15
- "events": {"multipleValues": "list"},
16
- "founder": {"multipleValues": "list"},
17
- "founders": {"multipleValues": "list"},
18
- "itemListElement": {"multipleValues": "list"},
19
- "musicGroupMember": {"multipleValues": "list"},
20
- "performerIn": {"multipleValues": "list"},
21
- "actor": {"multipleValues": "list"},
22
- "actors": {"multipleValues": "list"},
23
- "performer": {"multipleValues": "list"},
24
- "performers": {"multipleValues": "list"},
25
- "producer": {"multipleValues": "list"},
26
- "recipeInstructions": {"multipleValues": "list"},
27
- "season": {"multipleValues": "list"},
28
- "seasons": {"multipleValues": "list"},
29
- "subEvent": {"multipleValues": "list"},
30
- "subEvents": {"multipleValues": "list"},
31
- "track": {"multipleValues": "list"},
32
- "tracks": {"multipleValues": "list"}
4
+ "additionalType": {"subPropertyOf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"}
33
5
  }
34
6
  },
35
- "http://microformats.org/profile/hcard": {
36
- "propertyURI": "vocabulary",
37
- "multipleValues": "unordered"
38
- },
39
- "http://microformats.org/profile/hcalendar#": {
40
- "propertyURI": "vocabulary",
41
- "multipleValues": "unordered",
42
- "properties": {
43
- "categories": {"multipleValues": "list"}
44
- }
45
- }
7
+ "http://microformats.org/profile/hcard": {}
46
8
  }
@@ -37,10 +37,12 @@ module RDF::Microdata
37
37
 
38
38
  # Interface to registry
39
39
  class Registry
40
- # @!attribute [r] uri
41
40
  # @return [RDF::URI] Prefix of vocabulary
42
41
  attr_reader :uri
43
42
 
43
+ # @return [Hash] properties
44
+ attr_reader :properties
45
+
44
46
  ##
45
47
  # Initialize the registry from a URI or file path
46
48
  #
@@ -53,39 +55,23 @@ module RDF::Microdata
53
55
  @prefixes = {}
54
56
  json.each do |prefix, elements|
55
57
  next unless elements.is_a?(Hash)
56
- propertyURI = elements.fetch("propertyURI", "vocabulary").to_sym
57
- multipleValues = elements.fetch("multipleValues", "unordered").to_sym
58
58
  properties = elements.fetch("properties", {})
59
- @prefixes[prefix] = Registry.new(prefix, propertyURI, multipleValues, properties)
59
+ @prefixes[prefix] = Registry.new(prefix, properties)
60
60
  end
61
61
  @registry_uri = registry_uri
62
62
  end
63
-
64
- ##
65
- # True if registry has already been loaded
66
- def self.loaded?
67
- @prefixes.is_a?(Hash)
68
- end
69
63
 
70
64
  ##
71
65
  # Initialize registry for a particular prefix URI
72
66
  #
73
67
  # @param [RDF::URI] prefixURI
74
- # @param [#to_sym] propertyURI (:vocabulary)
75
- # @param [#to_sym] multipleValues (:unordered)
76
68
  # @param [Hash] properties ({})
77
- def initialize(prefixURI, propertyURI = :vocabulary, multipleValues = :unordered, properties = {})
69
+ def initialize(prefixURI, properties = {})
78
70
  @uri = prefixURI
79
- @scheme = propertyURI.to_sym
80
- @multipleValues = multipleValues.to_sym
81
71
  @properties = properties
82
- if @scheme == :vocabulary
83
- @property_base = prefixURI.to_s
84
- # Append a '#' for fragment if necessary
85
- @property_base += '#' unless %w(/ #).include?(@property_base[-1,1])
86
- else
87
- @property_base = 'http://www.w3.org/ns/md?type='
88
- end
72
+ @property_base = prefixURI.to_s
73
+ # Append a '#' for fragment if necessary
74
+ @property_base += '#' unless %w(/ #).include?(@property_base[-1,1])
89
75
  end
90
76
 
91
77
  ##
@@ -94,6 +80,7 @@ module RDF::Microdata
94
80
  # @param [RDF::URI] type
95
81
  # @return [Registry]
96
82
  def self.find(type)
83
+ @prefixes ||= {}
97
84
  k = @prefixes.keys.detect {|key| type.to_s.index(key) == 0 }
98
85
  @prefixes[k] if k
99
86
  end
@@ -116,75 +103,34 @@ module RDF::Microdata
116
103
  u = RDF::URI(ec[:document_base].to_s)
117
104
  u.fragment = frag_escape(name)
118
105
  u
119
- elsif @scheme == :vocabulary
106
+ else
120
107
  # 4) If scheme is vocabulary return the URI reference constructed by appending the fragment escaped value of name to current vocabulary, separated by a U+0023 NUMBER SIGN character (#) unless the current vocabulary ends with either a U+0023 NUMBER SIGN character (#) or SOLIDUS U+002F (/).
121
108
  RDF::URI(@property_base + n)
122
- else # @scheme == :contextual
123
- if ec[:current_name].to_s.index(@property_base) == 0
124
- # 5.2) return the concatenation of s, a U+002E FULL STOP character (.) and the fragment-escaped value of name.
125
- RDF::URI(ec[:current_name] + '.' + n)
126
- else
127
- # 5.3) return the concatenation of http://www.w3.org/ns/md?type=, the fragment-escaped value of current type, the string &prop=, and the fragment-escaped value of name
128
- RDF::URI(@property_base +
129
- frag_escape(ec[:current_type]) +
130
- '&prop=' + n)
131
- end
132
- end
133
- end
134
-
135
- ##
136
- # Turn a predicateURI into a simple token
137
- # @param [RDF::URI] predicateURI
138
- # @return [String]
139
- def tokenize(predicateURI)
140
- case @scheme
141
- when :vocabulary
142
- predicateURI.to_s.sub(@property_base, '')
143
- when :contextual
144
- predicateURI.to_s.split('?prop=').last.split('.').last
145
109
  end
146
110
  end
147
111
 
148
112
  ##
149
- # Determine if property should be serialized as a list or not
113
+ # Yield a equivalentProperty or subPropertyOf if appropriate
150
114
  #
151
115
  # @param [RDF::URI] predicateURI
152
- # @return [Boolean]
153
- def as_list(predicateURI)
116
+ # @yield equiv
117
+ # @yieldparam [RDF::URI] equiv
118
+ def expand(predicateURI)
154
119
  tok = tokenize(predicateURI)
155
- if @properties[tok].is_a?(Hash) &&
156
- @properties[tok].has_key?("multipleValues")
157
- @properties[tok]["multipleValues"].to_sym == :list
158
- else
159
- @multipleValues == :list
120
+ if @properties[tok].is_a?(Hash)
121
+ value = @properties[tok].fetch("subPropertyOf", nil)
122
+ value ||= @properties[tok].fetch("equivalentProperty", nil)
123
+
124
+ Array(value).each {|equiv| yield RDF::URI(equiv)}
160
125
  end
161
126
  end
162
127
 
163
128
  ##
164
- # Yield a equivalentProperty or subPropertyOf if appropriate
165
- #
129
+ # Turn a predicateURI into a simple token
166
130
  # @param [RDF::URI] predicateURI
167
- # @yield statement
168
- # @yieldparam [RDF::Statement] statement
169
- # @return [Boolean]
170
- def expand(predicateURI)
171
- tok = tokenize(predicateURI)
172
- if @properties[tok].is_a?(Hash)
173
- if value = @properties[tok]["equivalentProperty"]
174
- Array(value).each do |v|
175
- yield RDF::Statement.new(predicateURI,
176
- RDF::OWL.equivalentProperty,
177
- RDF::URI(v))
178
- end
179
- elsif value = @properties[tok]["subPropertyOf"]
180
- Array(value).each do |v|
181
- yield RDF::Statement.new(predicateURI,
182
- RDF::RDFS.subPropertyOf,
183
- RDF::URI(v))
184
- end
185
- end
186
- value = @properties[tok]
187
- end
131
+ # @return [String]
132
+ def tokenize(predicateURI)
133
+ predicateURI.to_s.sub(@property_base, '')
188
134
  end
189
135
 
190
136
  ##
@@ -211,9 +157,7 @@ module RDF::Microdata
211
157
  # whether to intern all parsed URIs
212
158
  # @option options [#to_s] :base_uri (nil)
213
159
  # the base URI to use when resolving relative URIs
214
- # @option options [#to_s] :registry_uri (DEFAULT_REGISTRY)
215
- # @option options [Boolean] :vocab_expansion (true)
216
- # whether to perform OWL2 expansion on the resulting graph
160
+ # @option options [#to_s] :registry
217
161
  # @option options [Array] :debug
218
162
  # Array to place debug messages
219
163
  # @return [reader]
@@ -224,7 +168,6 @@ module RDF::Microdata
224
168
  def initialize(input = $stdin, options = {}, &block)
225
169
  super do
226
170
  @debug = options[:debug]
227
- @vocab_expansion = options.fetch(:vocab_expansion, true)
228
171
 
229
172
  @library = :nokogiri
230
173
 
@@ -240,12 +183,12 @@ module RDF::Microdata
240
183
  errors = doc_errors.reject {|e| e.to_s =~ /Tag (audio|source|track|video|time) invalid/}
241
184
  raise RDF::ReaderError, "Syntax errors:\n#{errors}" if !errors.empty? && validate?
242
185
 
243
- add_debug(@doc, "library = #{@library}, expand = #{@vocab_expansion}")
186
+ add_debug(@doc, "library = #{@library}")
244
187
 
245
188
  # Load registry
246
189
  begin
247
- registry_uri = options[:registry_uri] || DEFAULT_REGISTRY
248
- add_debug(@doc, "registry = #{registry_uri}")
190
+ registry_uri = options.fetch(:registry, DEFAULT_REGISTRY)
191
+ add_debug(@doc, "registry = #{registry_uri.inspect}")
249
192
  Registry.load_registry(registry_uri)
250
193
  rescue JSON::ParserError => e
251
194
  raise RDF::ReaderError, "Failed to parse registry: #{e.message}"
@@ -270,16 +213,10 @@ module RDF::Microdata
270
213
  # @return [void]
271
214
  def each_statement(&block)
272
215
  if block_given?
273
- if @vocab_expansion
274
- @vocab_expansion = false
275
- expand.each_statement(&block)
276
- @vocab_expansion = true
277
- else
278
- @callback = block
216
+ @callback = block
279
217
 
280
- # parse
281
- parse_whole_document(@doc, base_uri)
282
- end
218
+ # parse
219
+ parse_whole_document(@doc, base_uri)
283
220
  end
284
221
  enum_for(:each_statement)
285
222
  end
@@ -365,29 +302,14 @@ module RDF::Microdata
365
302
 
366
303
  ec = {
367
304
  :memory => {},
368
- :current_name => nil,
369
305
  :current_type => nil,
370
306
  :current_vocabulary => nil,
371
307
  :document_base => base,
372
308
  }
373
- items = []
374
- # 1) For each element that is also a top-level item run the following algorithm:
375
- #
376
- # 1) Generate the triples for an item item, using the evaluation context. Let result be the (URI reference or blank node) subject returned.
377
- # 2) Append result to item list.
309
+ # 1) For each element that is also a top-level item, Generate the triples for that item using the evaluation context.
378
310
  getItems.each do |el|
379
- result = generate_triples(el, ec)
380
- items << result
311
+ generate_triples(el, ec)
381
312
  end
382
-
383
- # 2) Generate an RDF Collection list from the ordered list of values. Set value to the value returned from generate an RDF Collection.
384
- value = generateRDFCollection(root, items)
385
-
386
- # 3) Generate the following triple:
387
- # subject Document base
388
- # predicate http://www.w3.org/1999/xhtml/microdata#item
389
- # object value
390
- add_triple(doc, base, RDF::MD.item, value) if value
391
313
 
392
314
  add_debug(doc, "parse_whole_doc: traversal complete")
393
315
  end
@@ -422,146 +344,94 @@ module RDF::Microdata
422
344
  type ||= t
423
345
  add_triple(item, subject, RDF.type, t)
424
346
  end
425
-
426
- # 5) If type is an absolute URL, set current name in evaluation context to null.
427
- ec[:current_name] = nil if type
428
347
 
429
- # 6) Otherwise, set type to current type from the Evaluation Context if not empty.
348
+ # 4) Set type to the first value returned from element.itemType of the element defining the item.
349
+
350
+ # 5) Otherwise, set type to current type from the Evaluation Context if not empty.
430
351
  type ||= ec[:current_type]
431
- add_debug(item) {"gentrips(6): type=#{type.inspect}"}
352
+ add_debug(item) {"gentrips(5): type=#{type.inspect}"}
432
353
 
433
- # 7) If the registry contains a URI prefix that is a character for character match of type up to the length of the URI prefix, set vocab as that URI prefix and generate the following triple (unless it has already been generated):
354
+ # 6) If the registry contains a URI prefix that is a character for character match of type up to the length of the URI prefix, set vocab as that URI prefix.
434
355
  vocab = Registry.find(type)
435
- add_debug(item) {"gentrips(7): vocab=#{vocab.inspect}"}
436
- add_triple(item, base_uri, USES_VOCAB, RDF::URI(vocab.uri)) if vocab
437
356
 
438
- # 8) Otherwise, if type is not empty, construct vocab by removing everything following the last SOLIDUS U+002F ("/") or NUMBER SIGN U+0023 ("#") from the path component of type.
357
+ # 7) Otherwise, if type is not empty, construct vocab by removing everything following the last SOLIDUS U+002F ("/") or NUMBER SIGN U+0023 ("#") from the path component of type.
439
358
  vocab ||= begin
440
359
  type_vocab = type.to_s.sub(/([\/\#])[^\/\#]*$/, '\1')
441
- add_debug(item) {"gentrips(8): type_vocab=#{type_vocab.inspect}"}
442
- Registry.new(type_vocab) # if type
360
+ add_debug(item) {"gentrips(7): type_vocab=#{type_vocab.inspect}"}
361
+ Registry.new(type_vocab)
443
362
  end
444
363
 
445
- # 9) Update evaluation context setting current vocabulary to vocab.
364
+ # 8) Update evaluation context setting current vocabulary to vocab.
446
365
  ec[:current_vocabulary] = vocab
447
366
 
448
- # 10) Set property list to an empty mapping between properties and one or more ordered values as established below.
449
- property_list = {}
450
-
451
- # 11. For each element _element_ that has one or more property names and is one of the properties of the item _item_, in the order those elements are given by the algorithm that returns the properties of an item, run the following substep:
367
+ # 9. For each element _element_ that has one or more property names and is one of the properties of the item _item_, run the following substep:
452
368
  props = item_properties(item)
453
- # 11.1. For each name name in element's property names, run the following substeps:
369
+ # 9.1. For each name name in element's property names, run the following substeps:
454
370
  props.each do |element|
455
371
  element.attribute('itemprop').to_s.split(' ').compact.each do |name|
456
- add_debug(item) {"gentrips(11.1): name=#{name.inspect}, type=#{type}"}
457
- # 11.1.1) Let context be a copy of evaluation context with current type set to type and current vocabulary set to vocab.
372
+ add_debug(item) {"gentrips(9.1): name=#{name.inspect}, type=#{type}"}
373
+ # 9.1.1) Let context be a copy of evaluation context with current type set to type and current vocabulary set to vocab.
458
374
  ec_new = ec.merge({:current_type => type, :current_vocabulary => vocab})
459
375
 
460
- # 11.1.2) Let predicate be the result of generate predicate URI using context and name. Update context by setting current name to predicate.
376
+ # 9.1.2) Let predicate be the result of generate predicate URI using context and name. Update context by setting current name to predicate.
461
377
  predicate = vocab.predicateURI(name, ec_new)
462
-
463
- # (Generate Predicate URI steps 6 and 7)
464
- vocab.expand(predicate) do |statement|
465
- add_debug(item) {
466
- "gentrips(11.1.2): expansion #{statement.inspect}"
467
- }
468
- @callback.call(statement)
469
- end
470
378
 
471
- ec_new[:current_name] = predicate
472
- add_debug(item) {"gentrips(11.1.2): predicate=#{predicate}"}
473
-
474
- # 11.1.3) Let value be the property value of element.
379
+ # 9.1.3) Let value be the property value of element.
475
380
  value = property_value(element)
476
- add_debug(item) {"gentrips(11.1.3) value=#{value.inspect}"}
381
+ add_debug(item) {"gentrips(9.1.3) value=#{value.inspect}"}
477
382
 
478
- # 11.1.4) If value is an item, then generate the triples for value context. Replace value by the subject returned from those steps.
383
+ # 9.1.4) If value is an item, then generate the triples for value context. Replace value by the subject returned from those steps.
479
384
  if value.is_a?(Hash)
480
385
  value = generate_triples(element, ec_new)
481
- add_debug(item) {"gentrips(11.1.4): value=#{value.inspect}"}
386
+ add_debug(item) {"gentrips(9.1.4): value=#{value.inspect}"}
482
387
  end
483
388
 
484
- # 11.1.5) Add value to property list for predicate
485
- property_list[predicate] ||= []
486
- property_list[predicate] << value
389
+ # 9.1.4) Generate the following triple:
390
+ add_triple(item, subject, predicate, value)
391
+
392
+ # 9.1.5) If an entry exists in the registry for name in the vocabulary associated with vocab having the key subPropertyOf or equivalentProperty
393
+ vocab.expand(predicate) do |equiv|
394
+ # for each such value equiv, generate the following triple
395
+ add_triple(item, subject, equiv, value)
396
+ end
487
397
  end
488
398
  end
489
399
 
490
- # 11r. For each element _element_ that has one or more property names and is one of the reverse properties of the item _item_, in the order those elements are given by the algorithm that returns the properties of an item, run the following substep:
400
+ # 10. For each element element that has one or more reverse property names and is one of the reverse properties of the item item, run the following substep:
491
401
  props = item_properties(item, true)
492
- # 11r.1. For each name name in element's reverse property names, run the following substeps:
402
+ # 10.1. For each name name in element's reverse property names, run the following substeps:
493
403
  props.each do |element|
494
404
  element.attribute('itemprop-reverse').to_s.split(' ').compact.each do |name|
495
- add_debug(item) {"gentrips(11r.1): name=#{name.inspect}, type=#{type}"}
496
- # 11r.1.1) Let context be a copy of evaluation context with current type set to type and current vocabulary set to vocab.
405
+ add_debug(item) {"gentrips(10.1): name=#{name.inspect}"}
406
+ # 10.1.1) Let context be a copy of evaluation context with current type set to type and current vocabulary set to vocab.
497
407
  ec_new = ec.merge({:current_type => type, :current_vocabulary => vocab})
498
408
 
499
- # 11r.1.2) Let predicate be the result of generate predicate URI using context and name. Update context by setting current name to predicate.
409
+ # 10.1.2) Let predicate be the result of generate predicate URI using context and name. Update context by setting current name to predicate.
500
410
  predicate = vocab.predicateURI(name, ec_new)
501
411
 
502
- # (Generate Predicate URI steps 6 and 7)
503
- vocab.expand(predicate) do |statement|
504
- add_debug(item) {
505
- "gentrips(11.1.2): expansion #{statement.inspect}"
506
- }
507
- @callback.call(statement)
508
- end
509
-
510
- ec_new[:current_name] = predicate
511
- add_debug(item) {"gentrips(11r.1.2): predicate=#{predicate}"}
512
-
513
- # 11r.1.3) Let value be the property value of element.
412
+ # 10.1.3) Let value be the property value of element.
514
413
  value = property_value(element)
515
- add_debug(item) {"gentrips(11r.1.3) value=#{value.inspect}"}
414
+ add_debug(item) {"gentrips(10.1.3) value=#{value.inspect}"}
516
415
 
517
- # 11r.1.4) If value is an item, then generate the triples for value context. Replace value by the subject returned from those steps.
416
+ # 10.1.4) If value is an item, then generate the triples for value context. Replace value by the subject returned from those steps.
518
417
  if value.is_a?(Hash)
519
418
  value = generate_triples(element, ec_new)
520
- add_debug(item) {"gentrips(11.1.4): value=#{value.inspect}"}
419
+ add_debug(item) {"gentrips(10.1.4): value=#{value.inspect}"}
521
420
  elsif value.is_a?(RDF::Literal)
522
- # 11r.1.4r) Otherwise, if value is a literal, ignore the value and continue to the next name; it is an error for the value of @itemprop-reverse to be a literal
421
+ # 10.1.5) Otherwise, if value is a literal, ignore the value and continue to the next name; it is an error for the value of @itemprop-reverse to be a literal
523
422
  add_error(element, "Value of @itemprop-reverse may not be a literal: #{value.inspect}")
524
423
  next
525
424
  end
526
425
 
527
- # 11r.1.5r) Generate a property value using value as the subject and subject as the object
528
- generatePropertyValues(item, value, predicate, [subject])
426
+ # 10.1.6) Generate the following triple
427
+ add_triple(item, value, predicate, subject)
529
428
  end
530
429
  end
531
430
 
532
- # 12) For each predicate in property list
533
- property_list.each do |predicate, values|
534
- generatePropertyValues(item, subject, predicate, values)
535
- end
536
-
431
+ # 11) Return subject
537
432
  subject
538
433
  end
539
434
 
540
- def generatePropertyValues(element, subject, predicate, values)
541
- # If the registry contains a URI prefix that is a character for character match of predicate up to the length of the URI prefix, set vocab as that URI prefix. Otherwise set vocab to null
542
- registry = Registry.find(predicate)
543
- add_debug("generatePropertyValues") { "list(#{predicate})? #{registry.as_list(predicate).inspect}"} if registry
544
- if registry && registry.as_list(predicate)
545
- value = generateRDFCollection(element, values)
546
- add_triple(element, subject, predicate, value)
547
- else
548
- values.each {|v| add_triple(element, subject, predicate, v)}
549
- end
550
- end
551
-
552
- ##
553
- # Called when values has more than one entry
554
- # @param [Nokogiri::XML::Element] element
555
- # @param [Array<RDF::Value>] values
556
- # @return [RDF::Node]
557
- def generateRDFCollection(element, values)
558
- list = RDF::List.new(nil, nil, values)
559
- list.each_statement do |st|
560
- add_triple(element, st.subject, st.predicate, st.object) unless st.object == RDF.List
561
- end
562
- list.subject
563
- end
564
-
565
435
  ##
566
436
  # To find the properties of an item defined by the element root, the user agent must try to crawl the properties of the element root, with an empty list as the value of memory: if this fails, then the properties of the item defined by the element root is an empty list; otherwise, it is the returned list.
567
437
  #
@@ -670,8 +540,15 @@ module RDF::Microdata
670
540
  {}
671
541
  when element.name == 'meta'
672
542
  RDF::Literal.new(element.attribute('content').to_s, :language => element.language)
673
- when element.name == 'data'
543
+ when %w(data meter).include?(element.name)
674
544
  RDF::Literal.new(element.attribute('value').to_s, :language => element.language)
545
+ # Lexically scan value and assign appropriate type, otherwise, leave untyped
546
+ v = element.attribute('value').to_s
547
+ datatype = %w(Integer Float Double).map {|t| RDF::Literal.const_get(t)}.detect do |dt|
548
+ v.match(dt::GRAMMAR)
549
+ end || RDF::Literal
550
+ datatype = RDF::Literal::Double if datatype == RDF::Literal::Float
551
+ datatype.new(v)
675
552
  when %w(audio embed iframe img source track video).include?(element.name)
676
553
  uri(element.attribute('src'), base)
677
554
  when %w(a area link).include?(element.name)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-microdata
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: '2.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-02 00:00:00.000000000 Z
12
+ date: 2014-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdf
@@ -82,53 +82,75 @@ dependencies:
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0.3'
84
84
  - !ruby/object:Gem::Dependency
85
- name: open-uri-cached
85
+ name: yard
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: '0.0'
91
- - - ">="
90
+ version: '0.8'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '0.8'
98
+ - !ruby/object:Gem::Dependency
99
+ name: spira
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '='
92
103
  - !ruby/object:Gem::Version
93
- version: 0.0.5
104
+ version: 0.0.12
94
105
  type: :development
95
106
  prerelease: false
96
107
  version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '='
110
+ - !ruby/object:Gem::Version
111
+ version: 0.0.12
112
+ - !ruby/object:Gem::Dependency
113
+ name: rack-cache
114
+ requirement: !ruby/object:Gem::Requirement
97
115
  requirements:
98
116
  - - "~>"
99
117
  - !ruby/object:Gem::Version
100
- version: '0.0'
101
- - - ">="
118
+ version: '1.2'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
102
124
  - !ruby/object:Gem::Version
103
- version: 0.0.5
125
+ version: '1.2'
104
126
  - !ruby/object:Gem::Dependency
105
- name: yard
127
+ name: rest-client
106
128
  requirement: !ruby/object:Gem::Requirement
107
129
  requirements:
108
130
  - - "~>"
109
131
  - !ruby/object:Gem::Version
110
- version: '0.8'
132
+ version: '1.7'
111
133
  type: :development
112
134
  prerelease: false
113
135
  version_requirements: !ruby/object:Gem::Requirement
114
136
  requirements:
115
137
  - - "~>"
116
138
  - !ruby/object:Gem::Version
117
- version: '0.8'
139
+ version: '1.7'
118
140
  - !ruby/object:Gem::Dependency
119
- name: spira
141
+ name: rest-client-components
120
142
  requirement: !ruby/object:Gem::Requirement
121
143
  requirements:
122
- - - '='
144
+ - - "~>"
123
145
  - !ruby/object:Gem::Version
124
- version: 0.0.12
146
+ version: '1.3'
125
147
  type: :development
126
148
  prerelease: false
127
149
  version_requirements: !ruby/object:Gem::Requirement
128
150
  requirements:
129
- - - '='
151
+ - - "~>"
130
152
  - !ruby/object:Gem::Version
131
- version: 0.0.12
153
+ version: '1.3'
132
154
  - !ruby/object:Gem::Dependency
133
155
  name: rspec
134
156
  requirement: !ruby/object:Gem::Requirement
@@ -253,7 +275,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
253
275
  version: '0'
254
276
  requirements: []
255
277
  rubyforge_project: rdf-microdata
256
- rubygems_version: 2.2.2
278
+ rubygems_version: 2.4.3
257
279
  signing_key:
258
280
  specification_version: 4
259
281
  summary: Microdata reader for Ruby.