publisci 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/.travis.yml +13 -0
- data/Gemfile +36 -0
- data/LICENSE.txt +20 -0
- data/README.md +51 -0
- data/README.rdoc +48 -0
- data/Rakefile +68 -0
- data/bin/bio-publisci +106 -0
- data/bin/bio-publisci-server +50 -0
- data/examples/bio-band_integration.rb +9 -0
- data/examples/no_magic.prov +58 -0
- data/examples/no_magic.rb +58 -0
- data/examples/orm.prov +48 -0
- data/examples/primer-full.prov +120 -0
- data/examples/primer.prov +66 -0
- data/examples/prov_dsl.prov +85 -0
- data/examples/safe_gen.rb +7 -0
- data/examples/visualization/primer.prov +66 -0
- data/examples/visualization/prov_viz.rb +140 -0
- data/examples/visualization/viz.rb +35 -0
- data/features/create_generator.feature +21 -0
- data/features/integration.feature +12 -0
- data/features/integration_steps.rb +10 -0
- data/features/metadata.feature +37 -0
- data/features/metadata_steps.rb +40 -0
- data/features/orm.feature +60 -0
- data/features/orm_steps.rb +74 -0
- data/features/prov_dsl.feature +14 -0
- data/features/prov_dsl_steps.rb +11 -0
- data/features/reader.feature +25 -0
- data/features/reader_steps.rb +61 -0
- data/features/step_definitions/bio-publisci_steps.rb +0 -0
- data/features/store.feature +27 -0
- data/features/store_steps.rb +42 -0
- data/features/support/env.rb +13 -0
- data/features/writer.feature +14 -0
- data/features/writer_steps.rb +24 -0
- data/lib/bio-publisci.rb +64 -0
- data/lib/bio-publisci/analyzer.rb +57 -0
- data/lib/bio-publisci/datacube_model.rb +111 -0
- data/lib/bio-publisci/dataset/ORM/data_cube_orm.rb +240 -0
- data/lib/bio-publisci/dataset/ORM/observation.rb +20 -0
- data/lib/bio-publisci/dataset/configuration.rb +31 -0
- data/lib/bio-publisci/dataset/data_cube.rb +418 -0
- data/lib/bio-publisci/dataset/dataset.rb +11 -0
- data/lib/bio-publisci/dataset/dataset_for.rb +186 -0
- data/lib/bio-publisci/dataset/interactive.rb +72 -0
- data/lib/bio-publisci/dsl/config.rb +34 -0
- data/lib/bio-publisci/dsl/dataset_dsl.rb +93 -0
- data/lib/bio-publisci/dsl/dsl.rb +72 -0
- data/lib/bio-publisci/dsl/metadata_dsl.rb +85 -0
- data/lib/bio-publisci/dsl/prov_dsl.rb +143 -0
- data/lib/bio-publisci/metadata/generator.rb +323 -0
- data/lib/bio-publisci/metadata/metadata.rb +5 -0
- data/lib/bio-publisci/metadata/metadata_model.rb +25 -0
- data/lib/bio-publisci/metadata/prov/activity.rb +88 -0
- data/lib/bio-publisci/metadata/prov/agent.rb +100 -0
- data/lib/bio-publisci/metadata/prov/association.rb +107 -0
- data/lib/bio-publisci/metadata/prov/config.rb +34 -0
- data/lib/bio-publisci/metadata/prov/derivation.rb +60 -0
- data/lib/bio-publisci/metadata/prov/element.rb +120 -0
- data/lib/bio-publisci/metadata/prov/entity.rb +64 -0
- data/lib/bio-publisci/metadata/prov/model/prov_models.rb +109 -0
- data/lib/bio-publisci/metadata/prov/plan.rb +32 -0
- data/lib/bio-publisci/metadata/prov/prov.rb +78 -0
- data/lib/bio-publisci/metadata/prov/role.rb +40 -0
- data/lib/bio-publisci/metadata/prov/usage.rb +64 -0
- data/lib/bio-publisci/metadata/publisher.rb +25 -0
- data/lib/bio-publisci/mixins/custom_predicate.rb +38 -0
- data/lib/bio-publisci/mixins/dereferencable.rb +34 -0
- data/lib/bio-publisci/mixins/registry.rb +27 -0
- data/lib/bio-publisci/mixins/vocabulary.rb +8 -0
- data/lib/bio-publisci/output.rb +27 -0
- data/lib/bio-publisci/parser.rb +266 -0
- data/lib/bio-publisci/post_processor.rb +95 -0
- data/lib/bio-publisci/query/query_helper.rb +123 -0
- data/lib/bio-publisci/r_client.rb +54 -0
- data/lib/bio-publisci/readers/arff.rb +49 -0
- data/lib/bio-publisci/readers/base.rb +57 -0
- data/lib/bio-publisci/readers/csv.rb +88 -0
- data/lib/bio-publisci/readers/dataframe.rb +67 -0
- data/lib/bio-publisci/readers/maf.rb +199 -0
- data/lib/bio-publisci/readers/r_cross.rb +112 -0
- data/lib/bio-publisci/readers/r_matrix.rb +176 -0
- data/lib/bio-publisci/store.rb +56 -0
- data/lib/bio-publisci/writers/arff.rb +91 -0
- data/lib/bio-publisci/writers/base.rb +93 -0
- data/lib/bio-publisci/writers/csv.rb +31 -0
- data/lib/bio-publisci/writers/dataframe.rb +81 -0
- data/lib/bio-publisci/writers/json.rb +18 -0
- data/lib/r2rdf.rb +226 -0
- data/lib/template_bak.rb +12 -0
- data/lib/template_bak/publisci.rb +3 -0
- data/lib/vocabs/cc.rb +18 -0
- data/lib/vocabs/cert.rb +13 -0
- data/lib/vocabs/dc.rb +63 -0
- data/lib/vocabs/dc11.rb +23 -0
- data/lib/vocabs/doap.rb +45 -0
- data/lib/vocabs/exif.rb +168 -0
- data/lib/vocabs/foaf.rb +69 -0
- data/lib/vocabs/geo.rb +13 -0
- data/lib/vocabs/http.rb +26 -0
- data/lib/vocabs/ma.rb +78 -0
- data/lib/vocabs/owl.rb +59 -0
- data/lib/vocabs/rdfs.rb +17 -0
- data/lib/vocabs/rsa.rb +12 -0
- data/lib/vocabs/rss.rb +14 -0
- data/lib/vocabs/sioc.rb +93 -0
- data/lib/vocabs/skos.rb +36 -0
- data/lib/vocabs/wot.rb +21 -0
- data/lib/vocabs/xhtml.rb +9 -0
- data/lib/vocabs/xsd.rb +58 -0
- data/resources/maf_example.maf +10 -0
- data/resources/maf_rdf.ttl +1173 -0
- data/resources/primer.ttl +38 -0
- data/resources/queries/code_resources.rq +10 -0
- data/resources/queries/codes.rq +18 -0
- data/resources/queries/dataset.rq +7 -0
- data/resources/queries/dimension_ranges.rq +8 -0
- data/resources/queries/dimensions.rq +12 -0
- data/resources/queries/gene.rq +16 -0
- data/resources/queries/hugo_to_ensembl.rq +7 -0
- data/resources/queries/maf_column.rq +26 -0
- data/resources/queries/measures.rq +12 -0
- data/resources/queries/observation_labels.rq +8 -0
- data/resources/queries/observations.rq +13 -0
- data/resources/queries/patient.rq +11 -0
- data/resources/queries/patient_list.rq +11 -0
- data/resources/queries/patients_with_mutation.rq +18 -0
- data/resources/queries/properties.rq +8 -0
- data/resources/queries/test.rq +3 -0
- data/resources/weather.numeric.arff +28 -0
- data/scripts/get_gene_lengths.rb +50 -0
- data/scripts/islet_mlratio.rb +6 -0
- data/scripts/scan_islet.rb +6 -0
- data/scripts/update_reference.rb +25 -0
- data/server/helpers.rb +215 -0
- data/server/public/src-min-noconflict/LICENSE +24 -0
- data/server/public/src-min-noconflict/ace.js +11 -0
- data/server/public/src-min-noconflict/ext-chromevox.js +1 -0
- data/server/public/src-min-noconflict/ext-elastic_tabstops_lite.js +1 -0
- data/server/public/src-min-noconflict/ext-emmet.js +1 -0
- data/server/public/src-min-noconflict/ext-keybinding_menu.js +1 -0
- data/server/public/src-min-noconflict/ext-language_tools.js +1 -0
- data/server/public/src-min-noconflict/ext-modelist.js +1 -0
- data/server/public/src-min-noconflict/ext-old_ie.js +1 -0
- data/server/public/src-min-noconflict/ext-searchbox.js +1 -0
- data/server/public/src-min-noconflict/ext-settings_menu.js +1 -0
- data/server/public/src-min-noconflict/ext-spellcheck.js +1 -0
- data/server/public/src-min-noconflict/ext-split.js +1 -0
- data/server/public/src-min-noconflict/ext-static_highlight.js +1 -0
- data/server/public/src-min-noconflict/ext-statusbar.js +1 -0
- data/server/public/src-min-noconflict/ext-textarea.js +1 -0
- data/server/public/src-min-noconflict/ext-themelist.js +1 -0
- data/server/public/src-min-noconflict/ext-whitespace.js +1 -0
- data/server/public/src-min-noconflict/keybinding-emacs.js +1 -0
- data/server/public/src-min-noconflict/keybinding-vim.js +1 -0
- data/server/public/src-min-noconflict/mode-ruby.js +1 -0
- data/server/public/src-min-noconflict/snippets/ruby.js +1 -0
- data/server/public/src-min-noconflict/theme-twilight.js +1 -0
- data/server/public/src-min-noconflict/worker-coffee.js +1 -0
- data/server/public/src-min-noconflict/worker-css.js +1 -0
- data/server/public/src-min-noconflict/worker-javascript.js +1 -0
- data/server/public/src-min-noconflict/worker-json.js +1 -0
- data/server/public/src-min-noconflict/worker-lua.js +1 -0
- data/server/public/src-min-noconflict/worker-php.js +1 -0
- data/server/public/src-min-noconflict/worker-xquery.js +1 -0
- data/server/routes.rb +123 -0
- data/server/views/dsl.haml +65 -0
- data/server/views/dump.haml +3 -0
- data/server/views/import.haml +35 -0
- data/server/views/new_repository.haml +25 -0
- data/server/views/query.haml +28 -0
- data/server/views/repository.haml +25 -0
- data/spec/ORM/data_cube_orm_spec.rb +33 -0
- data/spec/ORM/prov_model_spec.rb +72 -0
- data/spec/analyzer_spec.rb +36 -0
- data/spec/bnode_spec.rb +66 -0
- data/spec/csv/bacon.csv +4 -0
- data/spec/csv/moar_bacon.csv +11 -0
- data/spec/data_cube_spec.rb +169 -0
- data/spec/dataset_for_spec.rb +77 -0
- data/spec/dsl_spec.rb +134 -0
- data/spec/generators/csv_spec.rb +44 -0
- data/spec/generators/dataframe_spec.rb +44 -0
- data/spec/generators/maf_spec.rb +40 -0
- data/spec/generators/r_cross_spec.rb +51 -0
- data/spec/generators/r_matrix_spec.rb +44 -0
- data/spec/length_lookup_spec.rb +0 -0
- data/spec/maf_query_spec.rb +343 -0
- data/spec/metadata/metadata_dsl_spec.rb +68 -0
- data/spec/prov/activity_spec.rb +74 -0
- data/spec/prov/agent_spec.rb +54 -0
- data/spec/prov/association_spec.rb +55 -0
- data/spec/prov/config_spec.rb +28 -0
- data/spec/prov/derivation_spec.rb +30 -0
- data/spec/prov/entity_spec.rb +52 -0
- data/spec/prov/role_spec.rb +94 -0
- data/spec/prov/usage_spec.rb +98 -0
- data/spec/queries/integrity/1.rq +21 -0
- data/spec/queries/integrity/11.rq +29 -0
- data/spec/queries/integrity/12.rq +37 -0
- data/spec/queries/integrity/14.rq +25 -0
- data/spec/queries/integrity/19_1.rq +21 -0
- data/spec/queries/integrity/19_2.rq +15 -0
- data/spec/queries/integrity/2.rq +22 -0
- data/spec/queries/integrity/3.rq +19 -0
- data/spec/queries/integrity/4.rq +13 -0
- data/spec/queries/integrity/5.rq +14 -0
- data/spec/r_builder_spec.rb +33 -0
- data/spec/resource/.RData +0 -0
- data/spec/resource/example.Rhistory +3 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/turtle/bacon +147 -0
- data/spec/turtle/reference +2064 -0
- data/spec/turtle/weather +275 -0
- data/spec/writer_spec.rb +75 -0
- metadata +589 -0
@@ -0,0 +1,85 @@
|
|
1
|
+
module PubliSci
|
2
|
+
class Metadata
|
3
|
+
module DSL
|
4
|
+
|
5
|
+
class Instance
|
6
|
+
include Metadata::DSL
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
Metadata.registry.clear
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def var(name=nil)
|
14
|
+
set_or_get('var',name)
|
15
|
+
end
|
16
|
+
alias_method :dataset, :var
|
17
|
+
|
18
|
+
def creator(id=nil)
|
19
|
+
set_or_get('creator',id)
|
20
|
+
end
|
21
|
+
alias_method :name, :creator
|
22
|
+
|
23
|
+
def description(desc=nil)
|
24
|
+
set_or_get('description',desc)
|
25
|
+
end
|
26
|
+
|
27
|
+
def title(desc=nil)
|
28
|
+
set_or_get('title',desc)
|
29
|
+
end
|
30
|
+
|
31
|
+
def topic(sub=nil)
|
32
|
+
add_or_get('topic',sub)
|
33
|
+
end
|
34
|
+
|
35
|
+
def publishers(pub=nil,&block)
|
36
|
+
if block_given?
|
37
|
+
p = Publisher.new
|
38
|
+
p.instance_eval(&block)
|
39
|
+
@publishers ||= [] << p
|
40
|
+
p
|
41
|
+
else
|
42
|
+
add_or_get('publishers',pub)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
alias_method :publisher, :publishers
|
46
|
+
|
47
|
+
def generate_n3
|
48
|
+
opts = {}
|
49
|
+
%w{var creator description title}.each{|field|
|
50
|
+
opts[field.to_sym] = send(field.to_sym) if send(field.to_sym)
|
51
|
+
}
|
52
|
+
opts[:subject] = topic if topic
|
53
|
+
publishers.each{|pub|
|
54
|
+
opts[:publishers] ||= [] << {label: pub.label, uri: pub.uri}
|
55
|
+
} if publishers
|
56
|
+
gen = Class.new {include PubliSci::Metadata::Generator}
|
57
|
+
|
58
|
+
gen.new.basic(opts)
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
def set_or_get(var,input=nil)
|
63
|
+
ivar = instance_variable_get("@#{var}")
|
64
|
+
|
65
|
+
if input
|
66
|
+
instance_variable_set("@#{var}", input)
|
67
|
+
else
|
68
|
+
ivar
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def add_or_get(var,input)
|
73
|
+
ivar = instance_variable_get("@#{var}")
|
74
|
+
|
75
|
+
if input
|
76
|
+
instance_variable_set("@#{var}", []) unless ivar
|
77
|
+
instance_variable_get("@#{var}") << input
|
78
|
+
instance_variable_get("@#{var}")
|
79
|
+
else
|
80
|
+
ivar
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
module PubliSci
|
2
|
+
class Prov
|
3
|
+
module DSL
|
4
|
+
|
5
|
+
include PubliSci::Vocabulary
|
6
|
+
|
7
|
+
class Instance
|
8
|
+
include Prov::DSL
|
9
|
+
def initialize
|
10
|
+
Prov.registry.clear
|
11
|
+
Prov.reset_settings
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.included(mod)
|
16
|
+
Prov.registry.clear
|
17
|
+
Prov.reset_settings
|
18
|
+
end
|
19
|
+
|
20
|
+
# def configure(&block)
|
21
|
+
# Prov.configuration.instance_eval(&block)
|
22
|
+
# end
|
23
|
+
|
24
|
+
def configure
|
25
|
+
yield Prov.configuration
|
26
|
+
end
|
27
|
+
|
28
|
+
def named_element(name,element_class,args={},&block)
|
29
|
+
el = element_class.new
|
30
|
+
el.__label=name
|
31
|
+
if block_given?
|
32
|
+
el.instance_eval(&block)
|
33
|
+
Prov.register(name,el)
|
34
|
+
else
|
35
|
+
args.keys.map{|k|
|
36
|
+
raise "Unkown #{element_class} setting #{k}" unless try_auto_set(el,k,args[k])
|
37
|
+
}
|
38
|
+
Prov.register(name,el)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def agent(name, args={}, &block)
|
43
|
+
named_element(name,Prov::Agent,args,&block)
|
44
|
+
end
|
45
|
+
|
46
|
+
def organization(name,args={},&block)
|
47
|
+
args[:type] = :organization
|
48
|
+
agent(name,args,&block)
|
49
|
+
end
|
50
|
+
|
51
|
+
def entity(name, args={}, &block)
|
52
|
+
named_element(name,Prov::Entity,args,&block)
|
53
|
+
end
|
54
|
+
alias_method :data, :entity
|
55
|
+
|
56
|
+
def plan(name, args={}, &block)
|
57
|
+
named_element(name,Prov::Plan,args,&block)
|
58
|
+
end
|
59
|
+
|
60
|
+
def activity(name,args={}, &block)
|
61
|
+
named_element(name,Prov::Activity,args,&block)
|
62
|
+
end
|
63
|
+
|
64
|
+
def base_url(url)
|
65
|
+
Prov.base_url=url
|
66
|
+
end
|
67
|
+
|
68
|
+
def generate_n3(abbreviate = false)
|
69
|
+
entities = Prov.entities.values.map(&:to_n3).join
|
70
|
+
agents = Prov.agents.values.map(&:to_n3).join
|
71
|
+
activities = Prov.activities.values.map(&:to_n3).join
|
72
|
+
plans = Prov.plans.values.map(&:to_n3).join
|
73
|
+
associations = Prov.registry[:associations].values.map(&:to_n3).join if Prov.registry[:associations]
|
74
|
+
derivations = Prov.registry[:derivation].values.map(&:to_n3).join if Prov.registry[:derivation]
|
75
|
+
usages = Prov.registry[:usage].values.map(&:to_n3).join if Prov.registry[:usage]
|
76
|
+
roles = Prov.registry[:role].values.map(&:to_n3).join if Prov.registry[:role]
|
77
|
+
|
78
|
+
str = "#{entities}#{agents}#{activities}#{plans}#{associations}#{derivations}#{usages}#{roles}"
|
79
|
+
|
80
|
+
if abbreviate
|
81
|
+
abbreviate_known(str)
|
82
|
+
else
|
83
|
+
str
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def settings
|
88
|
+
Prov.configuration
|
89
|
+
end
|
90
|
+
|
91
|
+
def return_objects
|
92
|
+
Prov.registry
|
93
|
+
end
|
94
|
+
|
95
|
+
def to_repository(turtle_string=(Prov.prefixes+generate_n3))
|
96
|
+
repo = settings.repository
|
97
|
+
case repo
|
98
|
+
when :in_memory
|
99
|
+
repo = RDF::Repository.new
|
100
|
+
when :fourstore
|
101
|
+
repo = RDF::FourStore::Repository.new('http://localhost:8080')
|
102
|
+
end
|
103
|
+
f = Tempfile.new(['repo','.ttl'])
|
104
|
+
f.write(turtle_string)
|
105
|
+
f.close
|
106
|
+
repo.load(f.path, :format => :ttl)
|
107
|
+
f.unlink
|
108
|
+
repo
|
109
|
+
end
|
110
|
+
|
111
|
+
def output
|
112
|
+
cfg = Prov.configuration
|
113
|
+
case cfg.output
|
114
|
+
when :generate_n3
|
115
|
+
generate_n3(cfg.abbreviate)
|
116
|
+
when :to_repository
|
117
|
+
raise "not implemented yet"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
private
|
122
|
+
def try_auto_set(object,method,args)
|
123
|
+
if object.methods.include? method
|
124
|
+
object.send(method,args)
|
125
|
+
true
|
126
|
+
else
|
127
|
+
false
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def abbreviate_known(turtle)
|
132
|
+
ttl = turtle.dup
|
133
|
+
%w{activity assoc agent plan entity derivation usage role}.each{|element|
|
134
|
+
ttl.gsub!(%r{<#{Prov.base_url}/#{element}/([\w|\d]+)>}, "#{element}:" + '\1')
|
135
|
+
}
|
136
|
+
|
137
|
+
ttl.gsub!(%r{<http://gsocsemantic.wordpress.com/([\w|\d]+)>}, 'me:\1')
|
138
|
+
ttl.gsub!(%r{<http://www.w3.org/ns/prov#([\w|\d]+)>}, 'prov:\1')
|
139
|
+
ttl
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,323 @@
|
|
1
|
+
class String
|
2
|
+
def unindent
|
3
|
+
gsub /^#{self[/\A\s*/]}/, ''
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
module PubliSci
|
8
|
+
class Metadata
|
9
|
+
module Generator
|
10
|
+
include PubliSci::Parser
|
11
|
+
|
12
|
+
def defaults
|
13
|
+
{
|
14
|
+
encode_nulls: false,
|
15
|
+
base_url: "http://www.rqtl.org",
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def basic(fields)
|
20
|
+
#TODO don't assume base dataset is "ns:dataset-var",
|
21
|
+
#make it just "var", and try to make that clear to calling classes
|
22
|
+
|
23
|
+
fields[:var] = sanitize([fields[:var]]).first
|
24
|
+
|
25
|
+
unless fields[:creator]
|
26
|
+
if ENV['USER']
|
27
|
+
fields[:creator] = ENV['USER']
|
28
|
+
elsif ENV['USERNAME']
|
29
|
+
fields[:creator] = ENV['USERNAME']
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
fields[:date] = Time.now.strftime("%Y-%m-%d") unless fields[:date]
|
34
|
+
|
35
|
+
#TODO some of these should probably be resources, eg dct:creator, or put under DC namespace
|
36
|
+
str = <<-EOF.unindent
|
37
|
+
ns:dataset-#{fields[:var]} rdfs:label "#{fields[:title]}";
|
38
|
+
dct:title "#{fields[:title]}";
|
39
|
+
dct:creator "#{fields[:creator]}";
|
40
|
+
rdfs:comment "#{fields[:description]}";
|
41
|
+
dct:description "#{fields[:description]}";
|
42
|
+
dct:issued "#{fields[:date]}"^^xsd:date.
|
43
|
+
EOF
|
44
|
+
|
45
|
+
end_str = ""
|
46
|
+
|
47
|
+
if fields[:subject] && fields[:subject].size > 0
|
48
|
+
str << " dct:subject"
|
49
|
+
fields[:subject].each{|subject|
|
50
|
+
sub = RDF::Resource(subject)
|
51
|
+
sub = RDF::Literal(subject) unless sub.valid?
|
52
|
+
|
53
|
+
str << " " + sub.to_base + ",\n"
|
54
|
+
}
|
55
|
+
str[-2] = ";"
|
56
|
+
end
|
57
|
+
|
58
|
+
if fields[:publishers]
|
59
|
+
fields[:publishers].map{|publisher|
|
60
|
+
raise "No URI for publisher #{publisher}" unless publisher[:uri]
|
61
|
+
raise "No label for publisher #{publisher}" unless publisher[:label]
|
62
|
+
str << " dct:publisher <#{publisher[:uri]}> ;\n"
|
63
|
+
end_str << "<#{publisher[:uri]}> a org:Organization, foaf:Agent;\n rdfs:label \"#{publisher[:label]}\" .\n\n"
|
64
|
+
}
|
65
|
+
str[-2] = '.'
|
66
|
+
end
|
67
|
+
|
68
|
+
str + "\n" + end_str
|
69
|
+
end
|
70
|
+
|
71
|
+
def provenance(original, triplified, chain, options={})
|
72
|
+
#TODO: should either add a prefixes method or replace some with full URIs
|
73
|
+
raise "MissingOriginal: must specify a provenance source" unless original && original[:resource]
|
74
|
+
|
75
|
+
#TODO include file type etc, or create a separate method for it
|
76
|
+
|
77
|
+
str = <<-EOF.unindent
|
78
|
+
<#{original[:resource]}> a prov:Entity ;
|
79
|
+
prov:wasGeneratredBy ns:activity-1 .
|
80
|
+
|
81
|
+
ns:activity-1 a prov:Activity ;
|
82
|
+
prov:generated <#{original[:resource]}> .
|
83
|
+
|
84
|
+
EOF
|
85
|
+
|
86
|
+
if original[:software]
|
87
|
+
original_assoc_id = Time.now.nsec.to_s(32)
|
88
|
+
|
89
|
+
|
90
|
+
str << <<-EOF.unindent
|
91
|
+
<#{original[:software]}> a prov:Entity.
|
92
|
+
|
93
|
+
ns:activity-1 prov:qualifiedAssociation ns:assoc-1_#{original_assoc_id} .
|
94
|
+
|
95
|
+
ns:assoc-1_#{original_assoc_id} a prov:Assocation ;
|
96
|
+
prov:entity <#{original[:software]}> .
|
97
|
+
|
98
|
+
EOF
|
99
|
+
|
100
|
+
if original[:process]
|
101
|
+
original[:process] = IO.read(original[:process]) if File.exist? original[:process]
|
102
|
+
|
103
|
+
steps = '"' + original[:process].split("\n").join('" "') + '"'
|
104
|
+
str << <<-EOF.unindent
|
105
|
+
ns:assoc-1_#{original_assoc_id} prov:hadPlan ns:plan-1.
|
106
|
+
|
107
|
+
ns:plan-1 a prov:Plan ;
|
108
|
+
rdfs:comment (#{steps});
|
109
|
+
|
110
|
+
EOF
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
if original[:author]
|
115
|
+
str << "<#{original[:author]}> a prov:Agent, prov:Person .\n"
|
116
|
+
str << "ns:activity-1 prov:wasAssociatedWith <#{original[:author]}> .\n"
|
117
|
+
|
118
|
+
str << "<#{original[:author]}> foaf:givenName \"#{original[:author_name]}\" .\n" if original[:author_name]
|
119
|
+
|
120
|
+
if original[:organization]
|
121
|
+
str << "<#{original[:author]}> prov:actedOnBehalfOf <#{original[:organization]}> .\n\n"
|
122
|
+
str << "<#{original[:organization]}> a prov:Agent, prov:Organization.\n"
|
123
|
+
if original[:organization_name]
|
124
|
+
str << "<#{original[:organization]}> foaf:name \"#{original[:organization_name]}\" .\n\n"
|
125
|
+
else
|
126
|
+
str << "\n"
|
127
|
+
end
|
128
|
+
else
|
129
|
+
str << "\n"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
if triplified
|
134
|
+
triples_assoc_id = Time.now.nsec.to_s(32)
|
135
|
+
|
136
|
+
str << <<-EOF.unindent
|
137
|
+
<#{triplified[:resource]}> a prov:Entity;
|
138
|
+
prov:wasGeneratredBy ns:activity-0 .
|
139
|
+
|
140
|
+
</ns/R2RDF> a prov:Agent, prov:SoftwareAgent ;
|
141
|
+
rdfs:label "Semantic Publishing Toolkit" .
|
142
|
+
|
143
|
+
ns:activity-0 a prov:Activity ;
|
144
|
+
prov:qualifiedAssociation ns:assoc-0_#{triples_assoc_id};
|
145
|
+
prov:generated <#{triplified[:resource]}> ;
|
146
|
+
prov:used <#{original[:resource]}> .
|
147
|
+
|
148
|
+
ns:assoc-0_#{triples_assoc_id} a prov:Assocation ;
|
149
|
+
prov:entity </ns/R2RDF>;
|
150
|
+
prov:hadPlan ns:plan-0.
|
151
|
+
|
152
|
+
ns:plan-0 a prov:Plan ;
|
153
|
+
rdfs:comment "generation of <#{triplified[:resource]}> by R2RDF gem" .
|
154
|
+
|
155
|
+
EOF
|
156
|
+
|
157
|
+
if triplified[:author]
|
158
|
+
str << "<#{triplified[:author]}> a prov:Agent, prov:Person .\n"
|
159
|
+
|
160
|
+
str << "<#{triplified[:author]}> foaf:givenName \"#{triplified[:author_name]}\" .\n" if triplified[:author_name]
|
161
|
+
|
162
|
+
if triplified[:organization]
|
163
|
+
str << "<#{triplified[:author]}> prov:actedOnBehalfOf <#{triplified[:organization]}> .\n\n"
|
164
|
+
str << "<#{triplified[:organization]}> a prov:Agent, prov:Organization.\n"
|
165
|
+
if triplified[:organization_name]
|
166
|
+
str << "<#{triplified[:organization]}> foaf:name \"#{triplified[:organization_name]}\" .\n\n"
|
167
|
+
else
|
168
|
+
str << "\n"
|
169
|
+
end
|
170
|
+
else
|
171
|
+
str << "\n"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
if chain
|
177
|
+
str << "ns:activity-1 prov:used <#{chain.first[:resource]}> .\n"
|
178
|
+
str << "<#{original[:resource]}> prov:wasDerivedFrom <#{chain.first[:resource]}> .\n\n"
|
179
|
+
chain.each_with_index{ |src,i|
|
180
|
+
if i == chain.size-1
|
181
|
+
str << activity(src[:resource],nil,src)
|
182
|
+
else
|
183
|
+
str << activity(src[:resource],chain[i+1][:resource],src)
|
184
|
+
end
|
185
|
+
}
|
186
|
+
end
|
187
|
+
|
188
|
+
str
|
189
|
+
end
|
190
|
+
|
191
|
+
def activity(entity, used, options={})
|
192
|
+
assoc_id = Time.now.nsec.to_s(32)
|
193
|
+
activity_id = Time.now.nsec.to_s(32)
|
194
|
+
plan_id = Time.now.nsec.to_s(32)
|
195
|
+
|
196
|
+
raise "NoEntityGiven: activity generation requires a subject entity" unless entity
|
197
|
+
|
198
|
+
entity_str = <<-EOF.unindent
|
199
|
+
<#{entity}> a prov:Entity ;
|
200
|
+
prov:wasGeneratredBy ns:activity-a_#{activity_id} ;
|
201
|
+
EOF
|
202
|
+
|
203
|
+
activity_str = <<-EOF.unindent
|
204
|
+
ns:activity-a_#{activity_id} a prov:Activity ;
|
205
|
+
prov:generated <#{entity}> ;
|
206
|
+
EOF
|
207
|
+
|
208
|
+
if used
|
209
|
+
entity_str << "\tprov:wasDerivedFrom <#{used}> . \n\n"
|
210
|
+
activity_str << "\tprov:used <#{used}> . \n\n"
|
211
|
+
else
|
212
|
+
entity_str[-2] = ".\n"
|
213
|
+
activity_str[-2] = ".\n"
|
214
|
+
end
|
215
|
+
|
216
|
+
activity_str << <<-EOF.unindent
|
217
|
+
ns:activity-a_#{activity_id} prov:qualifiedAssociation ns:assoc-s_#{assoc_id} .
|
218
|
+
|
219
|
+
ns:assoc-s_#{assoc_id} a prov:Assocation .
|
220
|
+
|
221
|
+
EOF
|
222
|
+
|
223
|
+
if options[:software]
|
224
|
+
|
225
|
+
activity_str << <<-EOF.unindent
|
226
|
+
<#{options[:software]}> a prov:Entity .
|
227
|
+
|
228
|
+
ns:assoc-s_#{assoc_id} prov:agent <#{options[:software]}> .
|
229
|
+
EOF
|
230
|
+
|
231
|
+
if options[:process]
|
232
|
+
options[:process] = IO.read(options[:process]) if File.exist? options[:process]
|
233
|
+
|
234
|
+
steps = '"' + options[:process].split("\n").join('" "') + '"'
|
235
|
+
activity_str << <<-EOF.unindent
|
236
|
+
ns:assoc-s_#{assoc_id} prov:hadPlan ns:plan-p_#{plan_id}.
|
237
|
+
|
238
|
+
ns:plan-p_#{plan_id} a prov:Plan ;
|
239
|
+
rdfs:comment (#{steps});
|
240
|
+
EOF
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
if options[:author]
|
245
|
+
entity_str << "<#{options[:author]}> a prov:Agent, prov:Person .\n"
|
246
|
+
entity_str << "<#{options[:author]}> foaf:givenName \"#{options[:author_name]}\" .\n" if options[:author_name]
|
247
|
+
|
248
|
+
activity_str << "ns:activity-a_#{activity_id} prov:wasAssociatedWith <#{options[:author]}> .\n"
|
249
|
+
activity_str << "ns:assoc-s_#{assoc_id} prov:agent <#{options[:author]}> .\n"
|
250
|
+
|
251
|
+
if options[:organization]
|
252
|
+
entity_str << "<#{options[:organization]}> a prov:Agent, prov:Organization .\n"
|
253
|
+
activity_str << "<#{options[:author]}> prov:actedOnBehalfOf <#{options[:organization]}> .\n\n"
|
254
|
+
if options[:organization_name]
|
255
|
+
entity_str << "<#{options[:organization]}> foaf:name \"#{options[:organization_name]}\" .\n\n"
|
256
|
+
end
|
257
|
+
else
|
258
|
+
activity_str << "\n"
|
259
|
+
# entity_str << "\n"
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
entity_str + "\n" + activity_str
|
264
|
+
end
|
265
|
+
|
266
|
+
def process(id, step_string, software_resource, software_var, options={})
|
267
|
+
#TODO a better predicate for the steplist than rdfs:comment
|
268
|
+
# and make sure it looks good.
|
269
|
+
steps = '"' + step_string.split("\n").join('" "') + '"'
|
270
|
+
assoc_id = Time.now.nsec.to_s(32)
|
271
|
+
str = <<-EOF.unindent
|
272
|
+
ns:activity-#{id} a prov:Activity ;
|
273
|
+
prov:qualifiedAssociation ns:assoc-#{assoc_id} ;
|
274
|
+
prov:used </ns/dataset/#{software_var}#var>.
|
275
|
+
|
276
|
+
ns:assoc-#{id}_#{assoc_id} a prov:Assocation ;
|
277
|
+
prov:entity <#{software_resource}>;
|
278
|
+
prov:hadPlan ns:plan-#{id}.
|
279
|
+
|
280
|
+
ns:plan-#{id} a prov:Plan ;
|
281
|
+
rdfs:comment (#{steps});
|
282
|
+
|
283
|
+
EOF
|
284
|
+
|
285
|
+
end
|
286
|
+
|
287
|
+
def r2rdf_metadata
|
288
|
+
str <<-EOF.unindent
|
289
|
+
<#{options[:base_url]}/ns/R2RDF> a foaf:Agent;
|
290
|
+
foaf:name "R2RDF Semantic Web Toolkit";
|
291
|
+
org:memberOf <http://sciruby.com/>
|
292
|
+
EOF
|
293
|
+
end
|
294
|
+
|
295
|
+
def org_metadata
|
296
|
+
str <<-EOF.unindent
|
297
|
+
<http://sciruby.com/> a org:Organization, prov:Organization;
|
298
|
+
skos:prefLabel "SciRuby";
|
299
|
+
rdfs:description "A Project to Build and Improve Tools for Scientific Computing in Ruby".
|
300
|
+
EOF
|
301
|
+
end
|
302
|
+
|
303
|
+
def metadata_help(topic=nil)
|
304
|
+
if topic
|
305
|
+
puts "This should display help information for #{topic}, but there's none here yet :("
|
306
|
+
else
|
307
|
+
puts <<-EOF.unindent
|
308
|
+
Available metadata fields:
|
309
|
+
(Field) (Ontology) (Description)
|
310
|
+
|
311
|
+
publishers dct/foaf/org The Organization/s responsible for publishing the dataset
|
312
|
+
subject dct The subject of this dataset. Use resources when possible
|
313
|
+
var dct The name of the datset resource (used internally)
|
314
|
+
creator dct The person or process responsible for creating the dataset
|
315
|
+
description dct/rdfs A descriptions of the dataset
|
316
|
+
issued dct The date of issuance for the dataset
|
317
|
+
|
318
|
+
EOF
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|