publisci 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +13 -0
  5. data/Gemfile +36 -0
  6. data/LICENSE.txt +20 -0
  7. data/README.md +51 -0
  8. data/README.rdoc +48 -0
  9. data/Rakefile +68 -0
  10. data/bin/bio-publisci +106 -0
  11. data/bin/bio-publisci-server +50 -0
  12. data/examples/bio-band_integration.rb +9 -0
  13. data/examples/no_magic.prov +58 -0
  14. data/examples/no_magic.rb +58 -0
  15. data/examples/orm.prov +48 -0
  16. data/examples/primer-full.prov +120 -0
  17. data/examples/primer.prov +66 -0
  18. data/examples/prov_dsl.prov +85 -0
  19. data/examples/safe_gen.rb +7 -0
  20. data/examples/visualization/primer.prov +66 -0
  21. data/examples/visualization/prov_viz.rb +140 -0
  22. data/examples/visualization/viz.rb +35 -0
  23. data/features/create_generator.feature +21 -0
  24. data/features/integration.feature +12 -0
  25. data/features/integration_steps.rb +10 -0
  26. data/features/metadata.feature +37 -0
  27. data/features/metadata_steps.rb +40 -0
  28. data/features/orm.feature +60 -0
  29. data/features/orm_steps.rb +74 -0
  30. data/features/prov_dsl.feature +14 -0
  31. data/features/prov_dsl_steps.rb +11 -0
  32. data/features/reader.feature +25 -0
  33. data/features/reader_steps.rb +61 -0
  34. data/features/step_definitions/bio-publisci_steps.rb +0 -0
  35. data/features/store.feature +27 -0
  36. data/features/store_steps.rb +42 -0
  37. data/features/support/env.rb +13 -0
  38. data/features/writer.feature +14 -0
  39. data/features/writer_steps.rb +24 -0
  40. data/lib/bio-publisci.rb +64 -0
  41. data/lib/bio-publisci/analyzer.rb +57 -0
  42. data/lib/bio-publisci/datacube_model.rb +111 -0
  43. data/lib/bio-publisci/dataset/ORM/data_cube_orm.rb +240 -0
  44. data/lib/bio-publisci/dataset/ORM/observation.rb +20 -0
  45. data/lib/bio-publisci/dataset/configuration.rb +31 -0
  46. data/lib/bio-publisci/dataset/data_cube.rb +418 -0
  47. data/lib/bio-publisci/dataset/dataset.rb +11 -0
  48. data/lib/bio-publisci/dataset/dataset_for.rb +186 -0
  49. data/lib/bio-publisci/dataset/interactive.rb +72 -0
  50. data/lib/bio-publisci/dsl/config.rb +34 -0
  51. data/lib/bio-publisci/dsl/dataset_dsl.rb +93 -0
  52. data/lib/bio-publisci/dsl/dsl.rb +72 -0
  53. data/lib/bio-publisci/dsl/metadata_dsl.rb +85 -0
  54. data/lib/bio-publisci/dsl/prov_dsl.rb +143 -0
  55. data/lib/bio-publisci/metadata/generator.rb +323 -0
  56. data/lib/bio-publisci/metadata/metadata.rb +5 -0
  57. data/lib/bio-publisci/metadata/metadata_model.rb +25 -0
  58. data/lib/bio-publisci/metadata/prov/activity.rb +88 -0
  59. data/lib/bio-publisci/metadata/prov/agent.rb +100 -0
  60. data/lib/bio-publisci/metadata/prov/association.rb +107 -0
  61. data/lib/bio-publisci/metadata/prov/config.rb +34 -0
  62. data/lib/bio-publisci/metadata/prov/derivation.rb +60 -0
  63. data/lib/bio-publisci/metadata/prov/element.rb +120 -0
  64. data/lib/bio-publisci/metadata/prov/entity.rb +64 -0
  65. data/lib/bio-publisci/metadata/prov/model/prov_models.rb +109 -0
  66. data/lib/bio-publisci/metadata/prov/plan.rb +32 -0
  67. data/lib/bio-publisci/metadata/prov/prov.rb +78 -0
  68. data/lib/bio-publisci/metadata/prov/role.rb +40 -0
  69. data/lib/bio-publisci/metadata/prov/usage.rb +64 -0
  70. data/lib/bio-publisci/metadata/publisher.rb +25 -0
  71. data/lib/bio-publisci/mixins/custom_predicate.rb +38 -0
  72. data/lib/bio-publisci/mixins/dereferencable.rb +34 -0
  73. data/lib/bio-publisci/mixins/registry.rb +27 -0
  74. data/lib/bio-publisci/mixins/vocabulary.rb +8 -0
  75. data/lib/bio-publisci/output.rb +27 -0
  76. data/lib/bio-publisci/parser.rb +266 -0
  77. data/lib/bio-publisci/post_processor.rb +95 -0
  78. data/lib/bio-publisci/query/query_helper.rb +123 -0
  79. data/lib/bio-publisci/r_client.rb +54 -0
  80. data/lib/bio-publisci/readers/arff.rb +49 -0
  81. data/lib/bio-publisci/readers/base.rb +57 -0
  82. data/lib/bio-publisci/readers/csv.rb +88 -0
  83. data/lib/bio-publisci/readers/dataframe.rb +67 -0
  84. data/lib/bio-publisci/readers/maf.rb +199 -0
  85. data/lib/bio-publisci/readers/r_cross.rb +112 -0
  86. data/lib/bio-publisci/readers/r_matrix.rb +176 -0
  87. data/lib/bio-publisci/store.rb +56 -0
  88. data/lib/bio-publisci/writers/arff.rb +91 -0
  89. data/lib/bio-publisci/writers/base.rb +93 -0
  90. data/lib/bio-publisci/writers/csv.rb +31 -0
  91. data/lib/bio-publisci/writers/dataframe.rb +81 -0
  92. data/lib/bio-publisci/writers/json.rb +18 -0
  93. data/lib/r2rdf.rb +226 -0
  94. data/lib/template_bak.rb +12 -0
  95. data/lib/template_bak/publisci.rb +3 -0
  96. data/lib/vocabs/cc.rb +18 -0
  97. data/lib/vocabs/cert.rb +13 -0
  98. data/lib/vocabs/dc.rb +63 -0
  99. data/lib/vocabs/dc11.rb +23 -0
  100. data/lib/vocabs/doap.rb +45 -0
  101. data/lib/vocabs/exif.rb +168 -0
  102. data/lib/vocabs/foaf.rb +69 -0
  103. data/lib/vocabs/geo.rb +13 -0
  104. data/lib/vocabs/http.rb +26 -0
  105. data/lib/vocabs/ma.rb +78 -0
  106. data/lib/vocabs/owl.rb +59 -0
  107. data/lib/vocabs/rdfs.rb +17 -0
  108. data/lib/vocabs/rsa.rb +12 -0
  109. data/lib/vocabs/rss.rb +14 -0
  110. data/lib/vocabs/sioc.rb +93 -0
  111. data/lib/vocabs/skos.rb +36 -0
  112. data/lib/vocabs/wot.rb +21 -0
  113. data/lib/vocabs/xhtml.rb +9 -0
  114. data/lib/vocabs/xsd.rb +58 -0
  115. data/resources/maf_example.maf +10 -0
  116. data/resources/maf_rdf.ttl +1173 -0
  117. data/resources/primer.ttl +38 -0
  118. data/resources/queries/code_resources.rq +10 -0
  119. data/resources/queries/codes.rq +18 -0
  120. data/resources/queries/dataset.rq +7 -0
  121. data/resources/queries/dimension_ranges.rq +8 -0
  122. data/resources/queries/dimensions.rq +12 -0
  123. data/resources/queries/gene.rq +16 -0
  124. data/resources/queries/hugo_to_ensembl.rq +7 -0
  125. data/resources/queries/maf_column.rq +26 -0
  126. data/resources/queries/measures.rq +12 -0
  127. data/resources/queries/observation_labels.rq +8 -0
  128. data/resources/queries/observations.rq +13 -0
  129. data/resources/queries/patient.rq +11 -0
  130. data/resources/queries/patient_list.rq +11 -0
  131. data/resources/queries/patients_with_mutation.rq +18 -0
  132. data/resources/queries/properties.rq +8 -0
  133. data/resources/queries/test.rq +3 -0
  134. data/resources/weather.numeric.arff +28 -0
  135. data/scripts/get_gene_lengths.rb +50 -0
  136. data/scripts/islet_mlratio.rb +6 -0
  137. data/scripts/scan_islet.rb +6 -0
  138. data/scripts/update_reference.rb +25 -0
  139. data/server/helpers.rb +215 -0
  140. data/server/public/src-min-noconflict/LICENSE +24 -0
  141. data/server/public/src-min-noconflict/ace.js +11 -0
  142. data/server/public/src-min-noconflict/ext-chromevox.js +1 -0
  143. data/server/public/src-min-noconflict/ext-elastic_tabstops_lite.js +1 -0
  144. data/server/public/src-min-noconflict/ext-emmet.js +1 -0
  145. data/server/public/src-min-noconflict/ext-keybinding_menu.js +1 -0
  146. data/server/public/src-min-noconflict/ext-language_tools.js +1 -0
  147. data/server/public/src-min-noconflict/ext-modelist.js +1 -0
  148. data/server/public/src-min-noconflict/ext-old_ie.js +1 -0
  149. data/server/public/src-min-noconflict/ext-searchbox.js +1 -0
  150. data/server/public/src-min-noconflict/ext-settings_menu.js +1 -0
  151. data/server/public/src-min-noconflict/ext-spellcheck.js +1 -0
  152. data/server/public/src-min-noconflict/ext-split.js +1 -0
  153. data/server/public/src-min-noconflict/ext-static_highlight.js +1 -0
  154. data/server/public/src-min-noconflict/ext-statusbar.js +1 -0
  155. data/server/public/src-min-noconflict/ext-textarea.js +1 -0
  156. data/server/public/src-min-noconflict/ext-themelist.js +1 -0
  157. data/server/public/src-min-noconflict/ext-whitespace.js +1 -0
  158. data/server/public/src-min-noconflict/keybinding-emacs.js +1 -0
  159. data/server/public/src-min-noconflict/keybinding-vim.js +1 -0
  160. data/server/public/src-min-noconflict/mode-ruby.js +1 -0
  161. data/server/public/src-min-noconflict/snippets/ruby.js +1 -0
  162. data/server/public/src-min-noconflict/theme-twilight.js +1 -0
  163. data/server/public/src-min-noconflict/worker-coffee.js +1 -0
  164. data/server/public/src-min-noconflict/worker-css.js +1 -0
  165. data/server/public/src-min-noconflict/worker-javascript.js +1 -0
  166. data/server/public/src-min-noconflict/worker-json.js +1 -0
  167. data/server/public/src-min-noconflict/worker-lua.js +1 -0
  168. data/server/public/src-min-noconflict/worker-php.js +1 -0
  169. data/server/public/src-min-noconflict/worker-xquery.js +1 -0
  170. data/server/routes.rb +123 -0
  171. data/server/views/dsl.haml +65 -0
  172. data/server/views/dump.haml +3 -0
  173. data/server/views/import.haml +35 -0
  174. data/server/views/new_repository.haml +25 -0
  175. data/server/views/query.haml +28 -0
  176. data/server/views/repository.haml +25 -0
  177. data/spec/ORM/data_cube_orm_spec.rb +33 -0
  178. data/spec/ORM/prov_model_spec.rb +72 -0
  179. data/spec/analyzer_spec.rb +36 -0
  180. data/spec/bnode_spec.rb +66 -0
  181. data/spec/csv/bacon.csv +4 -0
  182. data/spec/csv/moar_bacon.csv +11 -0
  183. data/spec/data_cube_spec.rb +169 -0
  184. data/spec/dataset_for_spec.rb +77 -0
  185. data/spec/dsl_spec.rb +134 -0
  186. data/spec/generators/csv_spec.rb +44 -0
  187. data/spec/generators/dataframe_spec.rb +44 -0
  188. data/spec/generators/maf_spec.rb +40 -0
  189. data/spec/generators/r_cross_spec.rb +51 -0
  190. data/spec/generators/r_matrix_spec.rb +44 -0
  191. data/spec/length_lookup_spec.rb +0 -0
  192. data/spec/maf_query_spec.rb +343 -0
  193. data/spec/metadata/metadata_dsl_spec.rb +68 -0
  194. data/spec/prov/activity_spec.rb +74 -0
  195. data/spec/prov/agent_spec.rb +54 -0
  196. data/spec/prov/association_spec.rb +55 -0
  197. data/spec/prov/config_spec.rb +28 -0
  198. data/spec/prov/derivation_spec.rb +30 -0
  199. data/spec/prov/entity_spec.rb +52 -0
  200. data/spec/prov/role_spec.rb +94 -0
  201. data/spec/prov/usage_spec.rb +98 -0
  202. data/spec/queries/integrity/1.rq +21 -0
  203. data/spec/queries/integrity/11.rq +29 -0
  204. data/spec/queries/integrity/12.rq +37 -0
  205. data/spec/queries/integrity/14.rq +25 -0
  206. data/spec/queries/integrity/19_1.rq +21 -0
  207. data/spec/queries/integrity/19_2.rq +15 -0
  208. data/spec/queries/integrity/2.rq +22 -0
  209. data/spec/queries/integrity/3.rq +19 -0
  210. data/spec/queries/integrity/4.rq +13 -0
  211. data/spec/queries/integrity/5.rq +14 -0
  212. data/spec/r_builder_spec.rb +33 -0
  213. data/spec/resource/.RData +0 -0
  214. data/spec/resource/example.Rhistory +3 -0
  215. data/spec/spec_helper.rb +17 -0
  216. data/spec/turtle/bacon +147 -0
  217. data/spec/turtle/reference +2064 -0
  218. data/spec/turtle/weather +275 -0
  219. data/spec/writer_spec.rb +75 -0
  220. metadata +589 -0
