rdf-microdata 2.0 → 2.0.1

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: d7797313b5b2b13d2c97e2ca613839ca72525064
4
- data.tar.gz: 6b955e34556a727e14b88a9b776b10b0d14f2f29
3
+ metadata.gz: b1d1b0be6be75b9604495e5571840eae3d760b5c
4
+ data.tar.gz: 72ea12e35779e10447eabd3965238533e892816b
5
5
  SHA512:
6
- metadata.gz: 4a68bb3d267426ffaa041f84f5f1b6cf195f15546593701c95c9bcfc672903726c421bed60546d330d80437c23adcd264b1b2c0ac7b27baeb11422744d3c1d3e
7
- data.tar.gz: da17e2b59b28bca0ca9c65476ef44486ce81058254655389bea7fa447860ec562100783c81d24b0597487def25443f135e132eb0b0148d6b6db1bd614dfb6f59
6
+ metadata.gz: 1bb225e865fe2e48b4606d67ccb04f5bce62b4dfa30c5a29d99217e4007ab290f273725eedf1682cb9d8e3e3a9facc2df4de6c1b8f22014d0bab951214a97967
7
+ data.tar.gz: 0f8cad8716484382a1b0286d66245698c37d8e4e81456d2cc3a0018be1e23fe13ff4875e0bf598a9df94359a3ae24547db14913571c69011fc0964cd40f94071
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0
1
+ 2.0.1
data/etc/doap.html CHANGED
@@ -22,11 +22,14 @@
22
22
  http://github.com/ruby-rdf/rdf-microdata/issues
23
23
  </a>
24
24
  </dd>
25
- <dt>Category</dt><dd itemprop="category">
26
- <a href="http://dbpedia.org/resource/Resource_Description_Framework">Resource Description Framework</a>
25
+ <dt>Category</dt><dd>
26
+ <a itemprop="category" href="http://dbpedia.org/resource/Resource_Description_Framework">Resource Description Framework</a>
27
27
  for
28
28
  <a itemprop="programming-language" href="http://dbpedia.org/resource/Ruby_(programming_language)">Ruby</a>
29
29
  </dd>
30
+ <dt>Implements</dt><dd>
31
+ <a itemprop="implements" href="http://www.w3.org/TR/microdata-rdf/">Microdata to RDF</a>
32
+ </dd>
30
33
  <dt>Download</dt><dd><a href="http://rubygems.org/gems/rdf-microdata" itemprop="download-page">
31
34
  http://rubygems.org/gems/rdf-microdata
32
35
  </a></dd>
data/etc/doap.nt CHANGED
@@ -2,7 +2,6 @@
2
2
  <http://rubygems.org/gems/rdf-microdata> <http://usefulinc.com/ns/doap#shortdesc> "Microdata reader for Ruby."@en .
3
3
  <http://rubygems.org/gems/rdf-microdata> <http://usefulinc.com/ns/doap#description> "\n RDF::Microdata is an Microdata reader for Ruby using the RDF.rb library suite.\n "@en .
4
4
  <http://rubygems.org/gems/rdf-microdata> <http://usefulinc.com/ns/doap#name> "RDF::Microdata" .
5
- <http://rubygems.org/gems/rdf-microdata> <http://usefulinc.com/ns/doap#category> "\n Resource Description Framework\n for\n Ruby\n " .
6
5
  <http://rubygems.org/gems/rdf-microdata> <http://purl.org/dc/terms/creator> <http://greggkellogg.net/foaf#me> .
7
6
  <http://rubygems.org/gems/rdf-microdata> <http://usefulinc.com/ns/doap#developer> <http://greggkellogg.net/foaf#me> .
8
7
  <http://rubygems.org/gems/rdf-microdata> <http://usefulinc.com/ns/doap#documenter> <http://greggkellogg.net/foaf#me> .
@@ -11,7 +10,9 @@
11
10
  <http://rubygems.org/gems/rdf-microdata> <http://usefulinc.com/ns/doap#created> "2011-08-29"^^<http://www.w3.org/2001/XMLSchema#date> .
12
11
  <http://rubygems.org/gems/rdf-microdata> <http://usefulinc.com/ns/doap#blog> <http://greggkellogg.net/> .
13
12
  <http://rubygems.org/gems/rdf-microdata> <http://usefulinc.com/ns/doap#bug-database> <http://github.com/ruby-rdf/rdf-microdata/issues> .
13
+ <http://rubygems.org/gems/rdf-microdata> <http://usefulinc.com/ns/doap#category> <http://dbpedia.org/resource/Resource_Description_Framework> .
14
14
  <http://rubygems.org/gems/rdf-microdata> <http://usefulinc.com/ns/doap#programming-language> <http://dbpedia.org/resource/Ruby_(programming_language)> .
