rbbt-util 5.44.1 → 6.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rbbt +67 -90
- data/etc/app.d/base.rb +2 -2
- data/etc/app.d/semaphores.rb +3 -3
- data/lib/rbbt/annotations/annotated_array.rb +207 -207
- data/lib/rbbt/annotations/refactor.rb +27 -0
- data/lib/rbbt/annotations/util.rb +282 -282
- data/lib/rbbt/annotations.rb +343 -320
- data/lib/rbbt/association/database.rb +200 -225
- data/lib/rbbt/association/index.rb +294 -291
- data/lib/rbbt/association/item.rb +227 -227
- data/lib/rbbt/association/open.rb +35 -34
- data/lib/rbbt/association/util.rb +0 -169
- data/lib/rbbt/association.rb +2 -4
- data/lib/rbbt/entity/identifiers.rb +119 -118
- data/lib/rbbt/entity/refactor.rb +12 -0
- data/lib/rbbt/entity.rb +319 -315
- data/lib/rbbt/hpc/batch.rb +72 -53
- data/lib/rbbt/hpc/lsf.rb +2 -2
- data/lib/rbbt/hpc/orchestrate/batches.rb +2 -2
- data/lib/rbbt/hpc/orchestrate/chains.rb +25 -5
- data/lib/rbbt/hpc/orchestrate/rules.rb +2 -2
- data/lib/rbbt/hpc/orchestrate.rb +19 -13
- data/lib/rbbt/hpc/slurm.rb +18 -18
- data/lib/rbbt/knowledge_base/entity.rb +13 -5
- data/lib/rbbt/knowledge_base/query.rb +2 -2
- data/lib/rbbt/knowledge_base/registry.rb +32 -31
- data/lib/rbbt/knowledge_base/traverse.rb +1 -1
- data/lib/rbbt/knowledge_base.rb +1 -1
- data/lib/rbbt/monitor.rb +36 -25
- data/lib/rbbt/persist/refactor.rb +166 -0
- data/lib/rbbt/persist/tsv/tokyocabinet.rb +105 -105
- data/lib/rbbt/persist/tsv.rb +187 -185
- data/lib/rbbt/persist.rb +556 -551
- data/lib/rbbt/refactor.rb +20 -0
- data/lib/rbbt/resource/path/refactor.rb +178 -0
- data/lib/rbbt/resource/path.rb +317 -497
- data/lib/rbbt/resource/util.rb +0 -48
- data/lib/rbbt/resource.rb +3 -390
- data/lib/rbbt/tsv/accessor.rb +2 -838
- data/lib/rbbt/tsv/attach.rb +303 -299
- data/lib/rbbt/tsv/change_id.rb +244 -245
- data/lib/rbbt/tsv/csv.rb +87 -85
- data/lib/rbbt/tsv/dumper.rb +2 -100
- data/lib/rbbt/tsv/excel.rb +26 -24
- data/lib/rbbt/tsv/field_index.rb +4 -1
- data/lib/rbbt/tsv/filter.rb +3 -2
- data/lib/rbbt/tsv/index.rb +2 -284
- data/lib/rbbt/tsv/manipulate.rb +750 -747
- data/lib/rbbt/tsv/marshal.rb +3 -3
- data/lib/rbbt/tsv/matrix.rb +2 -2
- data/lib/rbbt/tsv/parallel/through.rb +2 -1
- data/lib/rbbt/tsv/parallel/traverse.rb +783 -781
- data/lib/rbbt/tsv/parser.rb +678 -678
- data/lib/rbbt/tsv/refactor.rb +195 -0
- data/lib/rbbt/tsv/stream.rb +253 -251
- data/lib/rbbt/tsv/util.rb +420 -420
- data/lib/rbbt/tsv.rb +210 -208
- data/lib/rbbt/util/R/eval.rb +4 -4
- data/lib/rbbt/util/R/plot.rb +62 -166
- data/lib/rbbt/util/R.rb +21 -18
- data/lib/rbbt/util/cmd.rb +2 -318
- data/lib/rbbt/util/color.rb +269 -269
- data/lib/rbbt/util/colorize.rb +89 -89
- data/lib/rbbt/util/concurrency/processes/refactor.rb +22 -0
- data/lib/rbbt/util/concurrency/processes/worker.rb +2 -2
- data/lib/rbbt/util/concurrency/processes.rb +389 -386
- data/lib/rbbt/util/config.rb +169 -167
- data/lib/rbbt/util/iruby.rb +20 -0
- data/lib/rbbt/util/log/progress/report.rb +241 -241
- data/lib/rbbt/util/log/progress/util.rb +99 -99
- data/lib/rbbt/util/log/progress.rb +102 -102
- data/lib/rbbt/util/log/refactor.rb +49 -0
- data/lib/rbbt/util/log.rb +486 -532
- data/lib/rbbt/util/migrate.rb +1 -1
- data/lib/rbbt/util/misc/concurrent_stream.rb +248 -246
- data/lib/rbbt/util/misc/development.rb +12 -11
- data/lib/rbbt/util/misc/exceptions.rb +117 -112
- data/lib/rbbt/util/misc/format.rb +2 -230
- data/lib/rbbt/util/misc/indiferent_hash.rb +2 -107
- data/lib/rbbt/util/misc/inspect.rb +2 -476
- data/lib/rbbt/util/misc/lock.rb +109 -106
- data/lib/rbbt/util/misc/omics.rb +9 -1
- data/lib/rbbt/util/misc/pipes.rb +765 -793
- data/lib/rbbt/util/misc/refactor.rb +20 -0
- data/lib/rbbt/util/misc/ssw.rb +27 -17
- data/lib/rbbt/util/misc/system.rb +0 -15
- data/lib/rbbt/util/misc.rb +39 -20
- data/lib/rbbt/util/named_array/refactor.rb +4 -0
- data/lib/rbbt/util/named_array.rb +3 -220
- data/lib/rbbt/util/open/refactor.rb +7 -0
- data/lib/rbbt/util/open.rb +3 -857
- data/lib/rbbt/util/procpath.rb +6 -6
- data/lib/rbbt/util/python/paths.rb +27 -0
- data/lib/rbbt/util/python/run.rb +115 -0
- data/lib/rbbt/util/python/script.rb +110 -0
- data/lib/rbbt/util/python/util.rb +3 -3
- data/lib/rbbt/util/python.rb +22 -81
- data/lib/rbbt/util/semaphore.rb +152 -148
- data/lib/rbbt/util/simpleopt.rb +9 -8
- data/lib/rbbt/util/ssh/refactor.rb +19 -0
- data/lib/rbbt/util/ssh.rb +122 -118
- data/lib/rbbt/util/tar.rb +117 -115
- data/lib/rbbt/util/tmpfile.rb +69 -67
- data/lib/rbbt/util/version.rb +2 -0
- data/lib/rbbt/workflow/refactor/entity.rb +11 -0
- data/lib/rbbt/workflow/refactor/export.rb +66 -0
- data/lib/rbbt/workflow/refactor/inputs.rb +24 -0
- data/lib/rbbt/workflow/refactor/recursive.rb +64 -0
- data/lib/rbbt/workflow/refactor/task_info.rb +65 -0
- data/lib/rbbt/workflow/refactor.rb +153 -0
- data/lib/rbbt/workflow/remote_workflow/driver/ssh.rb +55 -32
- data/lib/rbbt/workflow/remote_workflow/remote_step/rest.rb +3 -1
- data/lib/rbbt/workflow/remote_workflow/remote_step/ssh.rb +14 -5
- data/lib/rbbt/workflow/remote_workflow/remote_step.rb +19 -7
- data/lib/rbbt/workflow/remote_workflow.rb +6 -1
- data/lib/rbbt/workflow/step/run.rb +766 -766
- data/lib/rbbt/workflow/step/save_load_inputs.rb +254 -254
- data/lib/rbbt/workflow/step.rb +2 -362
- data/lib/rbbt/workflow/task.rb +118 -118
- data/lib/rbbt/workflow/usage.rb +289 -287
- data/lib/rbbt/workflow/util/archive.rb +6 -5
- data/lib/rbbt/workflow/util/data.rb +1 -1
- data/lib/rbbt/workflow/util/orchestrator.rb +249 -246
- data/lib/rbbt/workflow/util/trace.rb +79 -44
- data/lib/rbbt/workflow.rb +4 -882
- data/lib/rbbt-util.rb +21 -13
- data/lib/rbbt.rb +16 -3
- data/python/rbbt/__init__.py +19 -1
- data/share/Rlib/plot.R +37 -37
- data/share/Rlib/svg.R +22 -5
- data/share/install/software/lib/install_helpers +1 -1
- data/share/rbbt_commands/hpc/list +2 -3
- data/share/rbbt_commands/hpc/orchestrate +4 -4
- data/share/rbbt_commands/hpc/tail +2 -0
- data/share/rbbt_commands/hpc/task +10 -7
- data/share/rbbt_commands/lsf/list +2 -3
- data/share/rbbt_commands/lsf/orchestrate +4 -4
- data/share/rbbt_commands/lsf/tail +2 -0
- data/share/rbbt_commands/lsf/task +10 -7
- data/share/rbbt_commands/migrate +1 -1
- data/share/rbbt_commands/pbs/list +2 -3
- data/share/rbbt_commands/pbs/orchestrate +4 -4
- data/share/rbbt_commands/pbs/tail +2 -0
- data/share/rbbt_commands/pbs/task +10 -7
- data/share/rbbt_commands/resource/produce +8 -1
- data/share/rbbt_commands/slurm/list +2 -3
- data/share/rbbt_commands/slurm/orchestrate +4 -4
- data/share/rbbt_commands/slurm/tail +2 -0
- data/share/rbbt_commands/slurm/task +10 -7
- data/share/rbbt_commands/system/clean +5 -5
- data/share/rbbt_commands/system/status +5 -5
- data/share/rbbt_commands/tsv/get +2 -3
- data/share/rbbt_commands/tsv/info +10 -13
- data/share/rbbt_commands/tsv/keys +18 -14
- data/share/rbbt_commands/tsv/slice +2 -2
- data/share/rbbt_commands/tsv/transpose +6 -2
- data/share/rbbt_commands/workflow/info +20 -24
- data/share/rbbt_commands/workflow/list +1 -1
- data/share/rbbt_commands/workflow/prov +20 -13
- data/share/rbbt_commands/workflow/server +11 -1
- data/share/rbbt_commands/workflow/task +76 -71
- data/share/rbbt_commands/workflow/write_info +26 -9
- data/share/software/opt/ssw/ssw.c +861 -0
- data/share/software/opt/ssw/ssw.h +130 -0
- data/share/workflow_config.ru +3 -3
- metadata +40 -2
@@ -1,227 +1,227 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module AssociationItem
|
4
|
-
extend
|
5
|
-
|
6
|
-
annotation :knowledge_base
|
7
|
-
annotation :database
|
8
|
-
annotation :reverse
|
9
|
-
|
10
|
-
property :name => :single do
|
11
|
-
[source_entity, target_entity].collect{|e| e.respond_to?(:name)? e.name || e : e } * "~"
|
12
|
-
end
|
13
|
-
|
14
|
-
property :full_name => :single do
|
15
|
-
database ? [database, name] * ":" : name
|
16
|
-
end
|
17
|
-
|
18
|
-
property :invert => :both do
|
19
|
-
if Array === self
|
20
|
-
inverted = self.collect do |item|
|
21
|
-
s,_sep,t= item.partition "~"
|
22
|
-
new = [t,s] * _sep
|
23
|
-
end
|
24
|
-
self.annotate inverted
|
25
|
-
inverted.reverse = ! reverse
|
26
|
-
inverted
|
27
|
-
else
|
28
|
-
s,_sep,t= self.partition "~"
|
29
|
-
inverted = self.annotate([t,s] * _sep)
|
30
|
-
inverted.reverse = ! reverse
|
31
|
-
inverted
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
property :namespace => :both do
|
36
|
-
knowledge_base.namespace
|
37
|
-
end
|
38
|
-
|
39
|
-
property :part => :array2single do
|
40
|
-
self.clean_annotations.collect{|p| p.partition("~") }
|
41
|
-
end
|
42
|
-
|
43
|
-
property :target => :array2single do
|
44
|
-
self.part.collect{|p| p[2]}
|
45
|
-
end
|
46
|
-
|
47
|
-
property :source => :array2single do
|
48
|
-
self.clean_annotations.collect{|p| p[/[^~]+/] }
|
49
|
-
end
|
50
|
-
|
51
|
-
property :target_entity_type => :both do
|
52
|
-
Entity.formats[target_type].to_s
|
53
|
-
end
|
54
|
-
|
55
|
-
property :source_entity_type => :both do
|
56
|
-
Entity.formats[source_type].to_s
|
57
|
-
end
|
58
|
-
|
59
|
-
property :target_type => :both do
|
60
|
-
if reverse
|
61
|
-
knowledge_base.source(database)
|
62
|
-
else
|
63
|
-
knowledge_base.target(database)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
property :source_type => :both do
|
68
|
-
if reverse
|
69
|
-
knowledge_base.target(database)
|
70
|
-
else
|
71
|
-
knowledge_base.source(database)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
property :undirected => :both do
|
76
|
-
knowledge_base.undirected(database)
|
77
|
-
end
|
78
|
-
|
79
|
-
property :target_entity => :array2single do
|
80
|
-
type = target_type
|
81
|
-
knowledge_base.annotate self.target, type, database #if self.target.any?
|
82
|
-
end
|
83
|
-
|
84
|
-
property :source_entity => :array2single do
|
85
|
-
type = source_type
|
86
|
-
knowledge_base.annotate self.source, type, database #if self.source.any?
|
87
|
-
end
|
88
|
-
|
89
|
-
property :index => :both do |database|
|
90
|
-
@index ||= knowledge_base.get_index(database)
|
91
|
-
end
|
92
|
-
property :value => :array2single do
|
93
|
-
index = index(database)
|
94
|
-
value = self.reverse ? index.chunked_values_at(self.invert) : index.chunked_values_at(self)
|
95
|
-
value.collect{|v| NamedArray.setup(v, index.fields)}
|
96
|
-
end
|
97
|
-
|
98
|
-
property :info_fields => :both do
|
99
|
-
knowledge_base.index_fields(database)
|
100
|
-
end
|
101
|
-
|
102
|
-
property :info => :array2single do
|
103
|
-
fields = self.info_fields
|
104
|
-
|
105
|
-
return [{}] * self.length if fields.nil? or fields.empty?
|
106
|
-
|
107
|
-
value = self.value
|
108
|
-
value.collect{|v|
|
109
|
-
raise "No info for pair; not registered in index" if v.nil?
|
110
|
-
Hash[*fields.zip(v).flatten]
|
111
|
-
}
|
112
|
-
end
|
113
|
-
|
114
|
-
property :tsv => :array do
|
115
|
-
info_fields = self.info_fields
|
116
|
-
fields = [self.source_type, self.target_type].concat info_fields
|
117
|
-
type = [self.source_type, self.target_type] * "~"
|
118
|
-
tsv = TSV.setup({}, :key_field => type, :fields => fields, :type => :list, :namespace => self.namespace)
|
119
|
-
index = index(database)
|
120
|
-
index.with_unnamed do
|
121
|
-
index.chunked_values_at(self).each_with_index do |v,i|
|
122
|
-
p = self[i]
|
123
|
-
source, _sep, target = p.partition("~")
|
124
|
-
if info_fields.empty?
|
125
|
-
tsv[p] = [source, target]
|
126
|
-
else
|
127
|
-
tsv[p] = [source, target].concat v
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
tsv.entity_options = {:
|
132
|
-
knowledge_base.entity_options.each do |type,options|
|
133
|
-
tsv.entity_options.merge! options
|
134
|
-
end
|
135
|
-
tsv
|
136
|
-
end
|
137
|
-
|
138
|
-
property :filter => :array do |*args,&block|
|
139
|
-
block = args.pop if Proc === args.last
|
140
|
-
keys = tsv.with_unnamed do tsv.select(*args, &block).keys end
|
141
|
-
keys = self.annotate keys
|
142
|
-
keys
|
143
|
-
end
|
144
|
-
|
145
|
-
def self.incidence(pairs, key_field = nil, &block)
|
146
|
-
matrix = {}
|
147
|
-
targets = []
|
148
|
-
sources = []
|
149
|
-
matches = {}
|
150
|
-
|
151
|
-
pairs.inject([]){|acc,m| acc << m; acc << m.invert if m.respond_to?(:undirected) and m.undirected; acc }.each do |p|
|
152
|
-
s, sep, t = p.partition "~"
|
153
|
-
|
154
|
-
sources << s
|
155
|
-
targets << t
|
156
|
-
if block_given?
|
157
|
-
matches[s] ||= Hash.new{nil}
|
158
|
-
value = block.call p
|
159
|
-
matches[s][t] = value unless value.nil? or (mv = matches[s][t] and value > mv)
|
160
|
-
else
|
161
|
-
matches[s] ||= Hash.new{false}
|
162
|
-
matches[s][t] ||= true
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
sources.uniq!
|
167
|
-
targets = targets.uniq.sort
|
168
|
-
|
169
|
-
matches.each do |s,hash|
|
170
|
-
matrix[s] = hash.values_at(*targets)
|
171
|
-
end
|
172
|
-
|
173
|
-
defined?(TSV)? TSV.setup(matrix, :key_field => (key_field || "Source") , :fields => targets, :type => :list) : matrix
|
174
|
-
end
|
175
|
-
|
176
|
-
def self.adjacency(pairs, key_field = nil, &block)
|
177
|
-
incidence = incidence(pairs, key_field, &block)
|
178
|
-
|
179
|
-
targets = incidence.fields
|
180
|
-
adjacency = TSV.setup({}, :key_field => incidence.key_field, :fields => ["Target"], :type => :double)
|
181
|
-
TSV.traverse incidence, :into => adjacency, :unnamed => true do |k,values|
|
182
|
-
target_values = targets.zip(values).reject{|t,v| v.nil? }.collect{|t,v| [t,v]}
|
183
|
-
next if target_values.empty?
|
184
|
-
[k, Misc.zip_fields(target_values)]
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
def self._select_match(orig, elem)
|
189
|
-
if Array === orig and Array === elem
|
190
|
-
(orig & elem).any?
|
191
|
-
elsif Array === orig
|
192
|
-
orig.include? elem
|
193
|
-
elsif Array === elem
|
194
|
-
elem.include? orig
|
195
|
-
else
|
196
|
-
elem === orif
|
197
|
-
end
|
198
|
-
false
|
199
|
-
end
|
200
|
-
|
201
|
-
def self.select(list, method = nil, &block)
|
202
|
-
if method and method.any?
|
203
|
-
list.select do |item|
|
204
|
-
method.collect do |key,value|
|
205
|
-
case key
|
206
|
-
when :target
|
207
|
-
_select_match item.target, value
|
208
|
-
when :source
|
209
|
-
_select_match item.source, value
|
210
|
-
else
|
211
|
-
orig = item.info[key]
|
212
|
-
orig = orig.split(";;") if String orig
|
213
|
-
_select_match orig, value
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
217
|
-
else
|
218
|
-
list.select(&block)
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
module TSV
|
224
|
-
def self.incidence(tsv)
|
225
|
-
AssociationItem.incidence Association.index(tsv, :persist => false).keys
|
226
|
-
end
|
227
|
-
end
|
1
|
+
#require_relative '../entity'
|
2
|
+
#
|
3
|
+
#module AssociationItem
|
4
|
+
# extend Entity
|
5
|
+
#
|
6
|
+
# annotation :knowledge_base
|
7
|
+
# annotation :database
|
8
|
+
# annotation :reverse
|
9
|
+
#
|
10
|
+
# property :name => :single do
|
11
|
+
# [source_entity, target_entity].collect{|e| e.respond_to?(:name)? e.name || e : e } * "~"
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# property :full_name => :single do
|
15
|
+
# database ? [database, name] * ":" : name
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# property :invert => :both do
|
19
|
+
# if Array === self
|
20
|
+
# inverted = self.collect do |item|
|
21
|
+
# s,_sep,t= item.partition "~"
|
22
|
+
# new = [t,s] * _sep
|
23
|
+
# end
|
24
|
+
# self.annotate inverted
|
25
|
+
# inverted.reverse = ! reverse
|
26
|
+
# inverted
|
27
|
+
# else
|
28
|
+
# s,_sep,t= self.partition "~"
|
29
|
+
# inverted = self.annotate([t,s] * _sep)
|
30
|
+
# inverted.reverse = ! reverse
|
31
|
+
# inverted
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# property :namespace => :both do
|
36
|
+
# knowledge_base.namespace
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# property :part => :array2single do
|
40
|
+
# self.clean_annotations.collect{|p| p.partition("~") }
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# property :target => :array2single do
|
44
|
+
# self.part.collect{|p| p[2]}
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# property :source => :array2single do
|
48
|
+
# self.clean_annotations.collect{|p| p[/[^~]+/] }
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# property :target_entity_type => :both do
|
52
|
+
# Entity.formats[target_type].to_s
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# property :source_entity_type => :both do
|
56
|
+
# Entity.formats[source_type].to_s
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# property :target_type => :both do
|
60
|
+
# if reverse
|
61
|
+
# knowledge_base.source(database)
|
62
|
+
# else
|
63
|
+
# knowledge_base.target(database)
|
64
|
+
# end
|
65
|
+
# end
|
66
|
+
#
|
67
|
+
# property :source_type => :both do
|
68
|
+
# if reverse
|
69
|
+
# knowledge_base.target(database)
|
70
|
+
# else
|
71
|
+
# knowledge_base.source(database)
|
72
|
+
# end
|
73
|
+
# end
|
74
|
+
#
|
75
|
+
# property :undirected => :both do
|
76
|
+
# knowledge_base.undirected(database)
|
77
|
+
# end
|
78
|
+
#
|
79
|
+
# property :target_entity => :array2single do
|
80
|
+
# type = target_type
|
81
|
+
# knowledge_base.annotate self.target, type, database #if self.target.any?
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
# property :source_entity => :array2single do
|
85
|
+
# type = source_type
|
86
|
+
# knowledge_base.annotate self.source, type, database #if self.source.any?
|
87
|
+
# end
|
88
|
+
#
|
89
|
+
# property :index => :both do |database|
|
90
|
+
# @index ||= knowledge_base.get_index(database)
|
91
|
+
# end
|
92
|
+
# property :value => :array2single do
|
93
|
+
# index = index(database)
|
94
|
+
# value = self.reverse ? index.chunked_values_at(self.invert) : index.chunked_values_at(self)
|
95
|
+
# value.collect{|v| NamedArray.setup(v, index.fields)}
|
96
|
+
# end
|
97
|
+
#
|
98
|
+
# property :info_fields => :both do
|
99
|
+
# knowledge_base.index_fields(database)
|
100
|
+
# end
|
101
|
+
#
|
102
|
+
# property :info => :array2single do
|
103
|
+
# fields = self.info_fields
|
104
|
+
#
|
105
|
+
# return [{}] * self.length if fields.nil? or fields.empty?
|
106
|
+
#
|
107
|
+
# value = self.value
|
108
|
+
# value.collect{|v|
|
109
|
+
# raise "No info for pair; not registered in index" if v.nil?
|
110
|
+
# Hash[*fields.zip(v).flatten]
|
111
|
+
# }
|
112
|
+
# end
|
113
|
+
#
|
114
|
+
# property :tsv => :array do
|
115
|
+
# info_fields = self.info_fields
|
116
|
+
# fields = [self.source_type, self.target_type].concat info_fields
|
117
|
+
# type = [self.source_type, self.target_type] * "~"
|
118
|
+
# tsv = TSV.setup({}, :key_field => type, :fields => fields, :type => :list, :namespace => self.namespace)
|
119
|
+
# index = index(database)
|
120
|
+
# index.with_unnamed do
|
121
|
+
# index.chunked_values_at(self).each_with_index do |v,i|
|
122
|
+
# p = self[i]
|
123
|
+
# source, _sep, target = p.partition("~")
|
124
|
+
# if info_fields.empty?
|
125
|
+
# tsv[p] = [source, target]
|
126
|
+
# else
|
127
|
+
# tsv[p] = [source, target].concat v
|
128
|
+
# end
|
129
|
+
# end
|
130
|
+
# end
|
131
|
+
# tsv.entity_options = {:namespace => namespace}
|
132
|
+
# knowledge_base.entity_options.each do |type,options|
|
133
|
+
# tsv.entity_options.merge! options
|
134
|
+
# end
|
135
|
+
# tsv
|
136
|
+
# end
|
137
|
+
#
|
138
|
+
# property :filter => :array do |*args,&block|
|
139
|
+
# block = args.pop if Proc === args.last
|
140
|
+
# keys = tsv.with_unnamed do tsv.select(*args, &block).keys end
|
141
|
+
# keys = self.annotate keys
|
142
|
+
# keys
|
143
|
+
# end
|
144
|
+
#
|
145
|
+
# def self.incidence(pairs, key_field = nil, &block)
|
146
|
+
# matrix = {}
|
147
|
+
# targets = []
|
148
|
+
# sources = []
|
149
|
+
# matches = {}
|
150
|
+
#
|
151
|
+
# pairs.inject([]){|acc,m| acc << m; acc << m.invert if m.respond_to?(:undirected) and m.undirected; acc }.each do |p|
|
152
|
+
# s, sep, t = p.partition "~"
|
153
|
+
#
|
154
|
+
# sources << s
|
155
|
+
# targets << t
|
156
|
+
# if block_given?
|
157
|
+
# matches[s] ||= Hash.new{nil}
|
158
|
+
# value = block.call p
|
159
|
+
# matches[s][t] = value unless value.nil? or (mv = matches[s][t] and value > mv)
|
160
|
+
# else
|
161
|
+
# matches[s] ||= Hash.new{false}
|
162
|
+
# matches[s][t] ||= true
|
163
|
+
# end
|
164
|
+
# end
|
165
|
+
#
|
166
|
+
# sources.uniq!
|
167
|
+
# targets = targets.uniq.sort
|
168
|
+
#
|
169
|
+
# matches.each do |s,hash|
|
170
|
+
# matrix[s] = hash.values_at(*targets)
|
171
|
+
# end
|
172
|
+
#
|
173
|
+
# defined?(TSV)? TSV.setup(matrix, :key_field => (key_field || "Source") , :fields => targets, :type => :list) : matrix
|
174
|
+
# end
|
175
|
+
#
|
176
|
+
# def self.adjacency(pairs, key_field = nil, &block)
|
177
|
+
# incidence = incidence(pairs, key_field, &block)
|
178
|
+
#
|
179
|
+
# targets = incidence.fields
|
180
|
+
# adjacency = TSV.setup({}, :key_field => incidence.key_field, :fields => ["Target"], :type => :double)
|
181
|
+
# TSV.traverse incidence, :into => adjacency, :unnamed => true do |k,values|
|
182
|
+
# target_values = targets.zip(values).reject{|t,v| v.nil? }.collect{|t,v| [t,v]}
|
183
|
+
# next if target_values.empty?
|
184
|
+
# [k, Misc.zip_fields(target_values)]
|
185
|
+
# end
|
186
|
+
# end
|
187
|
+
#
|
188
|
+
# def self._select_match(orig, elem)
|
189
|
+
# if Array === orig and Array === elem
|
190
|
+
# (orig & elem).any?
|
191
|
+
# elsif Array === orig
|
192
|
+
# orig.include? elem
|
193
|
+
# elsif Array === elem
|
194
|
+
# elem.include? orig
|
195
|
+
# else
|
196
|
+
# elem === orif
|
197
|
+
# end
|
198
|
+
# false
|
199
|
+
# end
|
200
|
+
#
|
201
|
+
# def self.select(list, method = nil, &block)
|
202
|
+
# if method and method.any?
|
203
|
+
# list.select do |item|
|
204
|
+
# method.collect do |key,value|
|
205
|
+
# case key
|
206
|
+
# when :target
|
207
|
+
# _select_match item.target, value
|
208
|
+
# when :source
|
209
|
+
# _select_match item.source, value
|
210
|
+
# else
|
211
|
+
# orig = item.info[key]
|
212
|
+
# orig = orig.split(";;") if String orig
|
213
|
+
# _select_match orig, value
|
214
|
+
# end
|
215
|
+
# end
|
216
|
+
# end
|
217
|
+
# else
|
218
|
+
# list.select(&block)
|
219
|
+
# end
|
220
|
+
# end
|
221
|
+
#end
|
222
|
+
#
|
223
|
+
#module TSV
|
224
|
+
# def self.incidence(tsv)
|
225
|
+
# AssociationItem.incidence Association.index(tsv, :persist => false).keys
|
226
|
+
# end
|
227
|
+
#end
|
@@ -1,35 +1,36 @@
|
|
1
|
-
require 'rbbt/association/database'
|
1
|
+
#require 'rbbt/association/database'
|
2
2
|
|
3
|
-
module Association
|
4
|
-
def self.version_file(file, namespace)
|
5
|
-
old_file, file = file, file.sub('NAMESPACE', namespace) if namespace and String === file
|
6
|
-
old_file.annotate file if Path === old_file
|
7
|
-
file
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.open(file, options = nil, persist_options = nil)
|
11
|
-
options = options.nil? ? {} : options.dup
|
12
|
-
persist_options = persist_options.nil? ?
|
13
|
-
|
14
|
-
options =
|
15
|
-
options[:zipped] = false unless options[:merge]
|
16
|
-
persist_options =
|
17
|
-
persist = persist_options[:persist]
|
18
|
-
|
19
|
-
file = version_file(file, options[:namespace]) if options[:namespace] and String === file
|
20
|
-
|
21
|
-
data = Persist.persist_tsv(file, nil, options, persist_options.merge(:prefix => "Association Database")) do |data|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
data
|
33
|
-
|
34
|
-
|
35
|
-
|
3
|
+
#module Association
|
4
|
+
# def self.version_file(file, namespace)
|
5
|
+
# old_file, file = file, file.sub('NAMESPACE', namespace) if namespace and String === file
|
6
|
+
# old_file.annotate file if Path === old_file
|
7
|
+
# file
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# def self.open(file, options = nil, persist_options = nil)
|
11
|
+
# options = options.nil? ? {} : options.dup
|
12
|
+
# persist_options = persist_options.nil? ? IndiferentHash.pull_keys(options, :persist) : persist_options.dup
|
13
|
+
#
|
14
|
+
# options = IndiferentHash.add_defaults options, :zipped => true, :merge => true, :monitor => {:desc => "Opening database #{Log.fingerprint file}"}
|
15
|
+
# options[:zipped] = false unless options[:merge]
|
16
|
+
# persist_options = IndiferentHash.add_defaults persist_options.dup, :persist => true, :dir => Rbbt.var.associations
|
17
|
+
# persist = persist_options[:persist]
|
18
|
+
#
|
19
|
+
# file = version_file(file, options[:namespace]) if options[:namespace] and String === file
|
20
|
+
#
|
21
|
+
# data = Persist.persist_tsv(file, nil, options, persist_options.merge(:prefix => "Association Database")) do |data|
|
22
|
+
# data = {} if data.nil?
|
23
|
+
# file = file.call if Proc === file
|
24
|
+
#
|
25
|
+
# options = options.dup
|
26
|
+
# data.serializer = :double if data.respond_to? :serializer
|
27
|
+
#
|
28
|
+
# tsv = Association.database(file, options.merge(:unnamed => true, :data => data, :type => :double))
|
29
|
+
#
|
30
|
+
# data
|
31
|
+
# end
|
32
|
+
# data.entity_options = options[:entity_options] if options[:entity_options]
|
33
|
+
# data
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
#end
|