publisci 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,7 +19,7 @@ describe PubliSci::ORM do
19
19
 
20
20
  to_repository
21
21
  end
22
- Spira.add_repository :default, r
22
+ Spira.repository = r
23
23
 
24
24
  PubliSci::ORM::Observation.count.should > 0
25
25
 
@@ -13,7 +13,7 @@ describe PubliSci::Prov::Model do
13
13
  to_repository
14
14
  end
15
15
 
16
- Spira.add_repository :default, r
16
+ Spira.repository = r
17
17
  PubliSci::Prov::Model::Entity.first.should_not be nil
18
18
  end
19
19
 
@@ -40,7 +40,7 @@ describe PubliSci::Prov::Model do
40
40
  # generate_n3
41
41
  # end
42
42
 
43
- Spira.add_repository :default, r
43
+ Spira.repository = r
44
44
  model_agent = PubliSci::Prov::Model::Agent.first
45
45
  ag.subject.should == model_agent.subject
46
46
  acts = model_agent.activities
@@ -64,7 +64,7 @@ describe PubliSci::Prov::Model do
64
64
  to_repository
65
65
  end
66
66
 
67
- Spira.add_repository :default, r
67
+ Spira.repository = r
68
68
  PubliSci::Prov::Model::Entity.first.all_types.should == %w{http://www.w3.org/ns/prov#Entity http://purl.org/linked-data/cube#DataSet}
69
69
  PubliSci::Prov::Model::Entity.first.has_data?.should == true
70
70
  end
@@ -29,7 +29,7 @@ describe PubliSci::Dataset do
29
29
  PubliSci::Dataset.register_reader('.maf',PubliSci::Readers::MAF)
30
30
  file = PubliSci::Dataset.for('resources/maf_example.maf')
31
31
  str = IO.read(file)
32
- File.delete(file.path)
32
+ File.delete(file)
33
33
  str.size.should > 0
34
34
  (str =~ /qb:Observation/).should_not be nil
35
35
  end
@@ -7,12 +7,13 @@ require 'tempfile'
7
7
 
8
8
  describe PubliSci::Readers::MAF do
9
9
  before(:each) do
10
- @generator = PubliSci::Readers::MAF.new
10
+ @generator = PubliSci::Readers::MAF
11
11
  @in_file = 'resources/maf_example.maf'
12
12
  end
13
13
 
14
14
  describe ".generate_n3" do
15
15
  def is_cube(str)
16
+
16
17
  str[/a qb:Observation/].should_not be nil
17
18
  str[/a rdf:Property, qb:DimensionProperty/].should_not be nil
18
19
  str[/a rdf:Property, qb:MeasureProperty/].should_not be nil
@@ -45,7 +45,7 @@ class MafQuery
45
45
  end
46
46
 
47
47
  def generate_data
48
- generator = PubliSci::Readers::MAF.new
48
+ generator = PubliSci::Readers::MAF
49
49
  in_file = 'resources/maf_example.maf'
50
50
  f = Tempfile.new('graph')
51
51
  f.close
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: publisci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Strinz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-10 00:00:00.000000000 Z
11
+ date: 2013-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -150,20 +150,6 @@ dependencies:
150
150
  - - ~>
151
151
  - !ruby/object:Gem::Version
152
152
  version: 2.8.0
153
- - !ruby/object:Gem::Dependency
154
- name: rdoc
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ~>
158
- - !ruby/object:Gem::Version
159
- version: '3.12'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ~>
165
- - !ruby/object:Gem::Version
166
- version: '3.12'
167
153
  - !ruby/object:Gem::Dependency
168
154
  name: cucumber
169
155
  requirement: !ruby/object:Gem::Requirement
@@ -224,16 +210,30 @@ dependencies:
224
210
  name: rdoc
225
211
  requirement: !ruby/object:Gem::Requirement
226
212
  requirements:
227
- - - ~>
213
+ - - '>='
228
214
  - !ruby/object:Gem::Version
229
- version: '3.12'
215
+ version: '0'
230
216
  type: :development
231
217
  prerelease: false
232
218
  version_requirements: !ruby/object:Gem::Requirement
233
219
  requirements:
234
- - - ~>
220
+ - - '>='
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: pry
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - '>='
235
228
  - !ruby/object:Gem::Version
236
- version: '3.12'
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - '>='
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
237
  - !ruby/object:Gem::Dependency
238
238
  name: spoon
239
239
  requirement: !ruby/object:Gem::Requirement
@@ -311,6 +311,8 @@ files:
311
311
  - lib/publisci/dsl/dsl.rb
312
312
  - lib/publisci/dsl/metadata_dsl.rb
313
313
  - lib/publisci/dsl/prov_dsl.rb
314
+ - lib/publisci/generators/base.rb
315
+ - lib/publisci/generators/maf.rb
314
316
  - lib/publisci/metadata/generator.rb
315
317
  - lib/publisci/metadata/metadata.rb
316
318
  - lib/publisci/metadata/metadata_model.rb
@@ -333,6 +335,8 @@ files:
333
335
  - lib/publisci/mixins/vocabulary.rb
334
336
  - lib/publisci/output.rb
335
337
  - lib/publisci/parser.rb
338
+ - lib/publisci/parsers/base.rb
339
+ - lib/publisci/parsers/maf.rb
336
340
  - lib/publisci/post_processor.rb
337
341
  - lib/publisci/query/query_helper.rb
338
342
  - lib/publisci/readers/arff.rb
@@ -347,8 +351,6 @@ files:
347
351
  - lib/publisci/writers/base.rb
348
352
  - lib/publisci/writers/csv.rb
349
353
  - lib/publisci/writers/dataframe.rb
350
- - lib/r2rdf.rb
351
- - lib/template_bak.rb
352
354
  - lib/template_bak/publisci.rb
353
355
  - lib/vocabs/cc.rb
354
356
  - lib/vocabs/cert.rb
@@ -438,7 +440,7 @@ files:
438
440
  - spec/writer_spec.rb
439
441
  homepage: http://github.com/wstrinz/publisci
440
442
  licenses:
441
- - MIT
443
+ - BSD 2-Clause
442
444
  metadata: {}
443
445
  post_install_message:
444
446
  rdoc_options: []
@@ -1,226 +0,0 @@
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
@@ -1,12 +0,0 @@
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 'publisci/publisci.rb'
12
-