15
+ <http://rubygems.org/gems/rdf-microdata> <http://usefulinc.com/ns/doap#implements> <http://www.w3.org/TR/microdata-rdf/> .
15
16
  <http://rubygems.org/gems/rdf-microdata> <http://usefulinc.com/ns/doap#download-page> <http://rubygems.org/gems/rdf-microdata> .
16
17
  <http://rubygems.org/gems/rdf-microdata> <http://usefulinc.com/ns/doap#homepage> <http://github.com/ruby-rdf/rdf-microdata> .
17
18
  <http://rubygems.org/gems/rdf-microdata> <http://usefulinc.com/ns/doap#license> <http://creativecommons.org/licenses/publicdomain/> .
data/etc/doap.ttl ADDED
@@ -0,0 +1,27 @@
1
+ @prefix dc: <http://purl.org/dc/terms/> .
2
+ @prefix doap: <http://usefulinc.com/ns/doap#> .
3
+ @prefix foaf: <http://xmlns.com/foaf/0.1/> .
4
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
5
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
6
+
7
+ <http://rubygems.org/gems/rdf-microdata> a doap:Project;
8
+ dc:creator <http://greggkellogg.net/foaf#me>;
9
+ doap:blog <http://greggkellogg.net/>;
10
+ doap:bug-database <http://github.com/ruby-rdf/rdf-microdata/issues>;
11
+ doap:category <http://dbpedia.org/resource/Resource_Description_Framework>;
12
+ doap:created "2011-08-29"^^xsd:date;
13
+ doap:description """
14
+ RDF::Microdata is an Microdata reader for Ruby using the RDF.rb library suite.
15
+ """@en;
16
+ doap:developer <http://greggkellogg.net/foaf#me>;
17
+ doap:documenter <http://greggkellogg.net/foaf#me>;
18
+ doap:download-page <http://rubygems.org/gems/rdf-microdata>;
19
+ doap:homepage <http://github.com/ruby-rdf/rdf-microdata>;
20
+ doap:implements <http://www.w3.org/TR/microdata-rdf/>;
21
+ doap:license <http://creativecommons.org/licenses/publicdomain/>;
22
+ doap:mailing-list <http://lists.w3.org/Archives/Public/public-rdf-ruby/>;
23
+ doap:maintainer <http://greggkellogg.net/foaf#me>;
24
+ doap:name "RDF::Microdata";
25
+ doap:programming-language <http://dbpedia.org/resource/Ruby_(programming_language)>;
26
+ doap:shortdesc "Microdata reader for Ruby."@en;
27
+ foaf:creator <http://greggkellogg.net/foaf#me> .
@@ -49,7 +49,7 @@ module RDF::Microdata
49
49
  # @param [String] registry_uri
50
50
  def self.load_registry(registry_uri)
51
51
  return if @registry_uri == registry_uri
52
-
52
+
53
53
  json = RDF::Util::File.open_file(registry_uri) { |f| JSON.load(f) }
54
54
 
55
55
  @prefixes = {}
@@ -187,7 +187,7 @@ module RDF::Microdata
187
187
 
188
188
  # Load registry
189
189
  begin
190
- registry_uri = options.fetch(:registry, DEFAULT_REGISTRY)
190
+ registry_uri = options[:registry] || DEFAULT_REGISTRY
191
191
  add_debug(@doc, "registry = #{registry_uri.inspect}")
192
192
  Registry.load_registry(registry_uri)
193
193
  rescue JSON::ParserError => e
@@ -391,6 +391,7 @@ module RDF::Microdata
391
391
 
392
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
393
  vocab.expand(predicate) do |equiv|
394
+ add_debug(item) {"gentrips(9.1.5): equiv=#{equiv.inspect}"}
394
395
  # for each such value equiv, generate the following triple
395
396
  add_triple(item, subject, equiv, value)
396
397
  end
@@ -441,11 +442,9 @@ module RDF::Microdata
441
442
  # List of property elements for an item
442
443
  def item_properties(item, reverse = false)
443
444
  add_debug(item, "item_properties (#{reverse.inspect})")
444
- results, errors = crawl_properties(item, [], reverse)
445
- raise CrawlFailure, "item_props: errors=#{errors}" if errors > 0
446
- results
445
+ crawl_properties(item, [], reverse)
447
446
  rescue CrawlFailure => e
448
- add_error(element, e.message)
447
+ add_error(item, e.message)
449
448
  return []
450
449
  end
451
450
 
@@ -455,48 +454,42 @@ module RDF::Microdata
455
454
  # @param [Nokogiri::XML::Element] root
456
455
  # @param [Array<Nokokogiri::XML::Element>] memory
457
456
  # @param [Boolean] reverse crawl reverse properties
458
- # @return [Array<Array<Nokogiri::XML::Element>, Integer>]
459
- # Resultant elements and error count
457
+ # @return [Array<Nokogiri::XML::Element>]
458
+ # Resultant elements
460
459
  def crawl_properties(root, memory, reverse)
