-
Notifications
You must be signed in to change notification settings - Fork 5
/
dsl.rb
72 lines (63 loc) · 1.55 KB
/
dsl.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
68
69
70
71
72
module PubliSci
module DSL
attr_reader :base_url
class Instance
include PubliSci::DSL
end
# Use to set base url for whole script; helps when referring to dataset
# resources from metadata and
def base_url=(url)
@base_url = url
Prov.base_url=url
end
def data(&block)
inst=PubliSci::Dataset::DSL::Instance.new
inst.instance_eval(&block)
@_dsl_data ||= [] << inst
inst
end
def metadata(&block)
inst=PubliSci::Metadata::DSL::Instance.new
inst.instance_eval(&block)
@_dsl_metadata = inst
inst
end
def provenance(&block)
inst=PubliSci::Prov::DSL::Instance.new
inst.instance_eval(&block)
@_dsl_prov = inst
inst
end
def configuration
@_dsl_config ||= DSL::Configuration.new
end
def configure
yield configuration
end
def settings
configuration
end
def generate_n3
out = ""
@_dsl_data.each{|dat| out << dat.generate_n3 } if @_dsl_data
out << @_dsl_metadata.generate_n3 if @_dsl_metadata
out << @_dsl_prov.generate_n3 if @_dsl_prov
out
end
def to_repository(turtle_string=generate_n3)
repo = settings.repository
case repo
when :in_memory
repo = RDF::Repository.new
when :fourstore
repo = RDF::FourStore::Repository.new('http://localhost:8080')
end
f=Tempfile.new(['repo','.ttl'])
f.write(turtle_string)
f.close
repo.load(f.path, :format => :ttl).to_s
f.unlink
repo
end
end
end