bio-publisci 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +10 -0
- data/Rakefile +1 -1
- data/bin/bio-publisci-server +50 -0
- data/features/reader_steps.rb +1 -1
- data/lib/bio-publisci.rb +11 -2
- data/lib/bio-publisci/datacube_model.rb +92 -88
- data/lib/bio-publisci/dataset/ORM/data_cube_orm.rb +0 -1
- data/lib/bio-publisci/dataset/data_cube.rb +78 -44
- data/lib/bio-publisci/dataset/dataset_for.rb +26 -27
- data/lib/bio-publisci/metadata/metadata_model.rb +21 -23
- data/lib/bio-publisci/metadata/prov/model/prov_models.rb +5 -5
- data/lib/bio-publisci/output.rb +1 -1
- data/lib/bio-publisci/parser.rb +130 -12
- data/lib/bio-publisci/post_processor.rb +95 -0
- data/lib/bio-publisci/query/query_helper.rb +13 -8
- data/lib/bio-publisci/readers/arff.rb +1 -1
- data/lib/bio-publisci/readers/base.rb +57 -0
- data/lib/bio-publisci/readers/csv.rb +2 -5
- data/lib/bio-publisci/readers/dataframe.rb +2 -2
- data/lib/bio-publisci/readers/maf.rb +199 -0
- data/lib/bio-publisci/readers/r_cross.rb +6 -10
- data/lib/bio-publisci/readers/r_matrix.rb +1 -1
- data/lib/bio-publisci/writers/base.rb +16 -0
- data/lib/bio-publisci/writers/json.rb +18 -0
- data/resources/maf_example.maf +10 -0
- data/resources/maf_rdf.ttl +1173 -0
- data/resources/primer.ttl +38 -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/patient.rq +11 -0
- data/resources/queries/patient_list.rq +11 -0
- data/resources/queries/patients_with_mutation.rq +18 -0
- data/scripts/get_gene_lengths.rb +50 -0
- data/scripts/islet_mlratio.rb +1 -1
- data/scripts/scan_islet.rb +1 -1
- data/scripts/update_reference.rb +8 -3
- 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 +1 -0
- data/spec/bnode_spec.rb +66 -0
- data/spec/data_cube_spec.rb +66 -63
- data/spec/dataset_for_spec.rb +36 -16
- data/spec/dsl_spec.rb +41 -0
- data/spec/generators/csv_spec.rb +3 -3
- data/spec/generators/dataframe_spec.rb +2 -2
- data/spec/generators/maf_spec.rb +40 -0
- data/spec/generators/r_cross_spec.rb +2 -2
- data/spec/generators/r_matrix_spec.rb +2 -2
- data/spec/length_lookup_spec.rb +0 -0
- data/spec/maf_query_spec.rb +343 -0
- data/spec/resource/example.Rhistory +1 -1
- data/spec/turtle/bacon +9 -9
- data/spec/turtle/reference +43 -43
- data/spec/turtle/weather +10 -10
- data/spec/writer_spec.rb +16 -2
- metadata +212 -61
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e7e64a90c4e9a15927e2ef67477298d50d22358e
|
4
|
+
data.tar.gz: 18c0ccecba26dc09e9604966b992f2444dbf4b0c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7bdfa9be8aee03c937b8a4298f05589035ebfbe2ffe8d0ece67da239580f0ab11b192dc3d2e48cb7a2efde2e78ee31f2cc20ba55afdf68c60565a31c8c3251ee
|
7
|
+
data.tar.gz: 1d0a10523a45cf231f521f4026fe7672e29143ca68a0d56af8bcc4df4a4b433b286c81eae7d4008944b93e4f9806732aec95b43a9faf2b885673686722eba7a9
|
data/Gemfile
CHANGED
@@ -21,6 +21,16 @@ end
|
|
21
21
|
gem 'rdf'
|
22
22
|
gem 'rdf-4store', :git => "https://github.com/fumi/rdf-4store.git"
|
23
23
|
gem 'rdf-turtle'
|
24
|
+
gem 'rdf-rdfxml'
|
25
|
+
gem 'json-ld'
|
24
26
|
gem 'rserve-client'
|
25
27
|
gem 'sparql'
|
26
28
|
|
29
|
+
gem 'slop'
|
30
|
+
|
31
|
+
gem 'sinatra'
|
32
|
+
gem 'sinatra-contrib'
|
33
|
+
gem 'sinatra-linkeddata'
|
34
|
+
gem 'sinatra-cross_origin'
|
35
|
+
gem 'rack-flash3'
|
36
|
+
gem 'rest-client'
|
data/Rakefile
CHANGED
@@ -21,7 +21,7 @@ Jeweler::Tasks.new do |gem|
|
|
21
21
|
gem.description = %Q{A toolkit for publishing scientific results and datasets using RDF, OWL, and related technologies }
|
22
22
|
gem.email = "wstrinz@gmail.com"
|
23
23
|
gem.authors = ["Will Strinz"]
|
24
|
-
gem.version = "0.0
|
24
|
+
gem.version = "0.1.0"
|
25
25
|
|
26
26
|
# dependencies defined in Gemfile
|
27
27
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'cgi'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
require 'bio-publisci'
|
6
|
+
require 'slop'
|
7
|
+
|
8
|
+
require 'sinatra/base'
|
9
|
+
require "sinatra/linkeddata"
|
10
|
+
require "sinatra/cross_origin"
|
11
|
+
require 'rack-flash'
|
12
|
+
|
13
|
+
class PubliSciServer < Sinatra::Base
|
14
|
+
configure do
|
15
|
+
enable :sessions
|
16
|
+
enable :cross_origin
|
17
|
+
end
|
18
|
+
|
19
|
+
set :views, File.dirname(__FILE__) + '/../server/views'
|
20
|
+
# set :repository, RDF::Repository.new
|
21
|
+
set :sudo_pass, nil
|
22
|
+
|
23
|
+
use Rack::Flash
|
24
|
+
|
25
|
+
require_relative '../server/helpers.rb'
|
26
|
+
|
27
|
+
if ARGV[0]
|
28
|
+
opts = Slop.parse do
|
29
|
+
banner 'Usage: bio-publisci-server [options]'
|
30
|
+
|
31
|
+
on 'uri', 'Store URI', argument: :optional
|
32
|
+
on 't', 'type', 'The repository type', argument: :optional
|
33
|
+
on 'a', 'sudo_pass', 'Password for sudo (currently needed to clear 4store)', argument: :optional
|
34
|
+
on 'p', 'port', 'Sinatra port', argument: :optional
|
35
|
+
on 'o', 'bind', 'Bind address ', argument: :optional
|
36
|
+
end
|
37
|
+
|
38
|
+
configure_server(opts)
|
39
|
+
else
|
40
|
+
# set :repository, RDF::FourStore::Repository.new('http://localhost:8080')
|
41
|
+
set :repository, RDF::Repository.new
|
42
|
+
|
43
|
+
settings.repository.load(File.dirname(__FILE__) + '/../resources/primer.ttl')
|
44
|
+
end
|
45
|
+
|
46
|
+
require_relative '../server/routes.rb'
|
47
|
+
|
48
|
+
|
49
|
+
run!
|
50
|
+
end
|
data/features/reader_steps.rb
CHANGED
data/lib/bio-publisci.rb
CHANGED
@@ -1,12 +1,19 @@
|
|
1
1
|
# This is temporary, just to help w/ development so I don't have to rewrite r2rdf.rb to be
|
2
2
|
# a standard gem base yet. Also load s the files instead of require for easy reloading
|
3
3
|
require 'tempfile'
|
4
|
-
require '
|
4
|
+
require 'fileutils'
|
5
5
|
require 'csv'
|
6
|
-
|
6
|
+
|
7
|
+
require 'rdf'
|
7
8
|
require 'sparql'
|
8
9
|
require 'sparql/client'
|
9
10
|
require 'rdf/turtle'
|
11
|
+
require 'rdf/rdfxml'
|
12
|
+
require 'json/ld'
|
13
|
+
|
14
|
+
require 'rserve'
|
15
|
+
require 'rest-client'
|
16
|
+
|
10
17
|
begin
|
11
18
|
require 'spira'
|
12
19
|
rescue LoadError
|
@@ -27,6 +34,7 @@ load_folder('bio-publisci/mixins')
|
|
27
34
|
load File.dirname(__FILE__) + '/bio-publisci/dataset/interactive.rb'
|
28
35
|
load File.dirname(__FILE__) + '/bio-publisci/query/query_helper.rb'
|
29
36
|
load File.dirname(__FILE__) + '/bio-publisci/parser.rb'
|
37
|
+
load File.dirname(__FILE__) + '/bio-publisci/post_processor.rb'
|
30
38
|
load File.dirname(__FILE__) + '/bio-publisci/r_client.rb'
|
31
39
|
load File.dirname(__FILE__) + '/bio-publisci/analyzer.rb'
|
32
40
|
load File.dirname(__FILE__) + '/bio-publisci/store.rb'
|
@@ -39,6 +47,7 @@ load File.dirname(__FILE__) + '/bio-publisci/output.rb'
|
|
39
47
|
load File.dirname(__FILE__) + '/bio-publisci/metadata/prov/element.rb'
|
40
48
|
load File.dirname(__FILE__) + '/bio-publisci/metadata/prov/prov.rb'
|
41
49
|
load File.dirname(__FILE__) + '/bio-publisci/writers/base.rb'
|
50
|
+
load File.dirname(__FILE__) + '/bio-publisci/readers/base.rb'
|
42
51
|
|
43
52
|
|
44
53
|
load_folder('bio-publisci/dsl')
|
@@ -1,107 +1,111 @@
|
|
1
1
|
require 'rdf/4store'
|
2
|
+
begin
|
3
|
+
require 'spira'
|
4
|
+
module PubliSci
|
5
|
+
module ORM
|
6
|
+
# class Observation < Spira::Base
|
7
|
+
# type RDF::URI.new('http://purl.org/linked-data/cube#Observation')
|
8
|
+
# property :label, predicate: RDFS.label
|
9
|
+
|
10
|
+
# end
|
11
|
+
QB ||= RDF::Vocabulary.new(RDF::URI.new('http://purl.org/linked-data/cube#'))
|
12
|
+
|
13
|
+
class Component < Spira::Base
|
14
|
+
type QB.ComponentSpecification
|
15
|
+
property :dimension, predicate: QB.dimension # RDF::URI.new('http://purl.org/linked-data/cube#dimension')
|
16
|
+
property :measure, predicate: QB.measure # RDF::URI.new('http://purl.org/linked-data/cube#measure')
|
17
|
+
end
|
2
18
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
# end
|
10
|
-
QB ||= RDF::Vocabulary.new(RDF::URI.new('http://purl.org/linked-data/cube#'))
|
11
|
-
|
12
|
-
class Component < Spira::Base
|
13
|
-
type QB.ComponentSpecification
|
14
|
-
property :dimension, predicate: QB.dimension # RDF::URI.new('http://purl.org/linked-data/cube#dimension')
|
15
|
-
property :measure, predicate: QB.measure # RDF::URI.new('http://purl.org/linked-data/cube#measure')
|
16
|
-
end
|
19
|
+
class DataStructureDefinition < Spira::Base
|
20
|
+
type QB.DataStructureDefinition
|
21
|
+
property :label, predicate: RDFS.label
|
22
|
+
has_many :component, predicate: QB.component
|
23
|
+
end
|
17
24
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
25
|
+
class DataSet < Spira::Base
|
26
|
+
type QB.DataSet
|
27
|
+
property :label, predicate: RDFS.label
|
28
|
+
property :structure, predicate: QB.structure
|
29
|
+
end
|
23
30
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
31
|
+
class Dimension < Spira::Base
|
32
|
+
type QB.DimensionProperty
|
33
|
+
property :range, predicate: RDFS.range
|
34
|
+
property :label, predicate: RDFS.label
|
35
|
+
end
|
29
36
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
37
|
+
class Measure < Spira::Base
|
38
|
+
type QB.MeasureProperty
|
39
|
+
property :label, predicate: RDFS.label
|
40
|
+
end
|
35
41
|
|
36
|
-
class Measure < Spira::Base
|
37
|
-
type QB.MeasureProperty
|
38
|
-
property :label, predicate: RDFS.label
|
39
|
-
end
|
40
42
|
|
43
|
+
def load_repo(repo)
|
44
|
+
raise "Not an RDF::Repository - #{repo}" unless repo.is_a? RDF::Repository
|
45
|
+
Spira.add_repository :default, repo
|
46
|
+
end
|
41
47
|
|
42
|
-
|
43
|
-
|
44
|
-
Spira
|
45
|
-
|
48
|
+
# def observation
|
49
|
+
# unless PubliSci::ORM.const_defined?("Observation")
|
50
|
+
# obs = Class.new(Spira::Base) do
|
51
|
+
# type RDF::URI.new('http://purl.org/linked-data/cube#Observation')
|
52
|
+
|
53
|
+
# property :structure, predicate: QB.dataSet
|
54
|
+
|
55
|
+
# ((Dimension.each.to_a | Measure.each.to_a) || []).each{|component|
|
56
|
+
# property strip_uri(component.subject.to_s), predicate: component.subject
|
57
|
+
# }
|
58
|
+
# end
|
59
|
+
# PubliSci::ORM.const_set("Observation",obs)
|
60
|
+
# end
|
61
|
+
# Observation
|
62
|
+
# end
|
63
|
+
|
64
|
+
class Observation < Spira::Base
|
65
|
+
type QB.Observation
|
66
|
+
property :label, predicate: RDFS.label
|
67
|
+
property :dataset, predicate: QB.dataSet
|
68
|
+
|
69
|
+
def load_properties
|
70
|
+
comps = dataset.as(DataSet).structure.as(DataStructureDefinition).component.map{|comp| comp.as(Component)}
|
71
|
+
props = comps.map{|comp| comp.dimension ? comp.dimension.as(Dimension) : comp.measure.as(Measure) }
|
72
|
+
props.each{|prop|
|
73
|
+
ss = strip_uri(prop.subject.to_s)
|
74
|
+
|
75
|
+
self.class.property ss.to_sym, predicate: prop.subject
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
# for testing; DRY up eventually
|
80
|
+
def strip_uri(uri)
|
81
|
+
uri = uri.to_s.dup
|
82
|
+
uri[-1] = '' if uri[-1] == '>'
|
83
|
+
uri.to_s.split('/').last.split('#').last
|
84
|
+
end
|
85
|
+
|
86
|
+
# def method_missing(meth, *args, &block)
|
87
|
+
# if meth.to_s =~ /^find_by_(.+)$/
|
88
|
+
# run_find_by_method($1, *args, &block)
|
89
|
+
# else
|
90
|
+
# super # You *must* call super if you don't handle the
|
91
|
+
# # method, otherwise you'll mess up Ruby's method
|
92
|
+
# # lookup.
|
93
|
+
# end
|
94
|
+
# end
|
95
|
+
end
|
46
96
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
# type RDF::URI.new('http://purl.org/linked-data/cube#Observation')
|
51
|
-
|
52
|
-
# property :structure, predicate: QB.dataSet
|
53
|
-
|
54
|
-
# ((Dimension.each.to_a | Measure.each.to_a) || []).each{|component|
|
55
|
-
# property strip_uri(component.subject.to_s), predicate: component.subject
|
56
|
-
# }
|
57
|
-
# end
|
58
|
-
# PubliSci::ORM.const_set("Observation",obs)
|
59
|
-
# end
|
60
|
-
# Observation
|
61
|
-
# end
|
62
|
-
|
63
|
-
class Observation < Spira::Base
|
64
|
-
type QB.Observation
|
65
|
-
property :label, predicate: RDFS.label
|
66
|
-
property :dataset, predicate: QB.dataSet
|
67
|
-
|
68
|
-
def load_properties
|
69
|
-
comps = dataset.as(DataSet).structure.as(DataStructureDefinition).component.map{|comp| comp.as(Component)}
|
70
|
-
props = comps.map{|comp| comp.dimension ? comp.dimension.as(Dimension) : comp.measure.as(Measure) }
|
71
|
-
props.each{|prop|
|
72
|
-
ss = strip_uri(prop.subject.to_s)
|
73
|
-
|
74
|
-
self.class.property ss.to_sym, predicate: prop.subject
|
75
|
-
}
|
97
|
+
def reload_observation
|
98
|
+
PubliSci::ORM.send(:remove_const, "Observation")
|
99
|
+
observation
|
76
100
|
end
|
77
101
|
|
78
|
-
# for testing; DRY up eventually
|
79
102
|
def strip_uri(uri)
|
80
103
|
uri = uri.to_s.dup
|
81
104
|
uri[-1] = '' if uri[-1] == '>'
|
82
105
|
uri.to_s.split('/').last.split('#').last
|
83
106
|
end
|
84
|
-
|
85
|
-
# def method_missing(meth, *args, &block)
|
86
|
-
# if meth.to_s =~ /^find_by_(.+)$/
|
87
|
-
# run_find_by_method($1, *args, &block)
|
88
|
-
# else
|
89
|
-
# super # You *must* call super if you don't handle the
|
90
|
-
# # method, otherwise you'll mess up Ruby's method
|
91
|
-
# # lookup.
|
92
|
-
# end
|
93
|
-
# end
|
94
|
-
end
|
95
|
-
|
96
|
-
def reload_observation
|
97
|
-
PubliSci::ORM.send(:remove_const, "Observation")
|
98
|
-
observation
|
99
|
-
end
|
100
|
-
|
101
|
-
def strip_uri(uri)
|
102
|
-
uri = uri.to_s.dup
|
103
|
-
uri[-1] = '' if uri[-1] == '>'
|
104
|
-
uri.to_s.split('/').last.split('#').last
|
105
107
|
end
|
106
108
|
end
|
109
|
+
rescue LoadError
|
110
|
+
# puts "Skipping ORM load"
|
107
111
|
end
|
@@ -13,7 +13,7 @@ module PubliSci
|
|
13
13
|
{
|
14
14
|
type: :dataframe,
|
15
15
|
encode_nulls: false,
|
16
|
-
base_url: "http://
|
16
|
+
base_url: "http://onto.strinz.me",
|
17
17
|
}
|
18
18
|
end
|
19
19
|
|
@@ -32,12 +32,10 @@ module PubliSci
|
|
32
32
|
|
33
33
|
newd = dimensions.map{|d|
|
34
34
|
if d =~ /^http:\/\//
|
35
|
-
# newc << "<#{d}>" if codes.include? d
|
36
35
|
"<#{d}>"
|
37
36
|
elsif d =~ /^[a-zA-z]+:[a-zA-z]+$/
|
38
37
|
d
|
39
38
|
else
|
40
|
-
# newc << "prop:#{d}" if codes.include? d
|
41
39
|
"prop:#{d}"
|
42
40
|
end
|
43
41
|
}
|
@@ -60,9 +58,10 @@ module PubliSci
|
|
60
58
|
[newm, newd, newc]
|
61
59
|
end
|
62
60
|
|
63
|
-
def component_gen(args,options={})
|
61
|
+
def component_gen(args,var,options={})
|
64
62
|
args = Array[args].flatten
|
65
|
-
args.map{|arg| arg.gsub("prop:","cs:").gsub(%r{<#{options[:base_url]}/.+/(\w.+)>$},'cs:'+'\1')}
|
63
|
+
args = args.map{|arg| arg.gsub("prop:","cs:").gsub(%r{<#{options[:base_url]}/.+/(\w.+)>$},'cs:'+'\1')}
|
64
|
+
args.map{|arg| arg.gsub(%r{<http://(.+)>},"<#{options[:base_url]}/dc/dataset/#{var}/cs/"+'\1'+'>')}
|
66
65
|
end
|
67
66
|
|
68
67
|
def encode_data(codes,data,var,options={})
|
@@ -76,7 +75,7 @@ module PubliSci
|
|
76
75
|
elsif val =~ /^[a-zA-z]+:[a-zA-z]+$/
|
77
76
|
val
|
78
77
|
else
|
79
|
-
"<code/#{k.downcase}/#{val}>"
|
78
|
+
"<code/#{k.downcase}/#{sanitize(val).first}>"
|
80
79
|
end
|
81
80
|
}
|
82
81
|
else
|
@@ -120,12 +119,12 @@ module PubliSci
|
|
120
119
|
options = defaults().merge(options)
|
121
120
|
base = options[:base_url]
|
122
121
|
<<-EOF.unindent
|
123
|
-
@base <#{base}/
|
124
|
-
@prefix ns: <#{base}/
|
122
|
+
@base <#{base}/dc/dataset/#{var}/> .
|
123
|
+
@prefix ns: <#{base}/dc/dataset/#{var}/> .
|
125
124
|
@prefix qb: <http://purl.org/linked-data/cube#> .
|
126
125
|
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
127
126
|
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
128
|
-
@prefix prop: <#{base}/
|
127
|
+
@prefix prop: <#{base}/properties/> .
|
129
128
|
@prefix dct: <http://purl.org/dc/terms/> .
|
130
129
|
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
|
131
130
|
@prefix cs: <#{base}/dc/dataset/#{var}/cs/> .
|
@@ -143,8 +142,8 @@ module PubliSci
|
|
143
142
|
var = sanitize([var]).first
|
144
143
|
options = defaults().merge(options)
|
145
144
|
rdf_measures, rdf_dimensions, rdf_codes = generate_resources(measures, dimensions, codes, options)
|
146
|
-
cs_dims = component_gen(rdf_dimensions,options) #rdf_dimensions.map{|d| d.gsub('prop:','cs:')}
|
147
|
-
cs_meas = component_gen(rdf_measures,options) #rdf_measures.map!{|m| m.gsub('prop:','cs:')}
|
145
|
+
cs_dims = component_gen(rdf_dimensions,var,options) #rdf_dimensions.map{|d| d.gsub('prop:','cs:')}
|
146
|
+
cs_meas = component_gen(rdf_measures,var,options) #rdf_measures.map!{|m| m.gsub('prop:','cs:')}
|
148
147
|
str = "ns:dsd-#{var} a qb:DataStructureDefinition;\n"
|
149
148
|
cs_dims.map{|d|
|
150
149
|
str << " qb:component #{d} ;\n"
|
@@ -172,16 +171,14 @@ module PubliSci
|
|
172
171
|
def component_specifications(measure_names, dimension_names, codes, var, options={})
|
173
172
|
options = defaults().merge(options)
|
174
173
|
rdf_measures, rdf_dimensions, rdf_codes = generate_resources(measure_names, dimension_names, codes, options)
|
175
|
-
cs_dims = component_gen(rdf_dimensions,options)
|
176
|
-
cs_meas = component_gen(rdf_measures,options)
|
177
|
-
# cs_dims = rdf_dimensions.map{|d| d.gsub('prop:','cs:')}
|
178
|
-
# cs_meas = rdf_measures.map{|m| m.gsub('prop:','cs:')}
|
174
|
+
cs_dims = component_gen(rdf_dimensions,var,options)
|
175
|
+
cs_meas = component_gen(rdf_measures,var,options)
|
179
176
|
specs = []
|
180
177
|
|
181
178
|
rdf_dimensions.each_with_index.map{|d,i|
|
182
179
|
specs << <<-EOF.unindent
|
183
180
|
#{cs_dims[i]} a qb:ComponentSpecification ;
|
184
|
-
rdfs:label "#{strip_prefixes(strip_uri(dimension_names[i]))}
|
181
|
+
rdfs:label "#{strip_prefixes(strip_uri(dimension_names[i]))}" ;
|
185
182
|
qb:dimension #{d} .
|
186
183
|
|
187
184
|
EOF
|
@@ -190,7 +187,7 @@ module PubliSci
|
|
190
187
|
rdf_measures.each_with_index.map{|n,i|
|
191
188
|
specs << <<-EOF.unindent
|
192
189
|
#{cs_meas[i]} a qb:ComponentSpecification ;
|
193
|
-
rdfs:label "#{strip_prefixes(strip_uri(measure_names[i]))}
|
190
|
+
rdfs:label "#{strip_prefixes(strip_uri(measure_names[i]))}" ;
|
194
191
|
qb:measure #{n} .
|
195
192
|
|
196
193
|
EOF
|
@@ -214,6 +211,7 @@ module PubliSci
|
|
214
211
|
|
215
212
|
rdf_dimensions.each_with_index{|d,i|
|
216
213
|
if dimension_codes.include?(dimensions[i])
|
214
|
+
|
217
215
|
code = rdf_codes[dimension_codes.index(dimensions[i])]
|
218
216
|
props << <<-EOF.unindent
|
219
217
|
#{d} a rdf:Property, qb:DimensionProperty ;
|
@@ -225,9 +223,13 @@ module PubliSci
|
|
225
223
|
else
|
226
224
|
props << <<-EOF.unindent
|
227
225
|
#{d} a rdf:Property, qb:DimensionProperty ;
|
228
|
-
rdfs:label "#{strip_prefixes(strip_uri(d))}"@en
|
229
|
-
|
226
|
+
rdfs:label "#{strip_prefixes(strip_uri(d))}"@en ;
|
230
227
|
EOF
|
228
|
+
if options[:ranges] && options[:ranges][dimension[i]]
|
229
|
+
props.last << "\n rdfs:range #{options[:ranges][dimensions[i]]} .\n\n"
|
230
|
+
else
|
231
|
+
props.last[-2] = ".\n"
|
232
|
+
end
|
231
233
|
end
|
232
234
|
}
|
233
235
|
|
@@ -239,14 +241,19 @@ module PubliSci
|
|
239
241
|
rdf_measures = generate_resources(measures, [], [], options)[0]
|
240
242
|
props = []
|
241
243
|
|
242
|
-
|
244
|
+
rdf_measures.each_with_index{ |m,i|
|
243
245
|
|
244
|
-
|
245
|
-
|
246
|
-
|
246
|
+
props << <<-EOF.unindent
|
247
|
+
#{m} a rdf:Property, qb:MeasureProperty ;
|
248
|
+
rdfs:label "#{strip_prefixes(strip_uri(m))}"@en ;
|
249
|
+
EOF
|
247
250
|
|
248
|
-
|
249
|
-
}
|
251
|
+
if options[:ranges] && options[:ranges][measures[i]]
|
252
|
+
props.last << " rdfs:range #{options[:ranges][measures[i]]} .\n\n"
|
253
|
+
else
|
254
|
+
props.last[-2] = ".\n"
|
255
|
+
end
|
256
|
+
}
|
250
257
|
|
251
258
|
props
|
252
259
|
end
|
@@ -255,7 +262,11 @@ module PubliSci
|
|
255
262
|
var = sanitize([var]).first
|
256
263
|
measures = sanitize(measures)
|
257
264
|
dimensions = sanitize(dimensions)
|
265
|
+
|
266
|
+
data.each{|k,v| data[k]=Array(v)}
|
267
|
+
observation_labels = Array(observation_labels)
|
258
268
|
options = defaults().merge(options)
|
269
|
+
|
259
270
|
rdf_measures, rdf_dimensions, rdf_codes = generate_resources(measures, dimensions, codes, options)
|
260
271
|
data = encode_data(codes, data, var, options)
|
261
272
|
obs = []
|
@@ -269,7 +280,7 @@ module PubliSci
|
|
269
280
|
}
|
270
281
|
|
271
282
|
observation_labels.each_with_index.map{|r, i|
|
272
|
-
contains_nulls = false
|
283
|
+
# contains_nulls = false
|
273
284
|
str = <<-EOF.unindent
|
274
285
|
ns:obs#{r} a qb:Observation ;
|
275
286
|
qb:dataSet ns:dataset-#{var} ;
|
@@ -277,33 +288,57 @@ module PubliSci
|
|
277
288
|
|
278
289
|
str << " rdfs:label \"#{r}\" ;\n" unless options[:no_labels]
|
279
290
|
|
291
|
+
obs_index = 0
|
292
|
+
obs_nodes = []
|
293
|
+
|
280
294
|
dimensions.each_with_index{|d,j|
|
281
|
-
contains_nulls =
|
295
|
+
contains_nulls = (data[d][i] == nil)
|
282
296
|
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
297
|
+
unless contains_nulls && !options[:encode_nulls]
|
298
|
+
if is_complex?(data[d][i])
|
299
|
+
str << " #{rdf_dimensions[j]} #{add_node(obs_index,add_node(r))} ;\n"
|
300
|
+
obs_nodes << encode_value(data[d][i], options, obs_index, add_node(r))
|
301
|
+
else
|
302
|
+
str << " #{rdf_dimensions[j]} #{encode_value(data[d][i], options)} ;\n"
|
303
|
+
end
|
288
304
|
end
|
305
|
+
|
306
|
+
obs_index += 1
|
289
307
|
}
|
290
308
|
|
291
309
|
measures.each_with_index{|m,j|
|
292
|
-
contains_nulls =
|
293
|
-
|
310
|
+
contains_nulls = (data[m][i] == nil)
|
311
|
+
|
312
|
+
unless contains_nulls && !options[:encode_nulls]
|
313
|
+
if is_complex?(data[m][i])
|
314
|
+
str << " #{rdf_measures[j]} #{add_node(obs_index,add_node(r))} ;\n"
|
315
|
+
val = encode_value(data[m][i], options, obs_index, add_node(r))
|
316
|
+
|
317
|
+
if val.last.is_a? Array
|
318
|
+
unless val.last.last[-2] == "."
|
319
|
+
val.last.last << ".\n"
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
obs_nodes << val
|
324
|
+
else
|
325
|
+
str << " #{rdf_measures[j]} #{encode_value(data[m][i], options)} ;\n"
|
326
|
+
end
|
327
|
+
end
|
294
328
|
|
329
|
+
obs_index += 1
|
295
330
|
}
|
296
331
|
|
297
332
|
str << " .\n\n"
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
end
|
304
|
-
else
|
305
|
-
obs << str
|
333
|
+
|
334
|
+
if obs_nodes.size > 0
|
335
|
+
flatted = obs_nodes.flatten
|
336
|
+
str << turtle_indent(flatted.join("\n"))
|
337
|
+
str << " \n\n"
|
306
338
|
end
|
339
|
+
|
340
|
+
obs << str
|
341
|
+
|
307
342
|
}
|
308
343
|
obs
|
309
344
|
end
|
@@ -356,7 +391,6 @@ module PubliSci
|
|
356
391
|
else
|
357
392
|
refcode = code[0]
|
358
393
|
end
|
359
|
-
# puts data[refcode].uniq
|
360
394
|
data[refcode].uniq.each_with_index{|value,i|
|
361
395
|
unless value == nil && !options[:encode_nulls]
|
362
396
|
concepts << <<-EOF.unindent
|
@@ -377,7 +411,7 @@ module PubliSci
|
|
377
411
|
def abbreviate_known(turtle_string)
|
378
412
|
#debug method
|
379
413
|
# puts turtle_string
|
380
|
-
turtle_string.gsub(/<http:\/\/www\.rqtl\.org\/dc\/properties\/(\S+)>/, 'prop:\1').gsub(/<http:\/\/www.rqtl.org\/ns\/dc\/code\/(\S+)\/(\S+)>/, '<code/\1/\2>').gsub(/<http:\/\/www.rqtl.org\/dc\/dataset\/(\S+)\/code\/(\
|
414
|
+
turtle_string.gsub(/<http:\/\/www\.rqtl\.org\/dc\/properties\/(\S+)>/, 'prop:\1').gsub(/<http:\/\/www.rqtl.org\/ns\/dc\/code\/(\S+)\/(\S+)>/, '<code/\1/\2>').gsub(/<http:\/\/www.rqtl.org\/dc\/dataset\/(\S+)\/code\/(\w+)>/, 'code:\2').gsub(/<http:\/\/www.rqtl.org\/dc\/dataset\/(\S+)\/code\/(\S+)>/, '<code/' + '\2' +'>')
|
381
415
|
end
|
382
416
|
end
|
383
417
|
end
|