461
-
462
460
  # 1. If root is in memory, then the algorithm fails; abort these steps.
463
461
  raise CrawlFailure, "crawl_props mem already has #{root.inspect}" if memory.include?(root)
464
462
 
465
463
  # 2. Collect all the elements in the item root; let results be the resulting list of elements, and errors be the resulting count of errors.
466
- results, errors = elements_in_item(root)
467
- add_debug(root) {"crawl_properties reverse=#{reverse.inspect} results=#{results.map {|e| node_path(e)}.inspect}, errors=#{errors}"}
464
+ results = elements_in_item(root)
465
+ add_debug(root) {"crawl_properties reverse=#{reverse.inspect} results=#{results.map {|e| node_path(e)}.inspect}"}
468
466
 
469
467
  # 3. Remove any elements from results that do not have an @itemprop (@itemprop-reverse) attribute specified.
470
468
  results = results.select {|e| e.has_attribute?(reverse ? 'itemprop-reverse' : 'itemprop')}
471
469
 
472
470
  # 4. Let new memory be a new list consisting of the old list memory with the addition of root.
471
+ raise CrawlFailure, "itemref recursion" if memory.detect {|n| root.node.object_id == n.node.object_id}
473
472
  new_memory = memory + [root]
474
473
 
475
474
  # 5. For each element in results that has an @itemscope attribute specified, crawl the properties of the element, with new memory as the memory.
476
475
  results.select {|e| e.has_attribute?('itemscope')}.each do |element|
477
- begin
478
- crawl_properties(element, new_memory, reverse)
479
- rescue CrawlFailure => e
480
- # If this fails, then remove the element from results and increment errors. (If it succeeds, the return value is discarded.)
481
- memory -= element
482
- add_error(element, e.message)
483
- errors += 1
484
- end
476
+ crawl_properties(element, new_memory, reverse)
485
477
  end
486
478
 
487
- [results, errors]
479
+ results
488
480
  end
489
481
 
490
482
  ##
491
- # To collect all the elements in the item root, the user agent must run these steps. They return a list of elements and a count of errors.
483
+ # To collect all the elements in the item root, the user agent must run these steps. They return a list of elements.
492
484
  #
493
485
  # @param [Nokogiri::XML::Element] root
494
- # @return [Array<Array<Nokogiri::XML::Element>, Integer>]
486
+ # @return Array<Nokogiri::XML::Element>]
495
487
  # Resultant elements and error count
488
+ # @raise CrawlFailure on element recursion
496
489
  def elements_in_item(root)
497
490
  # Let results and pending be empty lists of elements.
498
491
  # Let errors be zero.
499
- results, errors = [], 0
492
+ results, memory, errors = [], [], 0
500
493
 
501
494
  # Add all the children elements of root to pending.
502
495
  pending = root.elements
@@ -514,20 +507,19 @@ module RDF::Microdata
514
507
 
515
508
  # Loop: Remove an element from pending and let current be that element.
516
509
  while current = pending.shift
517
- if results.include?(current)
518
- # If current is already in results, increment errors.
519
- add_error(current, "elements_in_item: results already includes #{current.inspect}")
520
- errors += 1
510
+ if memory.include?(current)
511
+ raise CrawlFailure, "elements_in_item: results already includes #{current.inspect}"
521
512
  elsif !current.has_attribute?('itemscope')
522
513
  # If current is not already in results and current does not have an itemscope attribute, then: add all the child elements of current to pending.
523
514
  pending += current.elements
524
515
  end
516
+ memory << current
525
517
 
526
518
  # If current is not already in results, then: add current to results.
527
519
  results << current unless results.include?(current)
528
520
  end
529
521
 
530
- [results, errors]
522
+ results
531
523
  end
532
524
 
533
525
  ##
@@ -540,8 +532,7 @@ module RDF::Microdata
540
532
  {}
541
533
  when element.name == 'meta'
542
534
  RDF::Literal.new(element.attribute('content').to_s, :language => element.language)
543
- when %w(data meter).include?(element.name)
544
- RDF::Literal.new(element.attribute('value').to_s, :language => element.language)
535
+ when %w(data meter).include?(element.name) && element.attribute('value')
545
536
  # Lexically scan value and assign appropriate type, otherwise, leave untyped
546
537
  v = element.attribute('value').to_s
547
538
  datatype = %w(Integer Float Double).map {|t| RDF::Literal.const_get(t)}.detect do |dt|
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: '2.0'
4
+ version: 2.0.1
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-12-16 00:00:00.000000000 Z
12
+ date: 2015-04-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdf
@@ -247,6 +247,7 @@ files:
247
247
  - VERSION
248
248
  - etc/doap.html
249
249
  - etc/doap.nt
250
+ - etc/doap.ttl
250
251
  - etc/registry.json
251
252
  - lib/rdf/microdata.rb
252
253
  - lib/rdf/microdata/expansion.rb