Permalink
Browse files

Add rdfa:usesVocabulary output.

  • Loading branch information...
gkellogg committed Sep 20, 2012
1 parent 584b210 commit 29b72a0e3241684ce68ff0a951546eb366db1782
Showing with 25 additions and 7 deletions.
  1. +1 −0 .gemspec
  2. +7 −0 Gemfile.lock
  3. +7 −2 lib/rdf/microdata/reader.rb
  4. +1 −0 spec/matchers.rb
  5. +3 −3 spec/reader_spec.rb
  6. +3 −1 spec/test-files/example2.ttl
  7. +3 −1 spec/test-files/example3.ttl
View
@@ -41,6 +41,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'spira', '>= 0.0.12'
gem.add_development_dependency 'rspec', '>= 2.8.0'
gem.add_development_dependency 'rdf-spec', '>= 0.3.4'
+ gem.add_development_dependency 'rdf-rdfa', '>= 0.3.15'
gem.add_development_dependency 'rdf-turtle', '>= 0.1.0'
gem.add_development_dependency 'rdf-isomorphic', '>= 0.3.4'
gem.post_install_message = nil
View
@@ -14,6 +14,7 @@ GEM
diff-lcs (1.1.3)
equivalent-xml (0.2.9)
nokogiri (>= 1.4.3)
+ haml (3.1.7)
htmlentities (4.3.1)
json (1.7.5)
json (1.7.5-java)
@@ -24,6 +25,11 @@ GEM
addressable (>= 2.2.6)
rdf-isomorphic (0.3.4)
rdf (>= 0.2.3)
+ rdf-rdfa (0.3.15)
+ haml (>= 3.1.6)
+ htmlentities (>= 4.3.0)
+ rdf (>= 0.3.5)
+ rdf-xsd (>= 0.3.7)
rdf-spec (0.3.8)
rspec (>= 2.8.0)
rdf-turtle (0.1.2)
@@ -54,6 +60,7 @@ DEPENDENCIES
nokogiri (>= 1.5.0)
rdf-isomorphic (>= 0.3.4)
rdf-microdata!
+ rdf-rdfa (>= 0.3.15)
rdf-spec (>= 0.3.4)
rdf-turtle (>= 0.1.0)
rspec (>= 2.8.0)
@@ -19,6 +19,7 @@ class Reader < RDF::Reader
format Format
URL_PROPERTY_ELEMENTS = %w(a area audio embed iframe img link object source track video)
DEFAULT_REGISTRY = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "etc", "registry.json"))
+ USES_VOCAB = RDF::URI("http://www.w3.org/ns/rdfa#usesVocabulary")
class CrawlFailure < StandardError #:nodoc:
end
@@ -42,6 +43,9 @@ def base_uri
# Interface to registry
class Registry
+ # @attr_reader [RDF::URI] uri Prefix of vocabulary
+ attr_reader :uri
+
##
# Initialize the registry from a URI or file path
#
@@ -76,6 +80,7 @@ def self.loaded?
# @param [#to_sym] multipleValues (:unordered)
# @param [Hash] properties ({})
def initialize(prefixURI, propertyURI = :vocabulary, multipleValues = :unordered, properties = {})
+ @uri = prefixURI
@scheme = propertyURI.to_sym
@multipleValues = multipleValues.to_sym
@properties = properties
@@ -397,9 +402,9 @@ def generate_triples(item, ec = {})
type ||= ec[:current_type]
add_debug(item) {"gentrips(6): type=#{type.inspect}"}
- # 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
+ # 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):
vocab = Registry.find(type)
+ add_triple(item, base_uri, USES_VOCAB, RDF::URI(vocab.uri)) if vocab
# 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.
View
@@ -1,5 +1,6 @@
require 'rdf/isomorphic'
require 'rspec/matchers'
+require 'rdf/rdfa'
RSpec::Matchers.define :have_xpath do |xpath, value|
match do |actual|
View
@@ -636,7 +636,7 @@
%q(
<> <http://www.w3.org/ns/md#item> (
[ a <http://foo/bar>; <http://foo/baz> "FooBar" ]
- ) .
+ ).
)
],
"http://foo#bar + baz => http://foo#baz" =>
@@ -686,7 +686,7 @@
<> <http://www.w3.org/ns/md#item> (
[ a <http://contextual.unordered/>;
<http://www.w3.org/ns/md?type=http://contextual.unordered/&prop=baz> "FooBar" ]
- ) .
+ ); <http://www.w3.org/ns/rdfa#usesVocabulary> <http://contextual.unordered/> .
)
],
"http://contextual.unordered/ + bar + baz => http://www.w3.org/ns/md?type=http://contextual.unordered/&prop=bar.baz" =>
@@ -701,7 +701,7 @@
[ a <http://contextual.unordered/>;
<http://www.w3.org/ns/md?type=http://contextual.unordered/&prop=bar> [
<http://www.w3.org/ns/md?type=http://contextual.unordered/&prop=bar.baz> "Baz"]]
- )
+ ); <http://www.w3.org/ns/rdfa#usesVocabulary> <http://contextual.unordered/> .
)
],
}.each do |name, (md, nt)|
@@ -1,5 +1,6 @@
@prefix md: <http://www.w3.org/ns/md#> .
@prefix hcard: <http://microformats.org/profile/hcard#> .
+@prefix rdfa: <http://www.w3.org/ns/rdfa#> .
<> md:item (
[ a <http://microformats.org/profile/hcard>;
@@ -11,6 +12,7 @@
hcard:fn "Trekkie";
hcard:n [ hcard:given-name "Trekkie" ];
hcard:adr _:a
- ]) .
+ ]);
+ rdfa:usesVocabulary <http://microformats.org/profile/hcard> .
_:a hcard:street-address "Avenue Q" .
@@ -1,6 +1,7 @@
@prefix md: <http://www.w3.org/ns/md#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix schema: <http://schema.org/> .
+@prefix rdfa: <http://www.w3.org/ns/rdfa#> .
<> md:item ([ a schema:MusicPlaylist;
schema:name "Classic Rock Playlist";
@@ -15,4 +16,5 @@
schema:byArtist ("AC/DC");;
schema:name "Shook you all Night Long";
schema:url <shook-you-all-night-long>]
- )]); .
+ )]);
+ rdfa:usesVocabulary <http://schema.org/> .

0 comments on commit 29b72a0

Please sign in to comment.