rbbt-util 5.14.6 → 5.14.7
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.
- checksums.yaml +4 -4
- data/lib/rbbt/association.rb +1 -1
- data/lib/rbbt/association/index.rb +8 -3
- data/lib/rbbt/association/item.rb +8 -0
- data/lib/rbbt/knowledge_base.rb +19 -14
- data/lib/rbbt/util/misc/format.rb +2 -2
- data/lib/rbbt/workflow/accessor.rb +2 -1
- data/share/rbbt_commands/association/subset +41 -0
- data/share/rbbt_commands/workflow/knowledge_base +68 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc4fe61feb344cc28a196b45ce9a9a3f5f0cf8a1
|
4
|
+
data.tar.gz: 36d5dad6c8f90493f0a998c9078c74a8836084a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62bcc281c2dc513b52b67515b8df46b6151b318a6660a5096b7913637779e550a24c8ade84f2847c7af18760526abd5ac30a1f1d912651c44f8db33d16b9acb8
|
7
|
+
data.tar.gz: d89848d0ec11114934bb762fbdde56e5c2d81216925b5450cf223f120798d1378428c707326ac6d3840b00726e24d06c89cd0d733c1e776eaf1700a913a10796
|
data/lib/rbbt/association.rb
CHANGED
@@ -78,7 +78,7 @@ module Association
|
|
78
78
|
:persist => false,
|
79
79
|
:key_field => all_fields.index(source),
|
80
80
|
:fields => fields.collect{|f| String === f ? all_fields.index(f): f },
|
81
|
-
|
81
|
+
#:type => (options[:type] and options[:type].to_sym == :flat) ? :flat : nil,
|
82
82
|
:unnamed => true,
|
83
83
|
:merge => (options[:type] and options[:type].to_sym == :flat) ? false : true
|
84
84
|
})
|
@@ -20,6 +20,7 @@ module Association
|
|
20
20
|
|
21
21
|
if File.exists?(reverse_filename)
|
22
22
|
new = Persist.open_tokyocabinet(reverse_filename, false, serializer, TokyoCabinet::BDB)
|
23
|
+
new
|
23
24
|
else
|
24
25
|
FileUtils.mkdir_p File.basename(reverse_filename) unless File.exists?(File.basename(reverse_filename))
|
25
26
|
new = Persist.open_tokyocabinet(reverse_filename, true, serializer, TokyoCabinet::BDB)
|
@@ -64,8 +65,8 @@ module Association
|
|
64
65
|
source_type = Entity.formats[source_field]
|
65
66
|
target_type = Entity.formats[target_field]
|
66
67
|
|
67
|
-
source_entities = entities[source_field] || entities[Entity.formats[source_field].to_s]
|
68
|
-
target_entities = entities[target_field] || entities[Entity.formats[target_field].to_s]
|
68
|
+
source_entities = entities[:source] || entities[source_field] || entities[Entity.formats[source_field].to_s]
|
69
|
+
target_entities = entities[:target] || entities[target_field] || entities[Entity.formats[target_field].to_s]
|
69
70
|
|
70
71
|
[source_entities, target_entities]
|
71
72
|
end
|
@@ -79,7 +80,7 @@ module Association
|
|
79
80
|
matches = source.uniq.inject([]){|acc,e| acc.concat(match(e)) }
|
80
81
|
end
|
81
82
|
|
82
|
-
return matches if target == :all or target == "all"
|
83
|
+
return matches if target.nil? or target == :all or target == "all"
|
83
84
|
|
84
85
|
target_matches = {}
|
85
86
|
|
@@ -95,6 +96,10 @@ module Association
|
|
95
96
|
|
96
97
|
def subset_entities(entities)
|
97
98
|
source, target = select_entities(entities)
|
99
|
+
raise "Please specify source entities" if source.nil?
|
100
|
+
target = :all if target.nil?
|
101
|
+
return if Array === target and target.empty?
|
102
|
+
return if Array === source and source.empty?
|
98
103
|
subset source, target
|
99
104
|
end
|
100
105
|
end
|
@@ -19,6 +19,14 @@ module AssociationItem
|
|
19
19
|
self.clean_annotations.collect{|p| p[/[^~]+/] }
|
20
20
|
end
|
21
21
|
|
22
|
+
property :target_type => :single do
|
23
|
+
reverse ? knowledge_base.source(database) : knowledge_base.target(database)
|
24
|
+
end
|
25
|
+
|
26
|
+
property :source_type => :single do
|
27
|
+
reverse ? knowledge_base.target(database) : knowledge_base.source(database)
|
28
|
+
end
|
29
|
+
|
22
30
|
property :target_entity => :array2single do
|
23
31
|
type = reverse ? knowledge_base.source(database) : knowledge_base.target(database)
|
24
32
|
knowledge_base.annotate self.target, type, database #if self.target.any?
|
data/lib/rbbt/knowledge_base.rb
CHANGED
@@ -149,10 +149,6 @@ class KnowledgeBase
|
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
152
|
-
#def index(name, file, options = {}, persist_options = {})
|
153
|
-
# @indices[name] = Association.index(file, open_options.merge(options), persist_options)
|
154
|
-
#end
|
155
|
-
|
156
152
|
#{{{ Add manual database
|
157
153
|
|
158
154
|
def add_index(name, source_type, target_type, *fields)
|
@@ -279,19 +275,28 @@ class KnowledgeBase
|
|
279
275
|
end
|
280
276
|
|
281
277
|
def subset(name, entities)
|
282
|
-
case entities
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
278
|
+
entities = case entities
|
279
|
+
when AnnotatedArray
|
280
|
+
format = entities.format if entities.respond_to? :format
|
281
|
+
format ||= entities.base_entity.to_s
|
282
|
+
{format => entities.clean_annotations}
|
283
|
+
when Hash
|
284
|
+
entities
|
285
|
+
else
|
286
|
+
raise "Entities are not a Hash or an AnnotatedArray: #{Misc.fingerprint entities}"
|
287
|
+
end
|
288
|
+
|
291
289
|
repo = get_index name
|
290
|
+
|
292
291
|
begin
|
293
292
|
setup(name, repo.subset_entities(entities))
|
294
|
-
rescue
|
293
|
+
rescue Exception
|
294
|
+
target = entities[:target]
|
295
|
+
source = entities[:source]
|
296
|
+
if target or source
|
297
|
+
entities[:target] = source
|
298
|
+
entities[:source] = target
|
299
|
+
end
|
295
300
|
setup(name, repo.reverse.subset_entities(entities), true)
|
296
301
|
end
|
297
302
|
end
|
@@ -71,13 +71,13 @@ module Misc
|
|
71
71
|
text
|
72
72
|
end
|
73
73
|
|
74
|
-
def self.format_definition_list(defs, size = 80, indent = 20, color = :yellow)
|
74
|
+
def self.format_definition_list(defs, size = 80, indent = 20, color = :yellow, sep = "\n\n")
|
75
75
|
entries = []
|
76
76
|
defs.each do |dt,dd|
|
77
77
|
text = format_definition_list_item(dt,dd,size,indent,color)
|
78
78
|
entries << text
|
79
79
|
end
|
80
|
-
entries *
|
80
|
+
entries * sep
|
81
81
|
end
|
82
82
|
|
83
83
|
def self.camel_case(string)
|
@@ -503,7 +503,8 @@ module Workflow
|
|
503
503
|
options.each{|i,v|
|
504
504
|
case v
|
505
505
|
when Symbol
|
506
|
-
rec_dependency = real_dependencies.select{|d| d.task.name == v }.first
|
506
|
+
rec_dependency = real_dependencies.collect{|d| [d, d.dependencies].flatten}.flatten.select{|d| d.task.name == v }.first
|
507
|
+
rec_dependency = rec_dependency.run unless (dependency.first.tasks[dependency[1]].input_options[i] || {})[:stream]
|
507
508
|
inputs[i] = rec_dependency
|
508
509
|
else
|
509
510
|
inputs[i] = v
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rbbt-util'
|
4
|
+
require 'rbbt/util/simpleopt'
|
5
|
+
require 'rbbt/association'
|
6
|
+
|
7
|
+
$0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_commands
|
8
|
+
|
9
|
+
options = SOPT.setup <<EOF
|
10
|
+
|
11
|
+
Subset of matches between entities
|
12
|
+
|
13
|
+
$ rbbt association subset [options] <filename>
|
14
|
+
|
15
|
+
Indicate the index file (TokyoCabinet BDB with source~target keys) as the <filename> argument
|
16
|
+
|
17
|
+
-h--help Print this help
|
18
|
+
-s--source* Source entities
|
19
|
+
-t--target* Target entities
|
20
|
+
EOF
|
21
|
+
rbbt_usage and exit 0 if options[:help]
|
22
|
+
filename = ARGV.shift
|
23
|
+
raise ParameterException, "No filename specified" if filename.nil?
|
24
|
+
|
25
|
+
file = Persist.open_tokyocabinet(filename,false, nil, TokyoCabinet::BDB)
|
26
|
+
|
27
|
+
file.extend Association::Index
|
28
|
+
|
29
|
+
source = options[:source] ? options[:source].split(/,\|/) : :all
|
30
|
+
target = options[:target] ? options[:target].split(/,\|/) : :all
|
31
|
+
|
32
|
+
file.subset(source, target).each do |item|
|
33
|
+
puts Log.color(:magenta, item)
|
34
|
+
info = file.fields.zip(file[item])
|
35
|
+
source,_sep, target = item.partition "~"
|
36
|
+
puts " " << Misc.format_definition_list_item("source", source)
|
37
|
+
puts " " << Misc.format_definition_list_item("target", target)
|
38
|
+
info.each do |key,value|
|
39
|
+
puts " " << Misc.format_definition_list_item(key, value)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rbbt/util/simpleopt'
|
4
|
+
require 'rbbt/workflow'
|
5
|
+
require 'rbbt/workflow/usage'
|
6
|
+
require 'time'
|
7
|
+
|
8
|
+
options = SOPT.setup <<EOF
|
9
|
+
Access workflow knowledge_base
|
10
|
+
|
11
|
+
$ rbbt workflow knowledge_base <workflow> [<database>] [<action>] [<options>]
|
12
|
+
|
13
|
+
Access workflow knowledge base
|
14
|
+
|
15
|
+
-h--help Show this help:
|
16
|
+
-cl--clean Clean the last step of the job so that it gets recomputed:
|
17
|
+
-sf--source_format* Source format
|
18
|
+
-se--source_entities* Source entities
|
19
|
+
-tf--target_format* Target format
|
20
|
+
-te--target_entities* Target entities
|
21
|
+
-i--info Print information on matches
|
22
|
+
EOF
|
23
|
+
|
24
|
+
workflow = ARGV.shift
|
25
|
+
usage and exit -1 if workflow.nil? or options[:help]
|
26
|
+
|
27
|
+
database = ARGV.shift
|
28
|
+
action = ARGV.shift
|
29
|
+
|
30
|
+
# Get workflow
|
31
|
+
|
32
|
+
workflow = Workflow.require_workflow workflow
|
33
|
+
|
34
|
+
action = :list_databases if database.nil?
|
35
|
+
action ||= :summary
|
36
|
+
|
37
|
+
case action.to_sym
|
38
|
+
when :list_databases
|
39
|
+
dbs = workflow.knowledge_base.registry.keys
|
40
|
+
puts dbs * "\n"
|
41
|
+
when :summary
|
42
|
+
db = workflow.knowledge_base.get_database(database)
|
43
|
+
puts db.summary
|
44
|
+
when :subset
|
45
|
+
source_format = options[:source_format] || :source
|
46
|
+
target_format = options[:target_format] || :target
|
47
|
+
source_entities = options[:source_entities] || :all
|
48
|
+
target_entities = options[:target_entities] || :all
|
49
|
+
|
50
|
+
source_entities = source_entities.split(/,\|/) if String === source_entities
|
51
|
+
target_entities = target_entities.split(/,\|/) if String === target_entities
|
52
|
+
|
53
|
+
entities = {source_format => source_entities, target_format => target_entities}
|
54
|
+
|
55
|
+
matches = workflow.knowledge_base.subset(database, entities)
|
56
|
+
matches.each do |item|
|
57
|
+
puts Log.color :magenta, item
|
58
|
+
if options[:info]
|
59
|
+
source = item.source_entity
|
60
|
+
target = item.target_entity
|
61
|
+
source = source.name if source.respond_to? :name
|
62
|
+
target = target.name if target.respond_to? :name
|
63
|
+
|
64
|
+
info = item.info.merge(:source => source, :target => target)
|
65
|
+
puts Misc.format_definition_list(info, 80, 20, :yellow, "\n")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbbt-util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.14.
|
4
|
+
version: 5.14.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -232,6 +232,7 @@ files:
|
|
232
232
|
- share/rbbt_commands/app/install
|
233
233
|
- share/rbbt_commands/app/start
|
234
234
|
- share/rbbt_commands/app/template
|
235
|
+
- share/rbbt_commands/association/subset
|
235
236
|
- share/rbbt_commands/benchmark/pthrough
|
236
237
|
- share/rbbt_commands/benchmark/throughput
|
237
238
|
- share/rbbt_commands/benchmark/tsv
|
@@ -272,6 +273,7 @@ files:
|
|
272
273
|
- share/rbbt_commands/workflow/info
|
273
274
|
- share/rbbt_commands/workflow/install
|
274
275
|
- share/rbbt_commands/workflow/jobs
|
276
|
+
- share/rbbt_commands/workflow/knowledge_base
|
275
277
|
- share/rbbt_commands/workflow/list
|
276
278
|
- share/rbbt_commands/workflow/monitor
|
277
279
|
- share/rbbt_commands/workflow/prov
|