@@ -0,0 +1,31 @@
1
+ module PubliSci
2
+ module Writers
3
+ class CSV < Base
4
+ def build_csv(data,components=nil)
5
+ unless components
6
+ components = data.values.map(&:keys).uniq
7
+ end
8
+ str = components.join(',') + "\n"
9
+ data.map {|d| str << Hash[d[1]].values.join(',') + "\n" }
10
+ str[-1]=""
11
+ str
12
+ end
13
+
14
+ def from_turtle(turtle_file, verbose=false)
15
+ puts "loading #{turtle_file}" if verbose
16
+ repo = RDF::Repository.load(turtle_file)
17
+ puts "loaded #{repo.size} statements into temporary repo" if verbose
18
+
19
+ dims = dimensions(repo)
20
+ meas = measures(repo)
21
+ data = observations(repo)
22
+ build_csv(data, (dims | meas))
23
+ end
24
+
25
+ def from_store(repo,dataSet=nil, variable_out=nil, verbose=false)
26
+ data = observations(repo,dataSet,true)
27
+ build_csv(data)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,81 @@
1
+ module PubliSci
2
+ module Writers
3
+ module Dataframe
4
+
5
+ def framestring(name,vectors)
6
+ framestr = "#{name} = data.frame("
7
+ vectors.map{ |k,v| framestr << k + '=' + k +','}
8
+ framestr[-1] = ')'
9
+ framestr
10
+ end
11
+
12
+ def get_vectors(variable_name, helper, repo)
13
+ column_names = helper.get_ary(helper.execute(helper.property_names(variable_name), repo)).flatten.map{|n| n.gsub(' Component','')}
14
+ vectors = {}
15
+ column_names.map{|n|
16
+ vectors[n] = helper.get_ary(helper.execute(helper.property_values(variable_name,n),repo),'to_f').flatten unless n == "refRow"
17
+ }
18
+ vectors
19
+ end
20
+
21
+ def create_dataframe(name, connection, rows, vectors)
22
+ connection.assign('rows', rows)
23
+ vectors.map{ |k,v|
24
+ connection.assign(k,v)
25
+ }
26
+ connection.eval(framestring(name,vectors))
27
+ connection.eval("row.names(#{name}) <- rows")
28
+ connection.eval(name)
29
+ end
30
+
31
+ def save_workspace(connection, loc)
32
+ connection.eval "save.image(#{loc})"
33
+ end
34
+
35
+ def get_rownames(variable, helper, repo)
36
+ rows = helper.get_ary(helper.execute(helper.row_names(variable), repo)).flatten
37
+ end
38
+
39
+ end
40
+
41
+ class Builder
42
+ include PubliSci::Writers::Dataframe
43
+
44
+
45
+ def from_turtle(turtle_file, connection, variable_in=nil, variable_out=nil, verbose=true, save=true)
46
+ unless variable_in && variable_out
47
+ puts "no variable specified. Simple inference coming soon" if verbose
48
+ return
49
+ end
50
+ puts "loading #{turtle_file}" if verbose
51
+ repo = RDF::Repository.load(turtle_file)
52
+ puts "loaded #{repo.size} statements into temporary repo" if verbose
53
+ # connection = Rserve::Connection.new
54
+ query = PubliSci::QueryHelper.new
55
+ rows = get_rownames(variable_in, query, repo)
56
+ puts "frame has #{rows.size} rows" if verbose
57
+
58
+ vectors = get_vectors(variable_in, query, repo)
59
+ puts "got vectors of size #{vectors.first.last.size}" if verbose && vectors.first
60
+
61
+ create_dataframe(variable_out, connection, rows, vectors)
62
+ save_workspace(connection, connection.eval('getwd()').to_ruby) if save
63
+ end
64
+
65
+ def from_store(endpoint_url,connection,variable_in=nil, variable_out=nil, verbose=true, save=true)
66
+ unless variable_in && variable_out
67
+ puts "no variable specified. Simple inference coming soon" if verbose
68
+ return
69
+ end
70
+ puts "connecting to endpoint at #{endpoint_url}" if verbose
71
+ sparql = SPARQL::Client.new(endpoint_url)
72
+ # client = PubliSci::Client.new
73
+ query = PubliSci::QueryHelper.new
74
+
75
+ rows = query.get_ary(sparql.query(query.row_names(variable_in))).flatten
76
+
77
+ end
78
+
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,18 @@
1
+ module PubliSci
2
+ module Writers
3
+ class JSON < Base
4
+ def build_json(data)
5
+ data.values.to_json
6
+ end
7
+
8
+ def from_turtle(file,select_dataset=nil,shorten_url=true)
9
+ rb = turtle_to_ruby(file,select_dataset,shorten_url)
10
+ build_json(rb[:data])
11
+ end
12
+
13
+ def from_store(file,select_dataset=nil,shorten_url=true)
14
+ build_json(repo_to_ruby(file,select_dataset,shorten_url)[:data])
15
+ end
16
+ end
17
+ end
18
+ end
data/lib/r2rdf.rb ADDED
@@ -0,0 +1,226 @@
1
+ require 'rserve'
2
+ require 'rdf/4store'
3
+ Dir[File.dirname(__FILE__) + '/vocabs/*.rb'].each {|file| require file }
4
+
5
+ class QTL2RDF
6
+
7
+ attr_accessor :port_4s
8
+
9
+ def initialize(dir='.')
10
+ @dir = File.absolute_path(dir)
11
+ @R = Rserve::Connection.new()
12
+ if File.exist?(dir + "/.RData")
13
+ # puts "loading workspace #{dir}/.RData"
14
+ @R.eval("load('#{dir}/.RData')")
15
+ end
16
+
17
+ if File.exist?(dir + "/.Rhistory")
18
+ # puts "loading history #{dir}/.Rhistory"
19
+ @R.eval("loadhistory('#{dir}/.Rhistory')")
20
+ end
21
+
22
+ @port_4s = 8080
23
+ end
24
+
25
+ def load_workspace(dir=@dir,file='.RData')
26
+ path = File.join(File.absolute_path(dir),file)
27
+ if File.exist?(path)
28
+ # puts "loading workspace #{dir}/.RData"
29
+ @R.eval("load('#{path}')")
30
+ else
31
+ puts "Couldn't find #{path}"
32
+ end
33
+ end
34
+
35
+ def load_history(dir=@dir,file='.Rhistory')
36
+ path = File.join(File.absolute_path(dir),file)
37
+ if File.exist?(path)
38
+ # puts "loading history #{dir}/.Rhistory"
39
+ @R.eval("loadhistory('#{path}')")
40
+ else
41
+ puts "Couldn't find #{path}"
42
+ end
43
+ end
44
+
45
+ def dump_dataframe(var)
46
+ h = {}
47
+ h[var] = {"attr" => {}, "rows"=>{}}
48
+
49
+ x = @R.eval(var)
50
+
51
+ x.attr.payload.keys.map{ |a|
52
+ h[var]["attr"][a] = x.attr.payload[a].to_ruby
53
+ }
54
+
55
+ rownames = x.attr.payload["row.names"].to_ruby
56
+ colnames = x.payload.keys
57
+ rownames.each_with_index.map{ |row,i|
58
+ rh = {}
59
+ colnames.map{ |col|
60
+ rh[col] = x.payload[col].to_a[i].to_f
61
+ }
62
+ h[var]["rows"][row] = rh
63
+ }
64
+
65
+ h
66
+ end
67
+
68
+ def dump(var)
69
+ x = @R.eval(var)
70
+ if x.attr
71
+ # if x.attr.payload["class"].to_a.include? 'data.frame'
72
+ dump_dataframe var
73
+ # end
74
+ else
75
+ if x.list?
76
+ type = x.payload.class.to_s.split("::").last # seems hacky, but probably only temporary
77
+ value = x.payload.map(&:payload).flatten
78
+ elsif x.payload.size == 1
79
+ type = x.class.to_s.split("::").last
80
+ value = x.payload.first
81
+ else
82
+ type = x.class.to_s.split("::").last
83
+ value = x.payload
84
+ end
85
+ {var => {"attr"=>{"class" => type}, :value => value}}
86
+ end
87
+ end
88
+
89
+ def triples_for(h)
90
+ statements = []
91
+ base_n = RDF::Node.new
92
+ attr_n = RDF::Node.new
93
+ vocab = RDF::Vocabulary.new('http://www.placeholder.com/rqtl#')
94
+ base_uri = RDF::URI.new('http://www.placeholder.com/')
95
+ var = h.keys.first
96
+
97
+ statements << RDF::Statement.new(base_n, RDF::DC.title, RDF::Literal.new(var))
98
+
99
+ if h[var].is_a? Hash
100
+ if(h[var]["attr"])
101
+ statements << RDF::Statement.new(base_n, vocab.attributes, attr_n)
102
+ h[var]["attr"].map{ |k,v| statements << RDF::Statement.new(attr_n, vocab[k], RDF::Literal.new(v)) }
103
+ end
104
+
105
+ if h[var]["rows"]
106
+ h[var]["rows"].map{ |k,v|
107
+ row_uri = base_uri.join("row#{k}")
108
+ statements << RDF::Statement.new(row_uri, vocab.row_of, base_n)
109
+ statements << RDF::Statement.new(row_uri, RDF::DC.title, k)
110
+ num = 1 # maybe container support exists in RDF.rb?
111
+ v.map { |j,u|
112
+ n = RDF::Node.new
113
+ statements << RDF::Statement.new(n, vocab.entry_of, row_uri)
114
+ statements << RDF::Statement.new(n, RDF::DC.title, j)
115
+ statements << RDF::Statement.new(n, RDF::DC.title, j)
116
+ statements << RDF::Statement.new(n, vocab["_#{num}"], RDF::Literal.new(u))
117
+ num += 1
118
+ }
119
+ }
120
+ end
121
+
122
+ if h[var].has_key? :value
123
+ statements << RDF::Statement.new(base_n, vocab.has_value, RDF::Literal.new(h[var][:value]))
124
+ end
125
+ else
126
+ statements << RDF::Statement.new(base_n, vocab.has_value, RDF::Literal.new(h[var]))
127
+ end
128
+ statements
129
+ end
130
+
131
+ #get n3 for a dataframe using datacube vocabulary
132
+ #still needs range for measures and dimensions, sdmx-dimension equivalent for rows
133
+ def n3_for(h)
134
+ str = <<-EOF
135
+ @prefix : <http://www.rqtl.org/ns/#> .
136
+ @prefix qb: <http://purl.org/linked-data/cube#> .
137
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
138
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
139
+ @prefix prop: <http://www.rqtl.org/dc/properties/> .
140
+ @prefix cs: <http://www.rqtl.org/dc/cs/> .
141
+
142
+ EOF
143
+ #@prefix sdmx-measure: <http://purl.org/linked-data/sdmx/2009/measure#>
144
+ var = h.keys.first
145
+ names = h[var]["attr"]["names"]
146
+
147
+ #generate data structure definition
148
+ str << ":dsd-#{var} a qb:DataStructureDefinition ;\n"
149
+ str << "\tqb:component cs:refRow ,\n"
150
+ names.map{ |n|
151
+ str << "\t\tcs:#{n} ,\n\n"
152
+ }
153
+ str[-3]="."
154
+
155
+ #generate component specifications
156
+ str << "cs:refRow a qb:ComponentSpecification ;\n\trdfs:label \"Component Specification for Row\" ;\n\tqb:dimension prop:refRow .\n\n"
157
+ names.map{ |n|
158
+ str << "cs:#{n} a qb:ComponentSpecification ;\n\trdfs:label \"Component Specification for #{n}\" ;\n\tqb:measure prop:#{n} .\n\n"
159
+ }
160
+
161
+ #generate dataset definition
162
+ str << ":dataset-#{var} a qb:DataSet ;\n\trdfs:label \"#{var}\"@en ;\n\tqb:structure :dsd-#{var} .\n\n"
163
+
164
+ #add DimensionProperty for row
165
+ str << <<-EOF
166
+ :refRow a rdf:Property, qb:DimensionProperty ;
167
+ \trdfs:label "Row"@en .
168
+
169
+ EOF
170
+
171
+ #generate MeasureProperties
172
+ names.map{ |n|
173
+ str << ":#{n} a rdf:Property, qb:MeasureProperty ;\n\trdfs:label \"#{n}\"@en .\n\n"
174
+ }
175
+
176
+ #add observations
177
+ h[var]["rows"].map{|k,v|
178
+ str << ":obs#{k} a qb:Observation ;\n\tqb:dataSet :dataset-#{var} ;\n\tprop:refRow :#{k} ;\n"
179
+ v.map{|l,w|
180
+ str << "\tprop:#{l} #{w} ;\n"
181
+ }
182
+ str << "\t.\n\n"
183
+ }
184
+
185
+ #add row property definitions
186
+ h[var]["rows"].map{|k,v|
187
+ str << ":#{k} a prop:refRow ;\n\trdfs:label \"#{k}\" .\n\n"
188
+ }
189
+
190
+ str
191
+ end
192
+
193
+ def statements_for(string,type=:turtle)
194
+ statements = []
195
+ RDF::Reader.for(:turtle).new(string) do |reader|
196
+ reader.each_statement do |statement|
197
+ # puts statement.inspect
198
+ statements << statement
199
+ end
200
+ end
201
+ statements
202
+ end
203
+
204
+ def turtletype_for(value)
205
+ #use for providing ranges to better define data (later)
206
+ end
207
+
208
+ def load_statements(statements)
209
+ #maybe a better way than inserting statements one at a time?
210
+ repo = RDF::FourStore::Repository.new("http://localhost:#{@port_4s}")
211
+ statements.each{|s| repo.insert(s)}
212
+ end
213
+
214
+ def to_store(var, parse_type=:turtle)
215
+ load_statements(triples_for(dump(var))) if parse_type==:ntriples
216
+
217
+ #TODO: this doesn't work (needs to be converted to statments or
218
+ # a way of inserting raw strings needs to be figured out.
219
+ load_statements(n3_for(dump(var))) if parse_type==:turtle
220
+ end
221
+
222
+ def vars
223
+ @R.eval("ls()").payload
224
+ end
225
+
226
+ end
@@ -0,0 +1,12 @@
1
+ # Please require your code below, respecting the naming conventions in the
2
+ # bioruby directory tree.
3
+ #
4
+ # For example, say you have a plugin named bio-plugin, the only uncommented
5
+ # line in this file would be
6
+ #
7
+ # require 'bio/bio-plugin/plugin'
8
+ #
9
+ # In this file only require other files. Avoid other source code.
10
+
11
+ require 'bio-publisci/publisci.rb'
12
+
@@ -0,0 +1,3 @@
1
+
2
+ module BioPublisci
3
+ end
data/lib/vocabs/cc.rb ADDED
@@ -0,0 +1,18 @@
1
+ module RDF
2
+ ##
3
+ # Creative Commons (CC) vocabulary.
4
+ #
5
+ # @see http://creativecommons.org/ns
6
+ class CC < Vocabulary("http://creativecommons.org/ns#")
7
+ property :attributionName
8
+ property :attributionURL
9
+ property :deprecatedOn
10
+ property :jurisdiction
11
+ property :legalcode
12
+ property :license
13
+ property :morePermissions
14
+ property :permits
15
+ property :prohibits
16
+ property :requires
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ module RDF
2
+ ##
3
+ # W3 Authentication Certificates (CERT) vocabulary.
4
+ #
5
+ # @see http://www.w3.org/ns/auth/cert#
6
+ # @since 0.2.0
7
+ class CERT < Vocabulary("http://www.w3.org/ns/auth/cert#")
8
+ property :decimal
9
+ property :hex
10
+ property :identity
11
+ property :public_key
12
+ end
13
+ end
data/lib/vocabs/dc.rb ADDED
@@ -0,0 +1,63 @@
1
+ module RDF
2
+ ##
3
+ # Dublin Core (DC) vocabulary.
4
+ #
5
+ # @see http://dublincore.org/schemas/rdfs/
6
+ class DC < Vocabulary("http://purl.org/dc/terms/")
7
+ property :abstract
8
+ property :accessRights
9
+ property :accrualMethod
10
+ property :accrualPeriodicity
11
+ property :accrualPolicy
12
+ property :alternative
13
+ property :audience
14
+ property :available
15
+ property :bibliographicCitation
16
+ property :conformsTo
17
+ property :contributor
18
+ property :coverage
19
+ property :created
20
+ property :creator
21
+ property :date
22
+ property :dateAccepted
23
+ property :dateCopyrighted
24
+ property :dateSubmitted
25
+ property :description
26
+ property :educationLevel
27
+ property :extent
28
+ property :format
29
+ property :hasFormat
30
+ property :hasPart
31
+ property :hasVersion
32
+ property :identifier
33
+ property :instructionalMethod
34
+ property :isFormatOf
35
+ property :isPartOf
36
+ property :isReferencedBy
37
+ property :isReplacedBy
38
+ property :isRequiredBy
39
+ property :isVersionOf
40
+ property :issued
41
+ property :language
42
+ property :license
43
+ property :mediator
44
+ property :medium
45
+ property :modified
46
+ property :provenance
47
+ property :publisher
48
+ property :references
49
+ property :relation
50
+ property :replaces
51
+ property :requires
52
+ property :rights
53
+ property :rightsHolder
54
+ property :source
55
+ property :spatial
56
+ property :subject
57
+ property :tableOfContents
58
+ property :temporal
59
+ property :title
60
+ property :type
61
+ property :valid
62
+ end
63
+ end