Last active
January 4, 2016 03:39
-
-
Save no-reply/8563178 to your computer and use it in GitHub Desktop.
Using Vocabulary Loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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