rbbt-rest 1.4.1 → 1.4.2
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/entity.rb +0 -2
- data/lib/rbbt/rest/entity/list.rb +7 -4
- data/lib/rbbt/rest/knowledge_base.rb +441 -439
- data/lib/rbbt/rest/knowledge_base/helpers.rb +0 -62
- data/lib/rbbt/rest/knowledge_base/query.rb +442 -0
- data/lib/rbbt/rest/main.rb +4 -1
- data/share/views/compass/finder.sass +1 -1
- data/share/views/compass/grid_system.sass +9 -12
- data/share/views/compass/rbbt/menu.sass +2 -1
- data/share/views/public/js/deffer.js +15 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8d9b16fc1e559f1ea8bcf38a58768634327f9c1
|
4
|
+
data.tar.gz: c7c9548194b885e097a8d2429ef0ab846939c3f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d108573834a36a21719721c7b7d87bef951a34f4671d01aa59aa054a8a892489c90ae3ef90537271586e84da45092175851b4ca5cdf5ad83736e006cf7bbc1b
|
7
|
+
data.tar.gz: 6637db025c1ce3f51b2c48974ee6dd5a2153944d3aeb85609b0d52a8610eb3e3e85a0b8dda02f9f03e9bad3d8e41159f0152aed4b36a04a56147406a93af1f29
|
data/lib/rbbt/rest/entity.rb
CHANGED
@@ -7,7 +7,7 @@ module Entity
|
|
7
7
|
attr_accessor :entity_list_cache
|
8
8
|
end
|
9
9
|
|
10
|
-
self.entity_list_cache = "var/entity_list"
|
10
|
+
self.entity_list_cache = Path.setup("var/entity_list")
|
11
11
|
|
12
12
|
module List
|
13
13
|
|
@@ -20,12 +20,12 @@ module Entity
|
|
20
20
|
raise "Ilegal list id: #{ id }" unless Misc.path_relative_to Entity.entity_list_cache, File.join(Entity.entity_list_cache, id)
|
21
21
|
|
22
22
|
path = if user.nil?
|
23
|
-
|
23
|
+
Entity.entity_list_cache[entity_type.to_s][id]
|
24
24
|
else
|
25
|
-
|
25
|
+
Entity.entity_list_cache[entity_type.to_s][user.to_s][id]
|
26
26
|
end
|
27
27
|
|
28
|
-
path
|
28
|
+
path.exists? ? path.find : nil
|
29
29
|
end
|
30
30
|
|
31
31
|
def self.list_files(user = nil)
|
@@ -60,6 +60,9 @@ module Entity
|
|
60
60
|
path = list_file(entity_type, id, :public) unless path != nil and File.exists? path
|
61
61
|
path = list_file(entity_type, id) unless path != nil and File.exists? path
|
62
62
|
|
63
|
+
iii path
|
64
|
+
raise "List not found: #{ id }" if path.nil?
|
65
|
+
|
63
66
|
begin
|
64
67
|
list = Annotated.load_tsv TSV.open(path)
|
65
68
|
list.extend AnnotatedArray
|
@@ -3,6 +3,7 @@ require 'rbbt/workflow'
|
|
3
3
|
require 'sinatra/base'
|
4
4
|
|
5
5
|
require 'rbbt/knowledge_base'
|
6
|
+
require 'rbbt/rest/knowledge_base/query'
|
6
7
|
require 'rbbt/rest/knowledge_base/helpers'
|
7
8
|
|
8
9
|
module Sinatra
|
@@ -10,445 +11,446 @@ module Sinatra
|
|
10
11
|
def self.registered(base)
|
11
12
|
base.module_eval do
|
12
13
|
helpers KnowledgeBaseRESTHelpers
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
|
116
|
-
#
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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
|
-
end
|
154
|
-
|
155
|
-
|
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
|
-
end
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
end
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
end
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
#
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
end
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
end
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
end
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
end
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
end
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
end
|
14
|
+
use KnowledgeBaseRESTQuery
|
15
|
+
|
16
|
+
##{{{ Single entity
|
17
|
+
#
|
18
|
+
#get '/knowledge_base/:name/:database/children/:entity' do
|
19
|
+
# name = consume_parameter :name
|
20
|
+
# database = consume_parameter :database
|
21
|
+
# entity = consume_parameter :entity
|
22
|
+
|
23
|
+
# kb = get_knowledge_base name
|
24
|
+
# matches = kb.children(database, entity)
|
25
|
+
# case @format
|
26
|
+
# when :tsv
|
27
|
+
# content_type "text/tab-separated-values"
|
28
|
+
# halt 200, matches.tsv.to_s
|
29
|
+
# when :html
|
30
|
+
# template_render('knowledge_base_partials/matches', {:matches => matches}, "Children: #{ [name, database, entity] }")
|
31
|
+
# when :json
|
32
|
+
# content_type :json
|
33
|
+
# halt 200, matches.target.to_json
|
34
|
+
# else
|
35
|
+
# content_type :text
|
36
|
+
# halt 200, matches.target * "\n"
|
37
|
+
# end
|
38
|
+
#end
|
39
|
+
|
40
|
+
#get '/knowledge_base/:name/:database/parents/:entity' do
|
41
|
+
# name = consume_parameter :name
|
42
|
+
# database = consume_parameter :database
|
43
|
+
# entity = consume_parameter :entity
|
44
|
+
|
45
|
+
# kb = get_knowledge_base name
|
46
|
+
# matches = kb.parents(database, entity)
|
47
|
+
# case @format
|
48
|
+
# when :tsv
|
49
|
+
# content_type "text/tab-separated-values"
|
50
|
+
# halt 200, matches.tsv.to_s
|
51
|
+
# when :html
|
52
|
+
# template_render('knowledge_base_partials/matches', {:matches => matches}, "Parents: #{ [name, database, entity] }")
|
53
|
+
# when :json
|
54
|
+
# content_type :json
|
55
|
+
# halt 200, matches.source.to_json
|
56
|
+
# else
|
57
|
+
# content_type :text
|
58
|
+
# halt 200, matches.source * "\n"
|
59
|
+
# end
|
60
|
+
#end
|
61
|
+
|
62
|
+
#get '/knowledge_base/:name/:database/neighbours/:entity' do
|
63
|
+
# name = consume_parameter :name
|
64
|
+
# database = consume_parameter :database
|
65
|
+
# entity = consume_parameter :entity
|
66
|
+
|
67
|
+
# kb = get_knowledge_base name
|
68
|
+
# neighbours = kb.neighbours(database, entity)
|
69
|
+
# case @format
|
70
|
+
# when :tsv
|
71
|
+
# content_type "text/tab-separated-values"
|
72
|
+
# halt 200, neighbours.values.collect{|m| m.tsv.to_s } * "\n\n"
|
73
|
+
# when :html
|
74
|
+
# template_render('knowledge_base_partials/matches', {:matches => neighbours}, "Neighbours: #{ [name, database, entity] }")
|
75
|
+
# when :json
|
76
|
+
# content_type :json
|
77
|
+
# neighs = {}
|
78
|
+
# neighs[:parents] = neighbours[:parents].source if neighbours[:parents]
|
79
|
+
# neighs[:children] = neighbours[:children].target
|
80
|
+
# halt 200, neighs.to_json
|
81
|
+
# else
|
82
|
+
# content_type :text
|
83
|
+
# neighs = []
|
84
|
+
# neighs.concat neighbours[:parents].source if neighbours[:parents]
|
85
|
+
# neighs.concat neighbours[:children].target
|
86
|
+
# halt 200, neighs * "\n"
|
87
|
+
# end
|
88
|
+
#end
|
89
|
+
|
90
|
+
#get '/knowledge_base/:name/:database/subset' do
|
91
|
+
# name = consume_parameter :name
|
92
|
+
# database = consume_parameter :database
|
93
|
+
# source = consume_parameter :source
|
94
|
+
# target = consume_parameter :target
|
95
|
+
|
96
|
+
# source = source == "all" ? :all : source.split(@array_separator) if source
|
97
|
+
# target = target == "all" ? :all : target.split(@array_separator) if target
|
98
|
+
# entities = { :source => source, :target => target }
|
99
|
+
|
100
|
+
# kb = get_knowledge_base name
|
101
|
+
# subset = kb.subset(database, entities)
|
102
|
+
# case @format
|
103
|
+
# when :tsv
|
104
|
+
# content_type "text/tab-separated-values"
|
105
|
+
# halt 200, subset.tsv.to_s
|
106
|
+
# when :html
|
107
|
+
# template_render('knowledge_base_partials/subset', {:subset => subset}, "Subset: #{ [name, database] }")
|
108
|
+
# when :json
|
109
|
+
# content_type :json
|
110
|
+
# halt 200, subset.source.to_json
|
111
|
+
# else
|
112
|
+
# content_type :text
|
113
|
+
# halt 200, subset.source * "\n"
|
114
|
+
# end
|
115
|
+
#end
|
116
|
+
|
117
|
+
#
|
118
|
+
##{{{ Collection
|
119
|
+
|
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
|
+
|
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
|
+
|
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)
|
200
|
+
|
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 = case key
|
208
|
+
# when :children
|
209
|
+
# _matches.target_entity_type
|
210
|
+
# when :parents
|
211
|
+
# _matches.source_entity_type
|
212
|
+
# end
|
213
|
+
# _matches = acc[target_type].concat _matches if acc[target_type] and acc[target_type].any?
|
214
|
+
# acc.merge!({ target_type => _matches }) if _matches and _matches.any?
|
215
|
+
# end
|
216
|
+
# end
|
217
|
+
# acc
|
218
|
+
# }
|
219
|
+
|
220
|
+
# case @format
|
221
|
+
# when :tsv
|
222
|
+
# content_type "text/tab-separated-values"
|
223
|
+
# matches = matches.sort_by{|k,list| list.length }.last.last
|
224
|
+
# halt 200, matches.tsv.to_s
|
225
|
+
# when :html
|
226
|
+
# template_render('knowledge_base_partials/matches', {:matches => matches}, "Collection Parents: #{ [name, database] }")
|
227
|
+
# when :json
|
228
|
+
# content_type :json
|
229
|
+
# _matches = {}
|
230
|
+
# matches.each{|type,list|
|
231
|
+
# _matches[type] = list.target.uniq.sort
|
232
|
+
# }
|
233
|
+
# halt 200, _matches.to_json
|
234
|
+
# else
|
235
|
+
# content_type :text
|
236
|
+
# matches = matches.sort_by{|k,list| list.length }.last.last
|
237
|
+
# halt 200, matches.target * "\n"
|
238
|
+
# end
|
239
|
+
#end
|
240
|
+
|
241
|
+
#get '/knowledge_base/:name/:database/subset' do
|
242
|
+
# name = consume_parameter :name
|
243
|
+
# database = consume_parameter :database
|
244
|
+
# source = consume_parameter :source
|
245
|
+
# target = consume_parameter :target
|
246
|
+
|
247
|
+
# source = source == "all" ? :all : source.split(@array_separator) if source
|
248
|
+
# target = target == "all" ? :all : target.split(@array_separator) if target
|
249
|
+
# entities = { :source => source, :target => target }
|
250
|
+
|
251
|
+
# kb = get_knowledge_base name
|
252
|
+
# subset = kb.subset(database, entities)
|
253
|
+
# case @format
|
254
|
+
# when :tsv
|
255
|
+
# content_type "text/tab-separated-values"
|
256
|
+
# halt 200, subset.tsv.to_s
|
257
|
+
# when :html
|
258
|
+
# template_render('knowledge_base_partials/subset', {:subset => subset}, "Subset: #{ [name, database] }")
|
259
|
+
# when :json
|
260
|
+
# content_type :json
|
261
|
+
# halt 200, subset.source.to_json
|
262
|
+
# else
|
263
|
+
# content_type :text
|
264
|
+
# halt 200, subset.source * "\n"
|
265
|
+
# end
|
266
|
+
#end
|
267
|
+
|
268
|
+
##{{{ Info
|
269
|
+
#
|
270
|
+
#get '/knowledge_base/info/:name/:database/:pair' do
|
271
|
+
# name = consume_parameter :name
|
272
|
+
# database = consume_parameter :database
|
273
|
+
# pair = consume_parameter :pair
|
274
|
+
|
275
|
+
# kb = get_knowledge_base name
|
276
|
+
# index = kb.get_index(database)
|
277
|
+
|
278
|
+
# AssociationItem.setup(pair, kb, database, false)
|
279
|
+
# template_render('knowledge_base_partials/association', {:pair => pair, :kb => kb, :index => index, :database => database}, "Association: #{ pair }")
|
280
|
+
#end
|
281
|
+
#
|
282
|
+
##{{{ Children
|
283
|
+
|
284
|
+
#get '/knowledge_base/:name/:database/entity_children/:entity' do
|
285
|
+
# name = consume_parameter :name
|
286
|
+
# database = consume_parameter :database
|
287
|
+
# entity = consume_parameter :entity
|
288
|
+
|
289
|
+
# kb = get_knowledge_base name
|
290
|
+
# found = kb.identify database, entity
|
291
|
+
# raise ParameterException, "Entity #{entity} was not found" unless found
|
292
|
+
|
293
|
+
# list = kb.children(database, found).target_entity
|
294
|
+
|
295
|
+
# case @format
|
296
|
+
# when :json
|
297
|
+
# content_type "application/json"
|
298
|
+
# halt 200, prepare_entities_for_json(list).to_json
|
299
|
+
# when :html
|
300
|
+
# end
|
301
|
+
#end
|
302
|
+
|
303
|
+
## List children
|
304
|
+
#post '/knowledge_base/:name/:database/entity_list_children/' do
|
305
|
+
# name = consume_parameter :name
|
306
|
+
# database = consume_parameter :database
|
307
|
+
# entities = consume_parameter :entities
|
308
|
+
|
309
|
+
# raise ParameterException, "No 'entities' provided" if entities.nil?
|
310
|
+
|
311
|
+
# entities = entities.split("|")
|
312
|
+
|
313
|
+
# kb = get_knowledge_base name
|
314
|
+
|
315
|
+
# children = {}
|
316
|
+
# entities.each do |entity|
|
317
|
+
# found = kb.identify database, entity
|
318
|
+
# next if found.nil?
|
319
|
+
# children[entity] = kb.children(database, found).target_entity
|
320
|
+
# end
|
321
|
+
# case @format
|
322
|
+
# when :json
|
323
|
+
# content_type "application/json"
|
324
|
+
# halt 200, prepare_entities_for_json(children).to_json
|
325
|
+
# when :html
|
326
|
+
# end
|
327
|
+
#end
|
328
|
+
|
329
|
+
## Collection children
|
330
|
+
#post '/knowledge_base/:name/:database/entity_collection_children' do
|
331
|
+
# name = consume_parameter :name
|
332
|
+
# database = consume_parameter :database
|
333
|
+
# entities = consume_parameter :entities
|
334
|
+
|
335
|
+
# raise ParameterException, "No 'entities' provided" if entities.nil?
|
336
|
+
|
337
|
+
# entities = JSON.parse(entities)
|
338
|
+
|
339
|
+
# kb = get_knowledge_base name
|
340
|
+
|
341
|
+
# entities.each do |type,list|
|
342
|
+
# list.each do |entity|
|
343
|
+
# found = kb.identify database, entity
|
344
|
+
# next if found.nil?
|
345
|
+
# targets = kb.children(database, found).target_entity
|
346
|
+
# next if targets.nil? or targets.empty?
|
347
|
+
# target_type = kb.target database
|
348
|
+
# children[target_type] ||= []
|
349
|
+
# children[target_type].concat targets
|
350
|
+
# end
|
351
|
+
# end
|
352
|
+
|
353
|
+
# case @format
|
354
|
+
# when :json
|
355
|
+
# content_type "application/json"
|
356
|
+
# halt 200, prepare_entities_for_json(children).to_json
|
357
|
+
# when :html
|
358
|
+
# end
|
359
|
+
#end
|
360
|
+
|
361
|
+
##{{{ Neighbours
|
362
|
+
|
363
|
+
#get '/knowledge_base/:name/:database/entity_neighbours/:entity' do
|
364
|
+
# name = consume_parameter :name
|
365
|
+
# database = consume_parameter :database
|
366
|
+
# entity = consume_parameter :entity
|
367
|
+
|
368
|
+
# kb = get_knowledge_base name
|
369
|
+
# found = kb.identify database, entity
|
370
|
+
# raise ParameterException, "Entity #{entity} was not found" unless found
|
371
|
+
|
372
|
+
# list = kb.neighbours(database, found).values.select{|list| list and list.any?}.first
|
373
|
+
# list = list.target_entity if list.respond_to? :target_entity
|
374
|
+
# list ||= []
|
375
|
+
|
376
|
+
# case @format
|
377
|
+
# when :json
|
378
|
+
# content_type "application/json"
|
379
|
+
# halt 200, prepare_entities_for_json(list).to_json
|
380
|
+
# when :html
|
381
|
+
# end
|
382
|
+
#end
|
383
|
+
|
384
|
+
#post '/knowledge_base/:name/:database/entity_list_neighbours/' do
|
385
|
+
# name = consume_parameter :name
|
386
|
+
# database = consume_parameter :database
|
387
|
+
# entities = consume_parameter :entities
|
388
|
+
|
389
|
+
# raise ParameterException, "No 'entities' provided" if entities.nil?
|
390
|
+
|
391
|
+
# entities = entities.split("|")
|
392
|
+
|
393
|
+
# kb = get_knowledge_base name
|
394
|
+
|
395
|
+
# children = {}
|
396
|
+
# entities.each do |entity|
|
397
|
+
# found = kb.identify database, entity
|
398
|
+
# next if found.nil?
|
399
|
+
# matches = kb.neighbours(database, found).values.select{|list| list and list.any?}.first
|
400
|
+
# next if matches.nil? or matches.empty?
|
401
|
+
# children[entity] = matches.target_entity
|
402
|
+
# end
|
403
|
+
# case @format
|
404
|
+
# when :json
|
405
|
+
# content_type "application/json"
|
406
|
+
# halt 200, prepare_entities_for_json(children).to_json
|
407
|
+
# when :html
|
408
|
+
# end
|
409
|
+
#end
|
410
|
+
|
411
|
+
#post '/knowledge_base/:name/:database/entity_collection_neighbours' do
|
412
|
+
# name = consume_parameter :name
|
413
|
+
# database = consume_parameter :database
|
414
|
+
# entities = consume_parameter :entities
|
415
|
+
|
416
|
+
# raise ParameterException, "No 'entities' provided" if entities.nil?
|
417
|
+
|
418
|
+
# entities = JSON.parse(entities)
|
419
|
+
|
420
|
+
# kb = get_knowledge_base name
|
421
|
+
|
422
|
+
# neighbours = {}
|
423
|
+
# entities.each do |type,list|
|
424
|
+
# list.each do |entity|
|
425
|
+
|
426
|
+
# found = kb.identify_source database, entity
|
427
|
+
# if found.nil?
|
428
|
+
# reverse = true
|
429
|
+
# found = kb.identify_target database, entity
|
430
|
+
# else
|
431
|
+
# reverse = false
|
432
|
+
# end
|
433
|
+
# next if found.nil?
|
434
|
+
|
435
|
+
# matches = kb.neighbours(database, found)[reverse ? :parents : :children]
|
436
|
+
# next if matches.nil? or matches.empty?
|
437
|
+
# targets = matches.target
|
438
|
+
|
439
|
+
# entity_type = reverse ? kb.source_type(database) : kb.target_type(database)
|
440
|
+
# neighbours[entity_type] ||= []
|
441
|
+
# neighbours[entity_type].concat targets
|
442
|
+
# end
|
443
|
+
# end
|
444
|
+
|
445
|
+
# neighbours.each{|type, list| list.uniq!}
|
446
|
+
|
447
|
+
# case @format
|
448
|
+
# when :json
|
449
|
+
# content_type "application/json"
|
450
|
+
# halt 200, prepare_entities_for_json(neighbours).to_json
|
451
|
+
# when :html
|
452
|
+
# end
|
453
|
+
#end
|
452
454
|
end
|
453
455
|
end
|
454
456
|
end
|