Module: LinkedVocabs
- Defined in:
- lib/linked_vocabs.rb,
lib/linked_vocabs/version.rb,
lib/linked_vocabs/controlled.rb
Defined Under Namespace
Modules: Controlled, Validators, Vocabularies
Constant Summary
collapse
- VERSION =
'0.3.1'
Class Method Summary
collapse
Class Method Details
.add_vocabulary(name, prefix, args = {}) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/linked_vocabs.rb', line 23
def add_vocabulary(name, prefix, args = {})
name = name.to_sym
source = args.delete :source
strict = args.delete :strict
fetch = args.delete :fetch
raise "Unexpected arguments #{args.keys}. Accepted parameters are :source, :strict, and :fetch." unless args.empty?
vocabularies[name] = {
:prefix => prefix.to_s,
:strict => strict,
:fetch => fetch
}
vocabularies[name][:source] = source if source
vocabularies[name][:strict] = false if vocabularies[name][:strict].nil? or !source
vocabularies[name][:fetch] = false if vocabularies[name][:fetch].nil? or !source
end
|
.load_all ⇒ Object
70
71
72
73
74
|
# File 'lib/linked_vocabs.rb', line 70
def load_all
vocabularies.each_key do |name|
load_vocabulary(name)
end
end
|
.load_vocabulary(name, path = 'lib/rdf/') ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/linked_vocabs.rb', line 41
def load_vocabulary(name, path = 'lib/rdf/')
raise "Unregistered vocabulary #{name}" unless vocabularies.has_key? name
v = vocabularies[name]
out = StringIO.new
class_name = name.to_s.upcase
if v.fetch(:fetch, true)
loader = RDF::VocabularyLoader.new(class_name)
loader.uri = v[:prefix]
loader.source = v[:source] if v[:source]
loader. = v[:extra] if v[:extra]
loader.strict = v.fetch(:strict, true)
loader.output = out
loader.run
else
out.print %(# -*- encoding: utf-8 -*-
# This file generated automatically using vocab-fetch from #{v.fetch(:source, v[:prefix])}
require 'rdf'
module RDF
class #{class_name} < RDF::#{"Strict" if v.fetch(:strict, true)}Vocabulary("#{v[:prefix]}")
# terms not fetched by vocab-fetch
end
end
).gsub(/^ /, '')
end
out.rewind
File.open(File.join(path, "#{name}.rb"), "w") {|f| f.write out.read}
end
|
.vocabularies ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/linked_vocabs.rb', line 14
def vocabularies
@vocabularies ||= {
:dcmitype => { :prefix => 'http://purl.org/dc/dcmitype/', :source => 'http://dublincore.org/2012/06/14/dctype.rdf' },
:geonames => { :prefix => 'http://sws.geonames.org/', :strict => false, :fetch => false },
:lcsh => { :prefix => 'http://id.loc.gov/authorities/subjects/', :strict => false, :fetch => false }
}
end
|