rbbt-rest 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rbbt/rest/common/cache.rb +34 -31
- data/lib/rbbt/rest/common/table.rb +1 -0
- data/lib/rbbt/rest/entity.rb +4 -2
- data/lib/rbbt/rest/entity/favourites.rb +1 -1
- data/lib/rbbt/rest/entity/rest.rb +5 -1
- data/lib/rbbt/rest/knowledge_base.rb +318 -286
- data/lib/rbbt/rest/knowledge_base/helpers.rb +11 -0
- data/share/views/compass/base/colors.sass +1 -0
- data/share/views/compass/base/variables/color.sass +1 -1
- data/share/views/entity_partials/list_container.haml +6 -3
- data/share/views/help.haml +1 -1
- data/share/views/help/workflow.haml +1 -1
- data/share/views/job_result/job_control.haml +3 -3
- data/share/views/layout/coda.haml +2 -2
- data/share/views/public/js/app.js +12 -2
- data/share/views/public/js/rbbt/favourites.js +1 -6
- data/share/views/public/js/rbbt/map.js +1 -0
- data/share/views/public/plugins/angular/angular.js +26253 -248
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 019b238df0884dac2b1bd0c4c97588d9c0ddf295
|
4
|
+
data.tar.gz: dbb37b58e7d10dc8a2fd82e4636eb006427733fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3645c2891ebaf8ccbfd1afd8a938b3b2e1a186fe3f6115b53cd62d978337293da74524065d9d25624e96207b5adecea1f70f90d1bac2bda4a157f2c9b2d91b8e
|
7
|
+
data.tar.gz: 5eb156ff821ac00db1b6ddd0949ff4e7f9e85e2161e97b1a52cf408ad4f27baab472b463b972a2775764ba7da67b58d77c81651e58b4fa9db0c9776d7ad08a8d
|
@@ -41,6 +41,36 @@ module RbbtRESTHelpers
|
|
41
41
|
send_file step.file(@file), :filename => @file
|
42
42
|
end
|
43
43
|
|
44
|
+
# Clean/update job
|
45
|
+
|
46
|
+
if old_cache(step.path, check) or update == :reload
|
47
|
+
begin
|
48
|
+
pid = step.info[:pid]
|
49
|
+
step.abort if pid and Misc.pid_exists?(pid) and not pid == Process.pid
|
50
|
+
step.pid = nil
|
51
|
+
rescue Exception
|
52
|
+
Log.medium{$!.message}
|
53
|
+
end
|
54
|
+
step.clean
|
55
|
+
end
|
56
|
+
|
57
|
+
clean_url = request.url
|
58
|
+
clean_url = remove_GET_param(clean_url, :_update)
|
59
|
+
clean_url = remove_GET_param(clean_url, :_)
|
60
|
+
|
61
|
+
class << step; def url; @url; end; end
|
62
|
+
step.instance_variable_set(:@url, clean_url)
|
63
|
+
|
64
|
+
# Issue
|
65
|
+
if not step.started?
|
66
|
+
if cache_type == :synchronous or cache_type == :sync
|
67
|
+
step.run
|
68
|
+
else
|
69
|
+
step.fork
|
70
|
+
step.soft_grace
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
44
74
|
# Return fragment
|
45
75
|
|
46
76
|
if @fragment
|
@@ -68,7 +98,9 @@ module RbbtRESTHelpers
|
|
68
98
|
list_id << " (#{ @filter })" if @filter
|
69
99
|
Entity::List.save_list(type.to_s, list_id, list, user)
|
70
100
|
header "Location", Entity::REST.entity_list_url(list_id, type)
|
71
|
-
|
101
|
+
url = Entity::REST.entity_list_url(list_id, type)
|
102
|
+
url = url + '?_layout=false' unless @layout
|
103
|
+
redirect to(url)
|
72
104
|
when "map"
|
73
105
|
tsv = tsv_process(load_tsv(fragment_file).first)
|
74
106
|
type = tsv.keys.annotation_types.last
|
@@ -77,6 +109,7 @@ module RbbtRESTHelpers
|
|
77
109
|
map_id << " (#{ @filter.gsub(';','|') })" if @filter
|
78
110
|
Entity::Map.save_map(type.to_s, column, map_id, tsv, user)
|
79
111
|
url = Entity::REST.entity_map_url(map_id, type, column)
|
112
|
+
url = url + '?_layout=false' unless @layout
|
80
113
|
redirect to(url)
|
81
114
|
when "excel"
|
82
115
|
require 'rbbt/tsv/excel'
|
@@ -101,36 +134,6 @@ module RbbtRESTHelpers
|
|
101
134
|
end
|
102
135
|
end
|
103
136
|
|
104
|
-
# Clean/update job
|
105
|
-
|
106
|
-
if old_cache(step.path, check) or update == :reload
|
107
|
-
begin
|
108
|
-
pid = step.info[:pid]
|
109
|
-
step.abort if pid and Misc.pid_exists?(pid) and not pid == Process.pid
|
110
|
-
step.pid = nil
|
111
|
-
rescue Exception
|
112
|
-
Log.medium{$!.message}
|
113
|
-
end
|
114
|
-
step.clean
|
115
|
-
end
|
116
|
-
|
117
|
-
clean_url = request.url
|
118
|
-
clean_url = remove_GET_param(clean_url, :_update)
|
119
|
-
clean_url = remove_GET_param(clean_url, :_)
|
120
|
-
|
121
|
-
class << step; def url; @url; end; end
|
122
|
-
step.instance_variable_set(:@url, clean_url)
|
123
|
-
|
124
|
-
# Issue
|
125
|
-
if not step.started?
|
126
|
-
if cache_type == :synchronous or cache_type == :sync
|
127
|
-
step.run
|
128
|
-
else
|
129
|
-
step.fork
|
130
|
-
step.soft_grace
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
137
|
if update == :reload
|
135
138
|
redirect to(clean_url)
|
136
139
|
end
|
data/lib/rbbt/rest/entity.rb
CHANGED
@@ -305,7 +305,8 @@ module Sinatra
|
|
305
305
|
when :name
|
306
306
|
file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, user)
|
307
307
|
file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, nil) unless File.exists? file
|
308
|
-
new = TSVWorkflow.job(:
|
308
|
+
#new = TSVWorkflow.job(:swap_id, "Map #{ map_id }", :format => "Associated Gene Name", :tsv => TSV.open(file)).exec
|
309
|
+
new = TSV.open(file).change_key "Associated Gene Name"
|
309
310
|
new_id = map_id << " [Names]"
|
310
311
|
Entity::Map.save_map(entity_type, column, new_id, new, user)
|
311
312
|
redirect to(Entity::REST.entity_map_url(new_id, entity_type, column))
|
@@ -484,7 +485,8 @@ module Sinatra
|
|
484
485
|
next unless entity.respond_to? :link
|
485
486
|
info = entity.info
|
486
487
|
info.delete :annotation_types
|
487
|
-
|
488
|
+
default = entity.respond_to?(:default) ? entity.default || entity.to_s : entity.to_s
|
489
|
+
type_favs[entity] = {:info => info, :link => entity.link, :code => entity, :id => default, :name => (entity.respond_to?(:name) ? entity.name || entity : entity) }
|
488
490
|
end
|
489
491
|
favs[type] = type_favs
|
490
492
|
}
|
@@ -139,7 +139,7 @@ module EntityRESTHelpers
|
|
139
139
|
|
140
140
|
dir = Path.setup(File.join(settings.favourite_maps_dir, user))
|
141
141
|
|
142
|
-
if (file = dir[entity_type][column]).exists?
|
142
|
+
if (file = dir[entity_type][column].find).exists?
|
143
143
|
maps = Open.read(file).split("\n")
|
144
144
|
maps -= [map]
|
145
145
|
if maps.any?
|
@@ -131,6 +131,10 @@ module Entity
|
|
131
131
|
attributes[:href] = Entity::REST.entity_url(self, entity_type.to_s, link_params)
|
132
132
|
attributes["attr-entity_id"] = self.to_s
|
133
133
|
|
134
|
+
attributes["data-entity-type"] = self.base_type
|
135
|
+
attributes["data-entity"] = self.to_s
|
136
|
+
attributes["data-entity-id"] = self.respond_to?(:default)? self.default || self.to_s : self.to_s
|
137
|
+
|
134
138
|
begin
|
135
139
|
text = self.respond_to?(:name)? self.name || self : self if text.nil?
|
136
140
|
rescue
|
@@ -191,8 +195,8 @@ module Entity
|
|
191
195
|
end
|
192
196
|
|
193
197
|
def list_action_link(action, text = nil, id = nil, options = {})
|
194
|
-
text = [id, action] * "→" if text.nil? or (String === text and text.strip.empty?)
|
195
198
|
id = options[:id] || Misc.digest((self * "|").inspect) if id.nil? or (String === id and id.empty?)
|
199
|
+
text = [id, action] * "→" if text.nil? or (String === text and text.strip.empty?)
|
196
200
|
|
197
201
|
reuse = options.delete(:reuse)
|
198
202
|
reuse = options.delete("reuse") if reuse.nil?
|
@@ -111,344 +111,376 @@ module Sinatra
|
|
111
111
|
else
|
112
112
|
content_type :text
|
113
113
|
halt 200, subset.source * "\n"
|
114
|
-
|
115
|
-
|
114
|
+
end
|
115
|
+
end
|
116
116
|
|
117
117
|
|
118
|
-
|
118
|
+
#{{{ Collection
|
119
119
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
120
|
+
post '/knowledge_base/:name/:database/collection_children' do
|
121
|
+
name = consume_parameter :name
|
122
|
+
database = consume_parameter :database
|
123
|
+
collection = consume_parameter :collection
|
124
|
+
raise ParameterException, "No collection specified" if collection.nil?
|
125
|
+
collection = JSON.parse(collection)
|
126
126
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
127
|
+
kb = get_knowledge_base name
|
128
|
+
matches = collection.keys.inject({}){|acc,type|
|
129
|
+
entities = collection[type]
|
130
|
+
entities.each do |entity|
|
131
|
+
_matches = kb.children(database, entity)
|
132
|
+
acc.merge!({ _matches.target_type => _matches}) if _matches and _matches.any?
|
133
|
+
end
|
134
|
+
acc
|
135
|
+
}
|
136
|
+
case @format
|
137
|
+
when :tsv
|
138
|
+
content_type "text/tab-separated-values"
|
139
|
+
matches = matches.sort_by{|k,list| list.length }.last.last
|
140
|
+
halt 200, matches.tsv.to_s
|
141
|
+
when :html
|
142
|
+
template_render('knowledge_base_partials/matches', {:matches => matches}, "Collection Children: #{ [name, database] }")
|
143
|
+
when :json
|
144
|
+
content_type :json
|
145
|
+
_matches = {}
|
146
|
+
matches.each{|type,list|
|
147
|
+
_matches[type] = list.target
|
148
|
+
}
|
149
|
+
halt 200, _matches.to_json
|
150
|
+
else
|
151
|
+
content_type :text
|
152
|
+
matches = matches.sort_by{|k,list| list.length }.last.last
|
153
|
+
halt 200, matches.target * "\n"
|
154
|
+
end
|
155
|
+
end
|
156
156
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
157
|
+
post '/knowledge_base/:name/:database/collection_parents' do
|
158
|
+
name = consume_parameter :name
|
159
|
+
database = consume_parameter :database
|
160
|
+
collection = consume_parameter :collection
|
161
|
+
raise ParameterException, "No collection specified" if collection.nil?
|
162
|
+
collection = JSON.parse(collection)
|
163
|
+
|
164
|
+
kb = get_knowledge_base name
|
165
|
+
matches = collection.keys.inject({}){|acc,type|
|
166
|
+
entities = collection[type]
|
167
|
+
entities.each do |entity|
|
168
|
+
_matches = kb.parents(database, entity)
|
169
|
+
acc.merge!({ _matches.target_type => _matches}) if _matches and _matches.any?
|
170
|
+
end
|
171
|
+
acc
|
172
|
+
}
|
173
|
+
case @format
|
174
|
+
when :tsv
|
175
|
+
content_type "text/tab-separated-values"
|
176
|
+
matches = matches.sort_by{|k,list| list.length }.last.last
|
177
|
+
halt 200, matches.tsv.to_s
|
178
|
+
when :html
|
179
|
+
template_render('knowledge_base_partials/matches', {:matches => matches}, "Collection Parents: #{ [name, database] }")
|
180
|
+
when :json
|
181
|
+
content_type :json
|
182
|
+
_matches = {}
|
183
|
+
matches.each{|type,list|
|
184
|
+
_matches[type] = list.target
|
185
|
+
}
|
186
|
+
halt 200, _matches.to_json
|
187
|
+
else
|
188
|
+
content_type :text
|
189
|
+
matches = matches.sort_by{|k,list| list.length }.last.last
|
190
|
+
halt 200, matches.target * "\n"
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
post '/knowledge_base/:name/:database/collection_neighbours' do
|
195
|
+
name = consume_parameter :name
|
196
|
+
database = consume_parameter :database
|
197
|
+
collection = consume_parameter :collection
|
198
|
+
raise ParameterException, "No collection specified" if collection.nil?
|
199
|
+
collection = JSON.parse(collection)
|
193
200
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
201
|
+
kb = get_knowledge_base name
|
202
|
+
matches = collection.keys.inject({}){|acc,type|
|
203
|
+
entities = collection[type]
|
204
|
+
entities.each do |entity|
|
205
|
+
_matches_h = kb.neighbours(database, entity)
|
206
|
+
_matches_h.each do |key, _matches|
|
207
|
+
target_type = _matches.target_entity_type
|
208
|
+
|
209
|
+
_matches = acc[target_type].concat _matches if acc[target_type] and acc[target_type].any?
|
210
|
+
|
211
|
+
acc.merge!({ target_type => _matches }) if _matches and _matches.any?
|
212
|
+
end
|
213
|
+
end
|
214
|
+
acc
|
215
|
+
}
|
216
|
+
|
217
|
+
@format ||= :json
|
218
|
+
case @format
|
219
|
+
when :tsv
|
220
|
+
content_type "text/tab-separated-values"
|
221
|
+
matches = matches.sort_by{|k,list| list.length }.last.last
|
222
|
+
halt 200, matches.tsv.to_s
|
223
|
+
when :html
|
224
|
+
template_render('knowledge_base_partials/matches', {:matches => matches}, "Collection Parents: #{ [name, database] }")
|
225
|
+
when :json
|
226
|
+
content_type :json
|
227
|
+
_matches = {}
|
228
|
+
matches.each{|type,list|
|
229
|
+
_matches[type] = list.target.uniq.sort
|
230
|
+
}
|
231
|
+
halt 200, _matches.to_json
|
232
|
+
else
|
233
|
+
content_type :text
|
234
|
+
matches = matches.sort_by{|k,list| list.length }.last.last
|
235
|
+
halt 200, matches.target * "\n"
|
236
|
+
end
|
237
|
+
end
|
200
238
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
_matches_h.each do |key, _matches|
|
207
|
-
target_type = _matches.target_entity_type
|
239
|
+
get '/knowledge_base/:name/:database/subset' do
|
240
|
+
name = consume_parameter :name
|
241
|
+
database = consume_parameter :database
|
242
|
+
source = consume_parameter :source
|
243
|
+
target = consume_parameter :target
|
208
244
|
|
209
|
-
|
245
|
+
source = source == "all" ? :all : source.split(@array_separator) if source
|
246
|
+
target = target == "all" ? :all : target.split(@array_separator) if target
|
247
|
+
entities = { :source => source, :target => target }
|
210
248
|
|
211
|
-
|
249
|
+
kb = get_knowledge_base name
|
250
|
+
subset = kb.subset(database, entities)
|
251
|
+
case @format
|
252
|
+
when :tsv
|
253
|
+
content_type "text/tab-separated-values"
|
254
|
+
halt 200, subset.tsv.to_s
|
255
|
+
when :html
|
256
|
+
template_render('knowledge_base_partials/subset', {:subset => subset}, "Subset: #{ [name, database] }")
|
257
|
+
when :json
|
258
|
+
content_type :json
|
259
|
+
halt 200, subset.source.to_json
|
260
|
+
else
|
261
|
+
content_type :text
|
262
|
+
halt 200, subset.source * "\n"
|
263
|
+
end
|
212
264
|
end
|
213
|
-
end
|
214
|
-
acc
|
215
|
-
}
|
216
|
-
|
217
|
-
@format ||= :json
|
218
|
-
case @format
|
219
|
-
when :tsv
|
220
|
-
content_type "text/tab-separated-values"
|
221
|
-
matches = matches.sort_by{|k,list| list.length }.last.last
|
222
|
-
halt 200, matches.tsv.to_s
|
223
|
-
when :html
|
224
|
-
template_render('knowledge_base_partials/matches', {:matches => matches}, "Collection Parents: #{ [name, database] }")
|
225
|
-
when :json
|
226
|
-
content_type :json
|
227
|
-
_matches = {}
|
228
|
-
matches.each{|type,list|
|
229
|
-
_matches[type] = list.target.uniq.sort
|
230
|
-
}
|
231
|
-
halt 200, _matches.to_json
|
232
|
-
else
|
233
|
-
content_type :text
|
234
|
-
matches = matches.sort_by{|k,list| list.length }.last.last
|
235
|
-
halt 200, matches.target * "\n"
|
236
|
-
end
|
237
|
-
end
|
238
265
|
|
239
|
-
|
240
|
-
name = consume_parameter :name
|
241
|
-
database = consume_parameter :database
|
242
|
-
source = consume_parameter :source
|
243
|
-
target = consume_parameter :target
|
244
|
-
|
245
|
-
source = source == "all" ? :all : source.split(@array_separator) if source
|
246
|
-
target = target == "all" ? :all : target.split(@array_separator) if target
|
247
|
-
entities = { :source => source, :target => target }
|
248
|
-
|
249
|
-
kb = get_knowledge_base name
|
250
|
-
subset = kb.subset(database, entities)
|
251
|
-
case @format
|
252
|
-
when :tsv
|
253
|
-
content_type "text/tab-separated-values"
|
254
|
-
halt 200, subset.tsv.to_s
|
255
|
-
when :html
|
256
|
-
template_render('knowledge_base_partials/subset', {:subset => subset}, "Subset: #{ [name, database] }")
|
257
|
-
when :json
|
258
|
-
content_type :json
|
259
|
-
halt 200, subset.source.to_json
|
260
|
-
else
|
261
|
-
content_type :text
|
262
|
-
halt 200, subset.source * "\n"
|
263
|
-
end
|
264
|
-
end
|
266
|
+
#{{{ Info
|
265
267
|
|
266
|
-
|
268
|
+
get '/knowledge_base/info/:name/:database/:pair' do
|
269
|
+
name = consume_parameter :name
|
270
|
+
database = consume_parameter :database
|
271
|
+
pair = consume_parameter :pair
|
267
272
|
|
268
|
-
|
269
|
-
|
270
|
-
database = consume_parameter :database
|
271
|
-
pair = consume_parameter :pair
|
273
|
+
kb = get_knowledge_base name
|
274
|
+
index = kb.get_index(database)
|
272
275
|
|
273
|
-
|
274
|
-
|
276
|
+
AssociationItem.setup(pair, kb, database, false)
|
277
|
+
template_render('knowledge_base_partials/association', {:pair => pair, :kb => kb, :index => index, :database => database}, "Association: #{ pair } #{[name, database] * ":"}", :cache_type => :async)
|
278
|
+
end
|
275
279
|
|
276
|
-
|
277
|
-
template_render('knowledge_base_partials/association', {:pair => pair, :kb => kb, :index => index, :database => database}, "Association: #{ pair } #{[name, database] * ":"}", :cache_type => :async)
|
278
|
-
end
|
280
|
+
#{{{ Children
|
279
281
|
|
280
|
-
|
282
|
+
get '/knowledge_base/:name/:database/entity_children/:entity' do
|
283
|
+
name = consume_parameter :name
|
284
|
+
database = consume_parameter :database
|
285
|
+
entity = consume_parameter :entity
|
281
286
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
entity = consume_parameter :entity
|
287
|
+
kb = get_knowledge_base name
|
288
|
+
found = kb.identify database, entity
|
289
|
+
raise ParameterException, "Entity #{entity} was not found" unless found
|
286
290
|
|
287
|
-
|
288
|
-
found = kb.identify database, entity
|
289
|
-
raise ParameterException, "Entity #{entity} was not found" unless found
|
291
|
+
list = kb.children(database, found).target_entity
|
290
292
|
|
291
|
-
|
293
|
+
case @format
|
294
|
+
when :json
|
295
|
+
content_type "application/json"
|
296
|
+
halt 200, prepare_entities_for_json(list).to_json
|
297
|
+
when :html
|
298
|
+
end
|
299
|
+
end
|
292
300
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
end
|
299
|
-
end
|
301
|
+
# List children
|
302
|
+
post '/knowledge_base/:name/:database/entity_list_children/' do
|
303
|
+
name = consume_parameter :name
|
304
|
+
database = consume_parameter :database
|
305
|
+
entities = consume_parameter :entities
|
300
306
|
|
301
|
-
|
302
|
-
post '/knowledge_base/:name/:database/entity_list_children/' do
|
303
|
-
name = consume_parameter :name
|
304
|
-
database = consume_parameter :database
|
305
|
-
entities = consume_parameter :entities
|
307
|
+
raise ParameterException, "No 'entities' provided" if entities.nil?
|
306
308
|
|
307
|
-
|
309
|
+
entities = entities.split("|")
|
308
310
|
|
309
|
-
|
311
|
+
kb = get_knowledge_base name
|
310
312
|
|
311
|
-
|
313
|
+
children = {}
|
314
|
+
entities.each do |entity|
|
315
|
+
found = kb.identify database, entity
|
316
|
+
next if found.nil?
|
317
|
+
children[entity] = kb.children(database, found).target_entity
|
318
|
+
end
|
319
|
+
case @format
|
320
|
+
when :json
|
321
|
+
content_type "application/json"
|
322
|
+
halt 200, prepare_entities_for_json(children).to_json
|
323
|
+
when :html
|
324
|
+
end
|
325
|
+
end
|
312
326
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
end
|
319
|
-
case @format
|
320
|
-
when :json
|
321
|
-
content_type "application/json"
|
322
|
-
halt 200, prepare_entities_for_json(children).to_json
|
323
|
-
when :html
|
324
|
-
end
|
325
|
-
end
|
327
|
+
# Collection children
|
328
|
+
post '/knowledge_base/:name/:database/entity_collection_children' do
|
329
|
+
name = consume_parameter :name
|
330
|
+
database = consume_parameter :database
|
331
|
+
entities = consume_parameter :entities
|
326
332
|
|
327
|
-
|
328
|
-
post '/knowledge_base/:name/:database/entity_collection_children' do
|
329
|
-
name = consume_parameter :name
|
330
|
-
database = consume_parameter :database
|
331
|
-
entities = consume_parameter :entities
|
333
|
+
raise ParameterException, "No 'entities' provided" if entities.nil?
|
332
334
|
|
333
|
-
|
335
|
+
entities = JSON.parse(entities)
|
334
336
|
|
335
|
-
|
337
|
+
kb = get_knowledge_base name
|
336
338
|
|
337
|
-
|
339
|
+
entities.each do |type,list|
|
340
|
+
list.each do |entity|
|
341
|
+
found = kb.identify database, entity
|
342
|
+
next if found.nil?
|
343
|
+
targets = kb.children(database, found).target_entity
|
344
|
+
next if targets.nil? or targets.empty?
|
345
|
+
target_type = kb.target database
|
346
|
+
children[target_type] ||= []
|
347
|
+
children[target_type].concat targets
|
348
|
+
end
|
349
|
+
end
|
338
350
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
children[target_type] ||= []
|
347
|
-
children[target_type].concat targets
|
348
|
-
end
|
349
|
-
end
|
351
|
+
case @format
|
352
|
+
when :json
|
353
|
+
content_type "application/json"
|
354
|
+
halt 200, prepare_entities_for_json(children).to_json
|
355
|
+
when :html
|
356
|
+
end
|
357
|
+
end
|
350
358
|
|
351
|
-
|
352
|
-
when :json
|
353
|
-
content_type "application/json"
|
354
|
-
halt 200, prepare_entities_for_json(children).to_json
|
355
|
-
when :html
|
356
|
-
end
|
357
|
-
end
|
359
|
+
#{{{ Neighbours
|
358
360
|
|
359
|
-
|
361
|
+
get '/knowledge_base/:name/:database/entity_neighbours/:entity' do
|
362
|
+
name = consume_parameter :name
|
363
|
+
database = consume_parameter :database
|
364
|
+
entity = consume_parameter :entity
|
360
365
|
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
entity = consume_parameter :entity
|
366
|
+
kb = get_knowledge_base name
|
367
|
+
found = kb.identify database, entity
|
368
|
+
raise ParameterException, "Entity #{entity} was not found" unless found
|
365
369
|
|
366
|
-
|
367
|
-
|
368
|
-
|
370
|
+
list = kb.neighbours(database, found).values.select{|list| list and list.any?}.first
|
371
|
+
list = list.target_entity if list.respond_to? :target_entity
|
372
|
+
list ||= []
|
369
373
|
|
370
|
-
|
371
|
-
|
372
|
-
|
374
|
+
case @format
|
375
|
+
when :json
|
376
|
+
content_type "application/json"
|
377
|
+
halt 200, prepare_entities_for_json(list).to_json
|
378
|
+
when :html
|
379
|
+
end
|
380
|
+
end
|
373
381
|
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
when :html
|
379
|
-
end
|
380
|
-
end
|
382
|
+
post '/knowledge_base/:name/:database/entity_list_neighbours/' do
|
383
|
+
name = consume_parameter :name
|
384
|
+
database = consume_parameter :database
|
385
|
+
entities = consume_parameter :entities
|
381
386
|
|
382
|
-
|
383
|
-
name = consume_parameter :name
|
384
|
-
database = consume_parameter :database
|
385
|
-
entities = consume_parameter :entities
|
387
|
+
raise ParameterException, "No 'entities' provided" if entities.nil?
|
386
388
|
|
387
|
-
|
389
|
+
entities = entities.split("|")
|
388
390
|
|
389
|
-
|
391
|
+
kb = get_knowledge_base name
|
390
392
|
|
391
|
-
|
393
|
+
children = {}
|
394
|
+
entities.each do |entity|
|
395
|
+
found = kb.identify database, entity
|
396
|
+
next if found.nil?
|
397
|
+
matches = kb.neighbours(database, found).values.select{|list| list and list.any?}.first
|
398
|
+
next if matches.nil? or matches.empty?
|
399
|
+
children[entity] = matches.target_entity
|
400
|
+
end
|
401
|
+
case @format
|
402
|
+
when :json
|
403
|
+
content_type "application/json"
|
404
|
+
halt 200, prepare_entities_for_json(children).to_json
|
405
|
+
when :html
|
406
|
+
end
|
407
|
+
end
|
392
408
|
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
matches = kb.neighbours(database, found).values.select{|list| list and list.any?}.first
|
398
|
-
next if matches.nil? or matches.empty?
|
399
|
-
children[entity] = matches.target_entity
|
400
|
-
end
|
401
|
-
case @format
|
402
|
-
when :json
|
403
|
-
content_type "application/json"
|
404
|
-
halt 200, prepare_entities_for_json(children).to_json
|
405
|
-
when :html
|
406
|
-
end
|
407
|
-
end
|
409
|
+
post '/knowledge_base/:name/:database/entity_collection_neighbours' do
|
410
|
+
name = consume_parameter :name
|
411
|
+
database = consume_parameter :database
|
412
|
+
entities = consume_parameter :entities
|
408
413
|
|
409
|
-
|
410
|
-
name = consume_parameter :name
|
411
|
-
database = consume_parameter :database
|
412
|
-
entities = consume_parameter :entities
|
414
|
+
raise ParameterException, "No 'entities' provided" if entities.nil?
|
413
415
|
|
414
|
-
|
416
|
+
entities = JSON.parse(entities)
|
415
417
|
|
416
|
-
|
418
|
+
kb = get_knowledge_base name
|
417
419
|
|
418
|
-
|
420
|
+
neighbours = {}
|
421
|
+
entities.each do |type,list|
|
422
|
+
list.each do |entity|
|
423
|
+
|
424
|
+
found = kb.identify_source database, entity
|
425
|
+
if found.nil?
|
426
|
+
reverse = true
|
427
|
+
found = kb.identify_target database, entity
|
428
|
+
else
|
429
|
+
reverse = false
|
430
|
+
end
|
431
|
+
next if found.nil?
|
432
|
+
|
433
|
+
matches = kb.neighbours(database, found)[reverse ? :parents : :children]
|
434
|
+
next if matches.nil? or matches.empty?
|
435
|
+
targets = matches.target
|
436
|
+
|
437
|
+
entity_type = reverse ? kb.source_type(database) : kb.target_type(database)
|
438
|
+
neighbours[entity_type] ||= []
|
439
|
+
neighbours[entity_type].concat targets
|
440
|
+
end
|
441
|
+
end
|
419
442
|
|
420
|
-
|
421
|
-
entities.each do |type,list|
|
422
|
-
list.each do |entity|
|
443
|
+
neighbours.each{|type, list| list.uniq!}
|
423
444
|
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
445
|
+
case @format
|
446
|
+
when :json
|
447
|
+
content_type "application/json"
|
448
|
+
halt 200, prepare_entities_for_json(neighbours).to_json
|
449
|
+
when :html
|
450
|
+
end
|
430
451
|
end
|
431
|
-
next if found.nil?
|
432
452
|
|
433
|
-
|
434
|
-
|
435
|
-
|
453
|
+
get '/kb/:name/:database/children/:entity' do
|
454
|
+
name = consume_parameter :name
|
455
|
+
database = consume_parameter :database
|
456
|
+
entity = consume_parameter :entity
|
436
457
|
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
end
|
441
|
-
end
|
458
|
+
kb = get_knowledge_base name
|
459
|
+
found = kb.identify database, entity
|
460
|
+
raise ParameterException, "Entity #{entity} was not found" unless found
|
442
461
|
|
443
|
-
|
462
|
+
iii kb.children(database, found)
|
463
|
+
list = kb.children(database, found).target_entity
|
444
464
|
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
465
|
+
content_type "application/json"
|
466
|
+
halt 200, serialize_entities(list).to_json
|
467
|
+
end
|
468
|
+
|
469
|
+
get '/kb/:name/:database/parents/:entity' do
|
470
|
+
name = consume_parameter :name
|
471
|
+
database = consume_parameter :database
|
472
|
+
entity = consume_parameter :entity
|
473
|
+
|
474
|
+
kb = get_knowledge_base name
|
475
|
+
found = kb.identify database, entity
|
476
|
+
raise ParameterException, "Entity #{entity} was not found" unless found
|
477
|
+
|
478
|
+
iii kb.parents(database, found)
|
479
|
+
list = kb.parents(database, found).target_entity
|
480
|
+
|
481
|
+
content_type "application/json"
|
482
|
+
halt 200, serialize_entities(list).to_json
|
483
|
+
end
|
452
484
|
end
|
453
485
|
end
|
454
486
|
end
|