nesstar-api 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/nesstar-api.rb +58 -16
- data/lib/nesstar-api/catalog.rb +3 -3
- data/lib/nesstar-api/category_statistic.rb +1 -1
- data/lib/nesstar-api/study.rb +2 -2
- data/lib/nesstar-api/summary_stat.rb +1 -0
- data/lib/nesstar-api/version.rb +1 -1
- metadata +4 -4
data/lib/nesstar-api.rb
CHANGED
@@ -14,13 +14,17 @@ require 'nesstar-api/study_date'
|
|
14
14
|
require 'nesstar-api/variable'
|
15
15
|
require 'nesstar-api/summary_stat'
|
16
16
|
|
17
|
+
#Methods for retrieving Nesstar catalog hierarchy and
|
18
|
+
#metadata information
|
17
19
|
module Nesstar
|
18
20
|
module Api
|
19
21
|
|
20
22
|
class CatalogApi
|
21
23
|
|
22
|
-
#
|
23
|
-
#survey types, which are surveys and link them to child datasets
|
24
|
+
#Given tree of datasets and catalogs, contained in a RubyTree Node object
|
25
|
+
#figure out which are the survey types, which are surveys and link them to child datasets
|
26
|
+
#This is to match the MethodBox (http://www.methodbox.org) data model, basically
|
27
|
+
#a dataset belongs to a survey which has a survey type.
|
24
28
|
def parse_surveys_from_nodes node, surveys_hash, survey_types_hash
|
25
29
|
node.children.each do |node|
|
26
30
|
if node.name.index('fStudy')
|
@@ -59,6 +63,14 @@ module Nesstar
|
|
59
63
|
end
|
60
64
|
end
|
61
65
|
|
66
|
+
#Get a hash of catalogs to child catalogs and datasets from a
|
67
|
+
#Nesstar instance. The children will be contained in an Array object
|
68
|
+
#Inputs are a url to the nesstar server eg
|
69
|
+
#http://nesstar.somewhere.com and a catalog id eg myCatalog
|
70
|
+
#If there appears to be no parent catalog for something then
|
71
|
+
#the key will be listed as 'none'
|
72
|
+
#
|
73
|
+
#Returns a Hash of catalogs to children
|
62
74
|
def get_catalog url, catalog
|
63
75
|
|
64
76
|
#Hash of catalogs to their child datasets
|
@@ -75,6 +87,11 @@ module Nesstar
|
|
75
87
|
return catalog_hash
|
76
88
|
end
|
77
89
|
|
90
|
+
#Given a Nesstar url and catalog eg
|
91
|
+
#http://nesstar.somewhere.com and a catalog id eg myCatalog
|
92
|
+
#the return a RubyTree node object containing the hierarchy.
|
93
|
+
#
|
94
|
+
#Returns a RubyTree Node
|
78
95
|
def get_nodes url, catalog
|
79
96
|
#tree of catalogs to their child datasets
|
80
97
|
root_tree_node = Tree::TreeNode.new(catalog, "Catalog Content")
|
@@ -90,7 +107,10 @@ module Nesstar
|
|
90
107
|
return root_tree_node
|
91
108
|
end
|
92
109
|
|
93
|
-
#
|
110
|
+
#Get the ddi xml for a nesstar dataset given a Nesstar url and catalog eg
|
111
|
+
#http://nesstar.somewhere.com and a catalog id eg myCatalog
|
112
|
+
#
|
113
|
+
#returns the ddi xml raw string
|
94
114
|
def get_ddi uri, dataset
|
95
115
|
ddi_uri = URI.parse(uri)
|
96
116
|
ddi_uri.merge!("/obj/fStudy/" + dataset)
|
@@ -102,11 +122,13 @@ module Nesstar
|
|
102
122
|
end
|
103
123
|
|
104
124
|
#return a catalog object with information inside it
|
105
|
-
#
|
106
|
-
#
|
107
|
-
|
125
|
+
#given a Nesstar url and catalog eg
|
126
|
+
#http://nesstar.somewhere.com and a catalog id eg myCatalog
|
127
|
+
#
|
128
|
+
#Returns a Nesstar::Catalog object
|
129
|
+
def get_catalog_information uri, catalog_id
|
108
130
|
catalog_uri = URI.parse(uri)
|
109
|
-
catalog_uri.merge!("/obj/fCatalog/" +
|
131
|
+
catalog_uri.merge!("/obj/fCatalog/" + catalog_id)
|
110
132
|
catalog_res = Net::HTTP.get(catalog_uri)
|
111
133
|
gz = Zlib::GzipReader.new(StringIO.new(catalog_res))
|
112
134
|
catalog_info = gz.read
|
@@ -114,15 +136,21 @@ module Nesstar
|
|
114
136
|
label = doc.xpath('//s:label')
|
115
137
|
description = doc.xpath('//s:comment')
|
116
138
|
catalog = Nesstar::Catalog.new
|
139
|
+
catalog.nesstar_id = catalog_id
|
140
|
+
catalog.nesstar_uri = uri
|
117
141
|
catalog.label = label[0].content.strip unless label[0] == nil
|
118
142
|
catalog.description = description[0].content.strip unless description[0] == nil
|
119
143
|
return catalog
|
120
144
|
end
|
121
145
|
|
122
|
-
#information about the dataset only
|
123
|
-
|
146
|
+
#Get basic information about the dataset only given a Nesstar url and catalog eg
|
147
|
+
#http://nesstar.somewhere.com and a catalog id eg myCatalog
|
148
|
+
#No information about the variables a study (ie dataset) contains are returned
|
149
|
+
#
|
150
|
+
#Returns a Nesstar::Study object
|
151
|
+
def get_simple_study_information uri, dataset_id
|
124
152
|
dataset_uri = URI.parse(uri)
|
125
|
-
dataset_uri.merge!("/obj/fStudy/" +
|
153
|
+
dataset_uri.merge!("/obj/fStudy/" + dataset_id)
|
126
154
|
dataset_res = Net::HTTP.get(dataset_uri)
|
127
155
|
gz = Zlib::GzipReader.new(StringIO.new(dataset_res))
|
128
156
|
dataset_info = gz.read
|
@@ -130,23 +158,31 @@ module Nesstar
|
|
130
158
|
label = doc.xpath('//s:label')
|
131
159
|
description = doc.xpath('//s:comment')
|
132
160
|
study = Nesstar::Study.new
|
161
|
+
study.nesstar_id = dataset_id
|
162
|
+
study.nesstar_uri = uri
|
133
163
|
study.title = label[0].content.strip unless label[0] == nil
|
134
164
|
study.abstract = description[0].content.strip unless description[0] == nil
|
135
165
|
return study
|
136
166
|
end
|
137
167
|
|
138
168
|
#information about the dataset and its variables
|
139
|
-
#
|
140
|
-
|
169
|
+
#given a Nesstar url and catalog eg
|
170
|
+
#http://nesstar.somewhere.com and a catalog id eg myCatalog
|
171
|
+
#The study will contain variable level information if available
|
172
|
+
#
|
173
|
+
#Returns a Nesstar::Study object
|
174
|
+
def get_study_information uri, dataset_id
|
141
175
|
#TODO use the get_ddi method above
|
142
176
|
ddi_uri = URI.parse(uri)
|
143
|
-
ddi_uri.merge!("/obj/fStudy/" +
|
177
|
+
ddi_uri.merge!("/obj/fStudy/" + dataset_id)
|
144
178
|
ddi_uri.merge!('?http://www.nesstar.org/rdf/method=http://www.nesstar.org/rdf/Dataset/GetDDI')
|
145
179
|
res = Net::HTTP.get(ddi_uri)
|
146
180
|
gz = Zlib::GzipReader.new(StringIO.new(res))
|
147
181
|
xml = gz.read
|
148
182
|
catalog = Nesstar::Catalog.new
|
149
183
|
study = Nesstar::Study.new
|
184
|
+
study.nesstar_id = dataset_id
|
185
|
+
study.nesstar_uri = uri
|
150
186
|
study_info_hash = Hash.new
|
151
187
|
parser = LibXML::XML::Parser.string(xml)
|
152
188
|
doc = parser.parse
|
@@ -308,10 +344,17 @@ module Nesstar
|
|
308
344
|
#categories in ddi are value domains in mb
|
309
345
|
catgry.each do |cat|
|
310
346
|
category = Nesstar::Category.new
|
311
|
-
|
347
|
+
valxml = cat.find('./catValu')
|
348
|
+
if valxml != nil && valxml[0] != nil
|
349
|
+
category.value = valxml[0].first.content.strip unless valxml[0].first == nil
|
350
|
+
else
|
351
|
+
category.value = 'N/A'
|
352
|
+
end
|
312
353
|
labxml = cat.find('./labl')
|
313
354
|
if labxml != nil && labxml[0] != nil
|
314
355
|
category.label = labxml[0].first.content.strip unless labxml[0].first == nil
|
356
|
+
else
|
357
|
+
category.label = 'N/A'
|
315
358
|
end
|
316
359
|
catstat = cat.find('./catStat')
|
317
360
|
category_statistics = []
|
@@ -321,12 +364,11 @@ module Nesstar
|
|
321
364
|
if a != nil
|
322
365
|
category_statistic.type = a.get_attribute('type').strip unless a.get_attribute('type') == nil
|
323
366
|
category_statistic.value = catstat.first.content.strip unless catstat.first == nil
|
324
|
-
category_statistic.type = a.get_attribute('type').strip unless a.get_attribute('type') == nil
|
325
367
|
category_statistics.push(category_statistic)
|
326
368
|
end
|
327
369
|
end
|
328
370
|
category.category_statistics = category_statistics
|
329
|
-
categories.push(
|
371
|
+
categories.push(category)
|
330
372
|
end
|
331
373
|
#what group is the variable in
|
332
374
|
variable_info_hash.each_key do |key|
|
data/lib/nesstar-api/catalog.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Nesstar
|
2
|
-
|
2
|
+
#A Nesstar catalog object, can contain 1 or more studies (ie datasets)
|
3
3
|
class Catalog
|
4
4
|
|
5
|
-
attr_reader :studies, :label, :description
|
6
|
-
attr_writer :studies, :label, :description
|
5
|
+
attr_reader :studies, :label, :description, :nesstar_id, :nesstar_uri
|
6
|
+
attr_writer :studies, :label, :description, :nesstar_id, :nesstar_uri
|
7
7
|
|
8
8
|
end
|
9
9
|
|
data/lib/nesstar-api/study.rb
CHANGED
@@ -3,8 +3,8 @@ module Nesstar
|
|
3
3
|
#Contains a set of variables and belongs to a catalog
|
4
4
|
class Study
|
5
5
|
|
6
|
-
attr_reader :variables, :abstract, :title, :id, :dates, :sampling_procedure, :weight
|
7
|
-
attr_writer :variables, :abstract, :title, :id, :dates, :sampling_procedure, :weight
|
6
|
+
attr_reader :variables, :abstract, :title, :id, :dates, :sampling_procedure, :weight, :nesstar_id, :nesstar_uri
|
7
|
+
attr_writer :variables, :abstract, :title, :id, :dates, :sampling_procedure, :weight, :nesstar_id, :nesstar_uri
|
8
8
|
|
9
9
|
end
|
10
10
|
|
data/lib/nesstar-api/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nesstar-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ian Dunlop
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-09 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|