Skip to content

Instantly share code, notes, and snippets.

@no-reply
Last active January 4, 2016 03:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save no-reply/8563178 to your computer and use it in GitHub Desktop.
Save no-reply/8563178 to your computer and use it in GitHub Desktop.
Using Vocabulary Loader
# The ruby-rdf vocabulary loader is used to maintain the vocabularies in the core library.
# There's a rake task that is the main way it is used and serves as a good reference.
# https://github.com/ruby-rdf/rdf/blob/develop/Rakefile
rake gen_vocabs
# Generate lib/rdf/vocab/cc.rb
# Generate lib/rdf/vocab/cert.rb
# Generate lib/rdf/vocab/dc.rb
# Generate lib/rdf/vocab/dc11.rb
# ...
# If you want to add vocabularies, you can do that in the Rakefile
# or you can just use the VocabularyLoader class
VOCABS = {
:dc => {:prefix => "http://purl.org/dc/terms/"},
:dc11 => {:prefix => "http://purl.org/dc/elements/1.1/"}
}
VOCABS.each do |id, v|
puts "Generate some/path/#{id}.rb"
begin
out = StringIO.new
loader = OregonDigital::RDF::VocabularyLoader.new(id.to_s.upcase)
loader.prefix = v[:prefix]
loader.source = v[:source] if v[:source]
loader.extra = v[:extra] if v[:extra]
loader.fetch = v.fetch(:fetch, true)
loader.strict = v.fetch(:strict, true)
loader.output = out
loader.run
out.rewind
File.open("some/path/#{id}.rb", "w") {|f| f.write out.read}
rescue
puts "Failed to load #{id}: #{$!.message}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment