scout-gear 10.7.2 → 10.7.4

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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +47 -32
  3. data/VERSION +1 -1
  4. data/bin/scout +15 -2
  5. data/lib/scout/association/index.rb +4 -0
  6. data/lib/scout/association/item.rb +1 -1
  7. data/lib/scout/association.rb +32 -10
  8. data/lib/scout/entity/identifiers.rb +2 -2
  9. data/lib/scout/entity/property.rb +2 -2
  10. data/lib/scout/knowledge_base/enrichment.rb +9 -0
  11. data/lib/scout/knowledge_base/entity.rb +152 -0
  12. data/lib/scout/knowledge_base/list.rb +95 -0
  13. data/lib/scout/knowledge_base/query.rb +96 -0
  14. data/lib/scout/knowledge_base/registry.rb +175 -0
  15. data/lib/scout/knowledge_base/traverse.rb +329 -0
  16. data/lib/scout/knowledge_base.rb +91 -0
  17. data/lib/scout/persist/engine/tokyocabinet.rb +85 -77
  18. data/lib/scout/persist/tsv/adapter/base.rb +8 -22
  19. data/lib/scout/tsv/annotation.rb +4 -4
  20. data/lib/scout/tsv/index.rb +0 -2
  21. data/lib/scout/tsv/parser.rb +11 -1
  22. data/lib/scout/tsv/stream.rb +3 -3
  23. data/lib/scout/tsv/transformer.rb +12 -0
  24. data/lib/scout/tsv/util/process.rb +2 -2
  25. data/lib/scout/tsv.rb +2 -0
  26. data/lib/scout/workflow/definition.rb +6 -2
  27. data/lib/scout/workflow/deployment/trace.rb +1 -1
  28. data/lib/scout/workflow/step/dependencies.rb +3 -6
  29. data/lib/scout/workflow/step/info.rb +17 -3
  30. data/lib/scout/workflow/task/info.rb +99 -0
  31. data/lib/scout/workflow/task.rb +1 -0
  32. data/scout-gear.gemspec +27 -7
  33. data/scout_commands/doc +3 -3
  34. data/scout_commands/kb/config +33 -0
  35. data/scout_commands/kb/entities +35 -0
  36. data/scout_commands/kb/list +39 -0
  37. data/scout_commands/{db → kb}/query +6 -11
  38. data/scout_commands/{db → kb}/register +9 -8
  39. data/scout_commands/{db → kb}/show +6 -16
  40. data/scout_commands/kb/traverse +66 -0
  41. data/scout_commands/workflow/task +7 -2
  42. data/test/data/person/brothers +1 -1
  43. data/test/scout/entity/test_identifiers.rb +3 -3
  44. data/test/scout/knowledge_base/test_enrichment.rb +0 -0
  45. data/test/scout/knowledge_base/test_entity.rb +38 -0
  46. data/test/scout/knowledge_base/test_list.rb +40 -0
  47. data/test/scout/knowledge_base/test_query.rb +39 -0
  48. data/test/scout/knowledge_base/test_registry.rb +35 -0
  49. data/test/scout/knowledge_base/test_traverse.rb +245 -0
  50. data/test/scout/persist/test_tsv.rb +1 -0
  51. data/test/scout/test_association.rb +32 -3
  52. data/test/scout/test_entity.rb +0 -15
  53. data/test/scout/test_knowledge_base.rb +27 -0
  54. data/test/scout/test_tsv.rb +15 -0
  55. data/test/scout/tsv/test_parser.rb +4 -0
  56. data/test/scout/tsv/test_transformer.rb +13 -0
  57. data/test/scout/workflow/step/test_info.rb +11 -0
  58. data/test/scout/workflow/task/test_info.rb +22 -0
  59. data/test/test_helper.rb +17 -0
  60. metadata +26 -9
data/scout-gear.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: scout-gear 10.7.2 ruby lib
5
+ # stub: scout-gear 10.7.4 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "scout-gear".freeze
9
- s.version = "10.7.2".freeze
9
+ s.version = "10.7.4".freeze
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Miguel Vazquez".freeze]
14
- s.date = "2024-12-10"
14
+ s.date = "2025-03-10"
15
15
  s.description = "Temporary files, logs, path, resources, persistence, workflows, TSV, etc.".freeze
16
16
  s.email = "mikisvaz@gmail.com".freeze
17
17
  s.executables = ["scout".freeze]
@@ -44,6 +44,13 @@ Gem::Specification.new do |s|
44
44
  "lib/scout/entity/named_array.rb",
45
45
  "lib/scout/entity/object.rb",
46
46
  "lib/scout/entity/property.rb",
47
+ "lib/scout/knowledge_base.rb",
48
+ "lib/scout/knowledge_base/enrichment.rb",
49
+ "lib/scout/knowledge_base/entity.rb",
50
+ "lib/scout/knowledge_base/list.rb",
51
+ "lib/scout/knowledge_base/query.rb",
52
+ "lib/scout/knowledge_base/registry.rb",
53
+ "lib/scout/knowledge_base/traverse.rb",
47
54
  "lib/scout/offsite.rb",
48
55
  "lib/scout/offsite/exceptions.rb",
49
56
  "lib/scout/offsite/ssh.rb",
@@ -114,6 +121,7 @@ Gem::Specification.new do |s|
114
121
  "lib/scout/workflow/step/status.rb",
115
122
  "lib/scout/workflow/task.rb",
116
123
  "lib/scout/workflow/task/dependencies.rb",
124
+ "lib/scout/workflow/task/info.rb",
117
125
  "lib/scout/workflow/task/inputs.rb",
118
126
  "lib/scout/workflow/usage.rb",
119
127
  "lib/scout/workflow/util.rb",
@@ -122,12 +130,16 @@ Gem::Specification.new do |s|
122
130
  "scout_commands/alias",
123
131
  "scout_commands/batch/clean",
124
132
  "scout_commands/batch/list",
125
- "scout_commands/db/query",
126
- "scout_commands/db/register",
127
- "scout_commands/db/show",
128
133
  "scout_commands/doc",
129
134
  "scout_commands/find",
130
135
  "scout_commands/glob",
136
+ "scout_commands/kb/config",
137
+ "scout_commands/kb/entities",
138
+ "scout_commands/kb/list",
139
+ "scout_commands/kb/query",
140
+ "scout_commands/kb/register",
141
+ "scout_commands/kb/show",
142
+ "scout_commands/kb/traverse",
131
143
  "scout_commands/log",
132
144
  "scout_commands/offsite",
133
145
  "scout_commands/rbbt",
@@ -158,6 +170,12 @@ Gem::Specification.new do |s|
158
170
  "test/scout/entity/test_named_array.rb",
159
171
  "test/scout/entity/test_object.rb",
160
172
  "test/scout/entity/test_property.rb",
173
+ "test/scout/knowledge_base/test_enrichment.rb",
174
+ "test/scout/knowledge_base/test_entity.rb",
175
+ "test/scout/knowledge_base/test_list.rb",
176
+ "test/scout/knowledge_base/test_query.rb",
177
+ "test/scout/knowledge_base/test_registry.rb",
178
+ "test/scout/knowledge_base/test_traverse.rb",
161
179
  "test/scout/offsite/test_ssh.rb",
162
180
  "test/scout/offsite/test_step.rb",
163
181
  "test/scout/offsite/test_sync.rb",
@@ -178,6 +196,7 @@ Gem::Specification.new do |s|
178
196
  "test/scout/persist/tsv/test_serialize.rb",
179
197
  "test/scout/test_association.rb",
180
198
  "test/scout/test_entity.rb",
199
+ "test/scout/test_knowledge_base.rb",
181
200
  "test/scout/test_offsite.rb",
182
201
  "test/scout/test_semaphore.rb",
183
202
  "test/scout/test_tsv.rb",
@@ -217,6 +236,7 @@ Gem::Specification.new do |s|
217
236
  "test/scout/workflow/step/test_provenance.rb",
218
237
  "test/scout/workflow/step/test_status.rb",
219
238
  "test/scout/workflow/task/test_dependencies.rb",
239
+ "test/scout/workflow/task/test_info.rb",
220
240
  "test/scout/workflow/task/test_inputs.rb",
221
241
  "test/scout/workflow/test_definition.rb",
222
242
  "test/scout/workflow/test_documentation.rb",
@@ -231,7 +251,7 @@ Gem::Specification.new do |s|
231
251
  ]
232
252
  s.homepage = "http://github.com/mikisvaz/scout-gear".freeze
233
253
  s.licenses = ["MIT".freeze]
234
- s.rubygems_version = "3.5.23".freeze
254
+ s.rubygems_version = "3.6.5".freeze
235
255
  s.summary = "basic gear for scouts".freeze
236
256
 
237
257
  s.specification_version = 4
data/scout_commands/doc CHANGED
@@ -26,12 +26,12 @@ end
26
26
 
27
27
  module_name = ARGV.first
28
28
  if module_name.nil?
29
- puts Rbbt.doc.lib.scout.glob("**/*.md").collect{|f| File.basename(f.unset_extension) } * "\n"
29
+ puts Scout.doc.lib.scout.glob("**/*.md").collect{|f| File.basename(f.unset_extension) } * "\n"
30
30
  else
31
31
  begin
32
- puts Rbbt.doc.lib.scout[module_name].find_with_extension('md', :lib).read
32
+ puts Scout.doc.lib.scout[module_name].find_with_extension('md', :lib).read
33
33
  rescue
34
- puts Rbbt.doc.lib.scout.glob("**/*.md").select{|f| File.basename(f.unset_extension) == module_name }.first.read
34
+ puts Scout.doc.lib.scout.glob("**/*.md").select{|f| File.basename(f.unset_extension) == module_name }.first.read
35
35
  end
36
36
  end
37
37
 
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'scout'
4
+ require 'scout/knowledge_base'
5
+
6
+ $0 = "scout #{$previous_commands.any? ? $previous_commands*" " + " " : "" }#{ File.basename(__FILE__) }" if $previous_commands
7
+
8
+ options = SOPT.setup <<EOF
9
+
10
+ Configure a knowlege base
11
+
12
+ $ #{$0} [<options>] <name> [knowledge_base]
13
+
14
+ -h--help Print this help
15
+ -i--identifier_files* Identifier files separated by ','
16
+ -n--namespace* Namespace
17
+ EOF
18
+ if options.delete :help
19
+ if defined? scout_usage
20
+ scout_usage
21
+ else
22
+ puts SOPT.doc
23
+ end
24
+ exit 0
25
+ end
26
+
27
+ knowledge_base_name = ARGV.first
28
+
29
+ knowledge_base = KnowledgeBase.load knowledge_base_name || :default
30
+
31
+ knowledge_base.namespace = options[:namespace] if options.include? :namespace
32
+ knowledge_base.identifier_files += options[:identifier_files].split(",") if options.include? :identifier_files
33
+ knowledge_base.save
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'scout'
4
+ require 'scout/knowledge_base'
5
+
6
+ $0 = "scout #{$previous_commands.any? ? $previous_commands*" " + " " : "" }#{ File.basename(__FILE__) }" if $previous_commands
7
+
8
+ options = SOPT.setup <<EOF
9
+
10
+ Declare a type of entity and assing an identifiers file
11
+
12
+ $ #{$0} [<options>] <entity> <identifier_files>
13
+
14
+ -h--help Print this help
15
+ -kb--knowledge_base* Knowlege base name (or :default)
16
+ EOF
17
+ if options.delete :help
18
+ if defined? scout_usage
19
+ scout_usage
20
+ else
21
+ puts SOPT.doc
22
+ end
23
+ exit 0
24
+ end
25
+
26
+ entity, identifier_files = ARGV
27
+
28
+ knowledge_base = KnowledgeBase.load options[:knowledge_base] || :default
29
+
30
+ knowledge_base.entity_options[entity] ||= {}
31
+ knowledge_base.entity_options[entity][:identifiers] ||= []
32
+ knowledge_base.entity_options[entity][:identifiers] = [knowledge_base.entity_options[entity][:identifiers]] unless Array === knowledge_base.entity_options[entity][:identifiers]
33
+ knowledge_base.entity_options[entity][:identifiers] += identifier_files.split(",")
34
+ knowledge_base.entity_options[entity][:identifiers].uniq!
35
+ knowledge_base.save
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'scout'
4
+ require 'scout/knowledge_base'
5
+
6
+ $0 = "scout #{$previous_commands.any? ? $previous_commands*" " + " " : "" }#{ File.basename(__FILE__) }" if $previous_commands
7
+
8
+ options = SOPT.setup <<EOF
9
+
10
+ Description of the tool
11
+
12
+ $ #{$0} [<options>] <filename> [<other|->]*
13
+
14
+ -h--help Print this help
15
+ EOF
16
+ if options[:help]
17
+ if defined? scout_usage
18
+ scout_usage
19
+ else
20
+ puts SOPT.doc
21
+ end
22
+ exit 0
23
+ end
24
+
25
+ knowledge_base = KnowledgeBase.load options[:knowledge_base] || :default
26
+ knowledge_base.define_entity_modules
27
+
28
+ list_name = ARGV.first
29
+
30
+ if list_name.nil?
31
+ knowledge_base.lists.each do |type,lists|
32
+ puts Log.color :title, type
33
+ puts lists * "\n"
34
+ end
35
+ else
36
+ list = knowledge_base.load_list(list_name)
37
+
38
+ puts list * "\n"
39
+ end
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'scout'
4
- require 'scout/association'
4
+ require 'scout/knowledge_base'
5
5
 
6
6
  $0 = "scout #{$previous_commands.any? ? $previous_commands*" " + " " : "" }#{ File.basename(__FILE__) }" if $previous_commands
7
7
 
@@ -12,6 +12,7 @@ Query a database
12
12
  $ #{$0} [<options>] <name> <entity>
13
13
 
14
14
  -h--help Print this help
15
+ -kb--knowledge_base* Knowlege base name (or :default)
15
16
  -l--list Only list matches
16
17
  -s--source* Source description
17
18
  -t--target* Target description
@@ -32,23 +33,17 @@ name, entity = ARGV
32
33
  raise MissingParameterException, :name if name.nil?
33
34
  raise MissingParameterException, :entity if entity.nil?
34
35
 
35
- registry = begin
36
- Scout.var.databases.registry.yaml
37
- rescue
38
- {}
39
- end
40
36
 
41
- list = IndiferentHash.process_options options, :list
37
+ knowledge_base = KnowledgeBase.load options[:knowledge_base] || :default
42
38
 
43
- raise ParameterException "Database #{name} not found Options: #{Log.fingerprint registry.keys}" unless registry.include? name
39
+ list = IndiferentHash.process_options options, :list
44
40
 
45
- file, db_options = registry[name]
46
- options = db_options.merge(options)
41
+ raise ParameterException "Database #{name} not found Options: #{Log.fingerprint knowledge_base.all_databases.keys}" unless knowledge_base.include? name
47
42
 
48
43
  IndiferentHash.setup(options)
49
44
  options.keys_to_sym!
50
45
 
51
- index = Association.index(file, **options)
46
+ index = knowledge_base.get_index(name, options)
52
47
 
53
48
  if entity.end_with?("~")
54
49
  matches = index.match(entity[0..-2])
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'scout'
4
+ require 'scout/knowledge_base'
4
5
 
5
6
  $0 = "scout #{$previous_commands.any? ? $previous_commands*" " + " " : "" }#{ File.basename(__FILE__) }" if $previous_commands
6
7
 
@@ -11,10 +12,13 @@ Register a database
11
12
  $ #{$0} [<options>] <name> <filename>
12
13
 
13
14
  -h--help Print this help
15
+ -kb--knowledge_base* Knowlege base name (or :default)
14
16
  -s--source* Source description
15
17
  -t--target* Target description
18
+ -f--fields* Fields to consider
16
19
  -n--namespace* Namespace
17
20
  -i--identifiers* Identifiers
21
+ -u--undirected
18
22
  EOF
19
23
  if options.delete :help
20
24
  if defined? scout_usage
@@ -27,17 +31,14 @@ end
27
31
 
28
32
  name, file = ARGV
29
33
 
34
+
30
35
  raise MissingParameterException, :name if name.nil?
31
36
  raise MissingParameterException, :file if file.nil?
32
37
 
33
- registry = begin
34
- Scout.var.databases.registry.yaml
35
- rescue
36
- {}
37
- end
38
+ knowledge_base = KnowledgeBase.load options[:knowledge_base] || :default
38
39
 
40
+ options[:fields] = options[:fields].split(/,\s*/) if options[:fields]
39
41
  file = Scout.identify(File.expand_path(file))
40
- registry[name] = [Scout.identify(file), options]
41
-
42
- Scout.var.databases.registry.write(registry.to_yaml)
42
+ knowledge_base.register name, Scout.identify(file), options
43
43
 
44
+ knowledge_base.save
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'scout'
4
- require 'scout/association'
4
+ require 'scout/knowledge_base'
5
5
 
6
6
  $0 = "scout #{$previous_commands.any? ? $previous_commands*" " + " " : "" }#{ File.basename(__FILE__) }" if $previous_commands
7
7
 
@@ -12,6 +12,7 @@ Show a database
12
12
  $ #{$0} [<options>] <name>
13
13
 
14
14
  -h--help Print this help
15
+ -kb--knowledge_base* Knowlege base name (or :default)
15
16
  EOF
16
17
  if options[:help]
17
18
  if defined? scout_usage
@@ -22,26 +23,15 @@ if options[:help]
22
23
  exit 0
23
24
  end
24
25
 
25
-
26
- registry = begin
27
- Scout.var.databases.registry.yaml
28
- rescue
29
- {}
30
- end
26
+ knowledge_base = KnowledgeBase.load options[:knowledge_base] || :default
31
27
 
32
28
  name = ARGV.first
33
29
 
34
30
  if name.nil?
35
- puts registry.keys * "\n"
36
-
31
+ puts knowledge_base.all_databases * "\n"
37
32
  else
38
33
 
39
- raise ParameterException "Database #{name} not found Options: #{Log.fingerprint registry.keys}" unless registry.include? name
40
-
41
- file, options = registry[name]
42
-
43
- IndiferentHash.setup(options)
44
- options.keys_to_sym!
34
+ raise ParameterException "Database #{name} not found Options: #{Log.fingerprint knowledge_base.all_databases}" unless knowledge_base.include? name
45
35
 
46
- Log.tsv Association.database(file, **options)
36
+ Log.tsv knowledge_base.get_database(name, options)
47
37
  end
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'scout'
4
+ require 'scout/knowledge_base'
5
+
6
+ $0 = "scout #{$previous_commands.any? ? $previous_commands*" " + " " : "" }#{ File.basename(__FILE__) }" if $previous_commands
7
+
8
+ options = SOPT.setup <<EOF
9
+
10
+ Traverse databases
11
+
12
+ $ #{$0} [<options>] <traversal>
13
+
14
+ -h--help Print this help
15
+ -kb--knowledge_base* Knowlege base name (or :default)
16
+ -p--paths Only list paths
17
+ -e--entities Only list entities
18
+ -l--list* List entities matching capture
19
+ -ln--list_name* Save list of matches with a name
20
+ EOF
21
+ if options[:help]
22
+ if defined? scout_usage
23
+ scout_usage
24
+ else
25
+ puts SOPT.doc
26
+ end
27
+ exit 0
28
+ end
29
+
30
+ traversal = ARGV.first
31
+
32
+ raise MissingParameterException, :traversal if traversal.nil?
33
+
34
+ knowledge_base = KnowledgeBase.load options[:knowledge_base] || :default
35
+
36
+ only_paths, only_entities, list, list_name = IndiferentHash.process_options options, :paths, :entities, :list, :list_name
37
+
38
+ rules = traversal.split(/,\s*/)
39
+
40
+ knowledge_base.define_entity_modules
41
+
42
+ entities, paths = knowledge_base.traverse(rules, only_entities || list)
43
+
44
+ if list
45
+ entity_list = entities["?" + list] || []
46
+ puts entity_list * "\n"
47
+ knowledge_base.save_list list_name, entity_list if list_name
48
+ else
49
+ paths = nil if only_entities && ! only_paths
50
+ entities = nil if only_paths && ! only_entities
51
+
52
+ if entities
53
+ entities.each do |type,list|
54
+ puts Log.color(:magenta, type[1..-1] + ": ") + Log.fingerprint(list * ", ")
55
+ end
56
+ end
57
+
58
+ if paths
59
+ paths.each do |path_list|
60
+ path_list.each do |match|
61
+ puts Log.color :magenta, (match.reverse ? match.invert : match)
62
+ puts IndiferentHash.setup(match.info).prety_print if match.info && match.info.any?
63
+ end
64
+ end
65
+ end
66
+ end
@@ -19,6 +19,7 @@ $ #{$0} [<options>] <workflow> <task>
19
19
  --nostream Disable job streaming
20
20
  --update Update jobs with newer dependencies
21
21
  --deploy* Deploy mode: serial, local, or SLURM (default 'serial')
22
+ --fork Fork and return path
22
23
  -jn--jobname* Name to use as job identifier
23
24
  -li--load_inputs* Directory with inputs files to load
24
25
  -pf--printpath Print the file path
@@ -39,8 +40,8 @@ task = workflow.tasks[task_name.to_sym] if task_name
39
40
 
40
41
  options[:help] = true if task.nil?
41
42
 
42
- help, provenance, clean, recursive_clean, clean_task, load_inputs, jobname, printpath, deploy, override_deps = IndiferentHash.process_options options,
43
- :help, :provenance, :clean, :recursive_clean, :clean_task, :load_inputs, :jobname, :printpath, :deploy, :override_deps,
43
+ help, provenance, clean, recursive_clean, clean_task, load_inputs, jobname, printpath, deploy, override_deps, do_fork = IndiferentHash.process_options options,
44
+ :help, :provenance, :clean, :recursive_clean, :clean_task, :load_inputs, :jobname, :printpath, :deploy, :override_deps, :fork,
44
45
  :deploy => 'serial'
45
46
 
46
47
  if help
@@ -92,6 +93,10 @@ end
92
93
 
93
94
  if provenance
94
95
  puts Step.prov_report(job)
96
+ elsif do_fork
97
+ job.fork
98
+ puts job.path
99
+ exit 0
95
100
  else
96
101
  case deploy
97
102
  when "serial"
@@ -1,4 +1,4 @@
1
1
  #: :sep=,#:type=:list
2
- #Older,Younger
2
+ #Older (Alias),Younger (Alias)
3
3
  Clei,Guille
4
4
  Isa,Miki
@@ -16,9 +16,9 @@ class TestEntityIdentifiers < Test::Unit::TestCase
16
16
 
17
17
  Person.add_identifiers datafile_test(Entity::Identified::NAMESPACE_TAG + '/identifiers'), "Name", "Alias"
18
18
 
19
- teardown do
20
- Entity.formats.clear
21
- end
19
+ #teardown do
20
+ # Entity.formats.clear
21
+ #end
22
22
 
23
23
  def test_alias
24
24
  miguel = Person.setup("Miguel", namespace: :person)
File without changes
@@ -0,0 +1,38 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ require 'scout/knowledge_base'
5
+
6
+
7
+ class TestKnowledgeBaseQuery < Test::Unit::TestCase
8
+ def test_types
9
+ TmpFile.with_dir do |dir|
10
+ kb = KnowledgeBase.new dir
11
+ kb.register :brothers, datafile_test(:person).brothers, undirected: true
12
+ kb.register :parents, datafile_test(:person).parents
13
+
14
+ assert_include kb.all_databases, :brothers
15
+
16
+ assert_equal Person, kb.target_type(:parents)
17
+ end
18
+ end
19
+
20
+ def test_options
21
+ TmpFile.with_dir do |dir|
22
+ kb = KnowledgeBase.new dir
23
+ kb.register :brothers, datafile_test(:person).brothers, undirected: true
24
+ kb.entity_options = { "Person" => {language: "es"} }
25
+
26
+ assert_include kb.entity_options_for("Person"), :language
27
+ end
28
+ end
29
+
30
+ def test_identify
31
+ TmpFile.with_dir do |dir|
32
+ kb = KnowledgeBase.new dir
33
+ kb.register :brothers, datafile_test(:person).brothers, undirected: true
34
+
35
+ assert_equal "Miki", kb.identify(:brothers, "001")
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ require 'scout/knowledge_base'
5
+ class TestKnowledgeBaseQuery < Test::Unit::TestCase
6
+ def test_entity_list
7
+ TmpFile.with_dir do |dir|
8
+ kb = KnowledgeBase.new dir
9
+ kb.register :brothers, datafile_test(:person).brothers, undirected: true
10
+ kb.register :parents, datafile_test(:person).parents
11
+
12
+ list = kb.subset(:brothers, :all).target_entity
13
+
14
+ kb.save_list("bro_and_sis", list)
15
+ assert_equal list, kb.load_list("bro_and_sis")
16
+
17
+ assert_include kb.lists["Person"], "bro_and_sis"
18
+ kb.delete_list("bro_and_sis")
19
+
20
+ refute kb.lists["simple"]
21
+ end
22
+ end
23
+
24
+ def test_simple_list
25
+ list = ["Miki", "Isa"]
26
+ TmpFile.with_dir do |dir|
27
+ kb = KnowledgeBase.new dir
28
+
29
+ kb.save_list("bro_and_sis", list)
30
+
31
+ assert_equal list, kb.load_list("bro_and_sis")
32
+
33
+ assert_include kb.lists["simple"], "bro_and_sis"
34
+
35
+ kb.delete_list("bro_and_sis")
36
+
37
+ refute kb.lists["simple"].any?
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ require 'scout/knowledge_base'
5
+
6
+
7
+ class TestKnowledgeBaseQuery < Test::Unit::TestCase
8
+ def test_query
9
+ TmpFile.with_dir do |dir|
10
+ kb = KnowledgeBase.new dir
11
+ kb.entity_options = {"Person" => {language: "es"}}
12
+
13
+ kb.register :brothers, datafile_test(:person).brothers, undirected: true
14
+ kb.register :parents, datafile_test(:person).parents, entity_options: {"Person" => {language: "en"}}
15
+
16
+ assert_include kb.all_databases, :brothers
17
+
18
+ matches = kb.subset(:parents, :all)
19
+ assert_include matches, "Clei~Domingo"
20
+
21
+ matches = kb.subset(:parents, target: :all, source: ["Miki"])
22
+ assert_include matches, "Miki~Juan"
23
+
24
+
25
+ assert_include kb.children(:parents, "Miki").target, "Juan"
26
+ assert_include kb.children(:brothers, "Miki").target, "Isa"
27
+
28
+ parents = matches.target_entity
29
+
30
+ assert_include parents, "Juan"
31
+ assert Person === parents.first
32
+ assert_equal "en", parents.first.language
33
+
34
+
35
+ matches = kb.subset(:brothers, target: :all, source: ["Miki"])
36
+ assert_equal "es", matches.first.source_entity.language
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ require 'scout/knowledge_base'
5
+
6
+ class TestKnowlegeBase < Test::Unit::TestCase
7
+ def test_registry
8
+ TmpFile.with_dir do |dir|
9
+ brothers = datafile_test(:person).brothers
10
+ kb = KnowledgeBase.new dir
11
+ kb.register :brothers, brothers
12
+ assert_include kb.all_databases, :brothers
13
+ end
14
+ end
15
+
16
+ def test_registry_identifiers
17
+ identifier =<<-EOF
18
+ #Alias,Initials
19
+ Clei,CC
20
+ Miki,MV
21
+ Guille,GC
22
+ Isa,IV
23
+ EOF
24
+ TmpFile.with_dir do |dir|
25
+ TmpFile.with_file(identifier) do |identifier_file|
26
+ identifiers = TSV.open(identifier_file, sep: ",", type: :single)
27
+ brothers = datafile_test(:person).brothers
28
+ kb = KnowledgeBase.new dir
29
+ kb.register :brothers, brothers, identifiers: identifiers
30
+ assert_include kb.get_index(:brothers, source: "=>Initials"), "CC~Guille"
31
+ end
32
+ end
33
+ end
34
+ end
35
+