rbbt-util 5.26.171 → 5.27.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/annotations.rb +2 -1
- data/lib/rbbt/annotations/util.rb +7 -6
- data/lib/rbbt/entity.rb +55 -2
- data/lib/rbbt/persist.rb +1 -0
- data/share/rbbt_commands/tsv/get +2 -1
- data/share/rbbt_commands/tsv/read +1 -0
- data/test/rbbt/annotations/test_util.rb +1 -1
- data/test/rbbt/test_annotations.rb +5 -5
- data/test/rbbt/test_entity.rb +51 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce00e5bba751f062a2cf055c1b0e5d937936a452c6edb6eed6da174aadeaa111
|
4
|
+
data.tar.gz: a54bc18f2cc45f0879151f44904ab312cbba26eddeed5a68f592ccd667258d0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86fd735a87478a1c37ea38eb075d76093db55178f5c6aae7d97a3b7fe70e68df82774ec830f7e6f55e1370df60df6cfe6312a42220af389876263669eb966aa4
|
7
|
+
data.tar.gz: 9facd461d8a5d6f8f549310df3257be39d9cc939abf2a36dcb2eb45e7c48c65d3aae09e269efc50fb67fc4e574dc9c801b9111986ae3b9483c53c3015631e463
|
data/lib/rbbt/annotations.rb
CHANGED
@@ -120,7 +120,7 @@ module Annotated
|
|
120
120
|
if object.instance_variables.include?(:@annotation_values)
|
121
121
|
hash = {}
|
122
122
|
object.instance_variable_get(:@annotation_values).each{|k,v| hash[k] = v}
|
123
|
-
self.annotation_values.each{|k,v| hash[k] = v}
|
123
|
+
self.annotation_values.each{|k,v| hash[k] = v unless v.nil?}
|
124
124
|
|
125
125
|
object.instance_variable_set(:@annotation_values, hash)
|
126
126
|
object.instance_variable_set(:@shared_annotations, false)
|
@@ -289,6 +289,7 @@ module Annotation
|
|
289
289
|
object.instance_variable_set(:@annotation_types, nil)
|
290
290
|
|
291
291
|
if Hash === (hash = values.last)
|
292
|
+
setup_positional(object, *values[0..-2]) if values.length > 1
|
292
293
|
clean_and_setup_hash(object, hash)
|
293
294
|
else
|
294
295
|
setup_positional(object, *values)
|
@@ -115,19 +115,21 @@ module Annotated
|
|
115
115
|
|
116
116
|
fields = case
|
117
117
|
|
118
|
-
when ((fields.compact.empty?)
|
118
|
+
when ((fields.compact.empty?) && ! annotations.empty?)
|
119
119
|
fields = AnnotatedArray === annotations ? annotations.annotations : annotations.compact.first.annotations
|
120
120
|
fields << :annotation_types
|
121
121
|
|
122
122
|
when (fields == [:literal] and not annotations.compact.empty?)
|
123
123
|
fields << :literal
|
124
124
|
|
125
|
-
when (fields == [:all]
|
126
|
-
|
125
|
+
when (fields == [:all] && Annotated === annotations)
|
126
|
+
annotation_names = annotations.annotations
|
127
|
+
annotation_names += annotations.first.annotations if Annotated === annotations.first
|
128
|
+
fields = [:annotation_types] + annotation_names.uniq
|
127
129
|
fields << :annotated_array if AnnotatedArray === annotations
|
128
130
|
fields << :literal
|
129
131
|
|
130
|
-
when (fields == [:all]
|
132
|
+
when (fields == [:all] && ! annotations.compact.empty?)
|
131
133
|
raise "Input array must be annotated or its elements must be" if not Annotated === annotations.compact.first and not Array === annotations.compact.first
|
132
134
|
raise "Input array must be annotated or its elements must be. No double arrays of singly annotated entities." if not Annotated === annotations.compact.first and Array === annotations.compact.first
|
133
135
|
fields = [:annotation_types] + (Annotated === annotations ?
|
@@ -157,12 +159,11 @@ module Annotated
|
|
157
159
|
tsv = TSV.setup({}, :key_field => "ID", :fields => fields, :type => :list, :unnamed => true)
|
158
160
|
|
159
161
|
annotations.compact.each_with_index do |annotation,i|
|
160
|
-
tsv[annotation.id + "
|
162
|
+
tsv[annotation.id + "#" << i.to_s] = annotation.tsv_values(*fields).dup
|
161
163
|
end
|
162
164
|
|
163
165
|
else
|
164
166
|
raise "Annotations need to be an Array to create TSV"
|
165
|
-
|
166
167
|
end
|
167
168
|
|
168
169
|
tsv
|
data/lib/rbbt/entity.rb
CHANGED
@@ -5,6 +5,8 @@ module Entity
|
|
5
5
|
|
6
6
|
UNPERSISTED_PREFIX = "entity_unpersisted_property_"
|
7
7
|
|
8
|
+
class MultipleEntity < Exception; end
|
9
|
+
|
8
10
|
class DontPersist < Exception
|
9
11
|
attr_accessor :payload
|
10
12
|
def self.initialize(payload)
|
@@ -170,7 +172,7 @@ module Entity
|
|
170
172
|
when :array, :array2single
|
171
173
|
ary_name = "_ary_" << name
|
172
174
|
define_method ary_name, &block
|
173
|
-
|
175
|
+
|
174
176
|
define_method name do |*args|
|
175
177
|
case
|
176
178
|
when Array === self
|
@@ -188,6 +190,53 @@ module Entity
|
|
188
190
|
Hash === res ? res[self] : res[0]
|
189
191
|
end
|
190
192
|
end
|
193
|
+
when :multiple
|
194
|
+
multi_name = "_multiple_" << name
|
195
|
+
|
196
|
+
define_method multi_name do
|
197
|
+
if self.instance_variable_get("@multiple_result")
|
198
|
+
return self.instance_variable_get("@multiple_result")
|
199
|
+
end
|
200
|
+
raise MultipleEntity, "Entity #{name} runs with multiple entities: #{self}"
|
201
|
+
end
|
202
|
+
|
203
|
+
define_method name do |*args|
|
204
|
+
obj = if Array === self
|
205
|
+
self
|
206
|
+
elsif self.respond_to?(:container) && Array === self.container
|
207
|
+
self.container
|
208
|
+
else
|
209
|
+
self.make_list
|
210
|
+
end
|
211
|
+
|
212
|
+
missing = []
|
213
|
+
obj.each do |e|
|
214
|
+
begin
|
215
|
+
e.send(multi_name)
|
216
|
+
rescue MultipleEntity
|
217
|
+
missing << e
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
res = missing.any? ? block.call(missing) : nil
|
222
|
+
case res
|
223
|
+
when Array
|
224
|
+
missing.zip(res).each do |o,res|
|
225
|
+
o.instance_variable_set("@multiple_result", res)
|
226
|
+
end
|
227
|
+
when Hash
|
228
|
+
res.each do |o,res|
|
229
|
+
o.instance_variable_set("@multiple_result", res)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
if Array === self
|
234
|
+
self.collect{|o| o.send(multi_name)}
|
235
|
+
else
|
236
|
+
self.send(multi_name)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
191
240
|
else
|
192
241
|
raise "Type not undestood in property: #{ type }"
|
193
242
|
end
|
@@ -200,12 +249,16 @@ module Entity
|
|
200
249
|
options ||= {}
|
201
250
|
options = Misc.add_defaults options, :dir => Entity.entity_property_cache
|
202
251
|
|
252
|
+
orig_method_name = method_name
|
253
|
+
multi_name = "_multiple_" + method_name.to_s
|
254
|
+
method_name = multi_name if self.instance_methods.include?(multi_name.to_sym)
|
255
|
+
|
203
256
|
orig_name = UNPERSISTED_PREFIX + method_name.to_s
|
204
257
|
alias_method orig_name, method_name unless self.instance_methods.include? orig_name.to_sym
|
205
258
|
|
206
259
|
define_method method_name do |*args|
|
207
260
|
id = self.id
|
208
|
-
persist_name =
|
261
|
+
persist_name = orig_method_name.to_s << ":" << (Array === id ? Misc.obj2digest(id) : id)
|
209
262
|
|
210
263
|
persist_options = options
|
211
264
|
persist_options = persist_options.merge(:other => {:args => args}) if args and args.any?
|
data/lib/rbbt/persist.rb
CHANGED
@@ -402,6 +402,7 @@ module Persist
|
|
402
402
|
subkey = name + ":"
|
403
403
|
|
404
404
|
if String === repo
|
405
|
+
repo = repo.find if Path === repo
|
405
406
|
repo = Persist.open_tokyocabinet(repo, false, :list, "BDB")
|
406
407
|
repo.read_and_close do
|
407
408
|
keys = repo.range subkey + 0.chr, true, subkey + 254.chr, true
|
data/share/rbbt_commands/tsv/get
CHANGED
@@ -14,6 +14,7 @@ Use - to read from STDIN
|
|
14
14
|
-tch--tokyocabinet File is a tokyocabinet hash database
|
15
15
|
-tcb--tokyocabinet_bd File is a tokyocabinet B database
|
16
16
|
-f--fields* Fields to extract
|
17
|
+
-s--sep* Separation character
|
17
18
|
-hh--header_hash* Change the character used to mark the header line (defaults to #)
|
18
19
|
-k--key_field* Use this field as key
|
19
20
|
-h--help Print this help
|
@@ -46,7 +47,7 @@ fields = options[:fields]
|
|
46
47
|
key_field = options[:key_field]
|
47
48
|
fields = fields.split(/[,|]/, -1) unless fields.nil?
|
48
49
|
|
49
|
-
parser = TSV::Parser.new tsv, :key_field => key_field, :fields => fields, :type => options[:type], :header_hash => options[:header_hash]
|
50
|
+
parser = TSV::Parser.new tsv, :key_field => key_field, :fields => fields, :type => options[:type], :header_hash => options[:header_hash], :sep => options[:sep]
|
50
51
|
fields ||= parser.fields
|
51
52
|
|
52
53
|
TSV.traverse(parser) do |k,v|
|
@@ -77,11 +77,11 @@ class TestAnnotations < Test::Unit::TestCase
|
|
77
77
|
AnnotatedString.setup(str1, annotation_str1)
|
78
78
|
AnnotatedString.setup(str2, annotation_str2)
|
79
79
|
|
80
|
-
assert_equal str1, Annotated.tsv([str1, str2], :all).tap{|t| t.unnamed = false}[str1.id + "
|
81
|
-
assert_equal annotation_str1, Annotated.tsv([str1, str2], :all).tap{|t| t.unnamed = false}[str1.id + "
|
82
|
-
assert_equal str1, Annotated.tsv([str1, str2], :all).tap{|t| t.unnamed = false}[str1.id + "
|
83
|
-
assert_equal annotation_str1, Annotated.tsv([str1, str2], :all).tap{|t| t.unnamed = false}[str1.id + "
|
84
|
-
assert_equal annotation_str1, Annotated.tsv([str1, str2], :annotation_str, :JSON).tap{|t| t.unnamed = false}[str1.id + "
|
80
|
+
assert_equal str1, Annotated.tsv([str1, str2], :all).tap{|t| t.unnamed = false}[str1.id + "#0"]["literal"]
|
81
|
+
assert_equal annotation_str1, Annotated.tsv([str1, str2], :all).tap{|t| t.unnamed = false}[str1.id + "#0"]["annotation_str"]
|
82
|
+
assert_equal str1, Annotated.tsv([str1, str2], :all).tap{|t| t.unnamed = false}[str1.id + "#0"]["literal"]
|
83
|
+
assert_equal annotation_str1, Annotated.tsv([str1, str2], :all).tap{|t| t.unnamed = false}[str1.id + "#0"]["annotation_str"]
|
84
|
+
assert_equal annotation_str1, Annotated.tsv([str1, str2], :annotation_str, :JSON).tap{|t| t.unnamed = false}[str1.id + "#0"]["annotation_str"]
|
85
85
|
end
|
86
86
|
|
87
87
|
def test_literal
|
data/test/rbbt/test_entity.rb
CHANGED
@@ -59,6 +59,19 @@ module ReversableString
|
|
59
59
|
persist :reverse_text_ary_p_array, :array, :dir => TmpFile.tmp_file
|
60
60
|
|
61
61
|
persist :annotation_list, :annotations, :dir => TmpFile.tmp_file
|
62
|
+
|
63
|
+
|
64
|
+
$processed_multiple = []
|
65
|
+
property :multiple_annotation_list => :multiple do |list|
|
66
|
+
$processed_multiple.concat list
|
67
|
+
res = {}
|
68
|
+
list.collect do |e|
|
69
|
+
e.chars.to_a.collect{|c|
|
70
|
+
ReversableString.setup(c)
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
persist :multiple_annotation_list, :annotations, :dir => TmpFile.tmp_file
|
62
75
|
end
|
63
76
|
|
64
77
|
class TestEntity < Test::Unit::TestCase
|
@@ -174,6 +187,42 @@ class TestEntity < Test::Unit::TestCase
|
|
174
187
|
assert_equal string.length, string.annotation_list.length
|
175
188
|
end
|
176
189
|
|
190
|
+
def test_persist_multiple_annotations
|
191
|
+
string1 = 'aaabbbccc'
|
192
|
+
string2 = 'AAABBBCCC'
|
193
|
+
string3 = 'AAABBBCCC_3'
|
194
|
+
string4 = 'AAABBBCCC_4'
|
195
|
+
|
196
|
+
array = ReversableString.setup([string1, string2])
|
197
|
+
assert_equal [string1, string2].collect{|s| s.chars}, array.multiple_annotation_list
|
198
|
+
|
199
|
+
assert_equal string1.length, array[0].multiple_annotation_list.length
|
200
|
+
assert_equal $processed_multiple, [string1, string2]
|
201
|
+
|
202
|
+
array = ReversableString.setup([string2, string3])
|
203
|
+
assert_equal string2.length, array[0].multiple_annotation_list.length
|
204
|
+
assert_equal $processed_multiple, [string1, string2, string3]
|
205
|
+
|
206
|
+
array = ReversableString.setup([string2, string3])
|
207
|
+
assert_equal string2.length, array[0].multiple_annotation_list.length
|
208
|
+
assert_equal $processed_multiple, [string1, string2, string3]
|
209
|
+
|
210
|
+
$processed_multiple = []
|
211
|
+
array = ReversableString.setup([string2, string3, string4])
|
212
|
+
assert_equal string2.length, array[0].multiple_annotation_list.length
|
213
|
+
assert_equal $processed_multiple, [string4]
|
214
|
+
|
215
|
+
string1 = 'aaabbbccc'
|
216
|
+
string2 = 'AAABBBCCC'
|
217
|
+
string3 = 'AAABBBCCC_3'
|
218
|
+
string4 = 'AAABBBCCC_4'
|
219
|
+
$processed_multiple = []
|
220
|
+
array = ReversableString.setup([string2, string3, string4])
|
221
|
+
assert_equal string2.length, array[0].multiple_annotation_list.length
|
222
|
+
assert_equal $processed_multiple, [string4]
|
223
|
+
|
224
|
+
end
|
225
|
+
|
177
226
|
def test_clean_annotations
|
178
227
|
|
179
228
|
string = "test_string"
|
@@ -184,7 +233,7 @@ class TestEntity < Test::Unit::TestCase
|
|
184
233
|
end
|
185
234
|
|
186
235
|
def test_all_properties
|
187
|
-
|
188
|
-
|
236
|
+
assert ReversableString.setup("TEST").all_properties.include?("reverse_text_ary")
|
237
|
+
assert_equal ReversableString.setup("TEST").all_properties, ReversableString.all_properties
|
189
238
|
end
|
190
239
|
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.
|
4
|
+
version: 5.27.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|