scout-gear 10.7.2 → 10.7.3
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/.vimproject +46 -32
- data/VERSION +1 -1
- data/lib/scout/association/index.rb +4 -0
- data/lib/scout/association/item.rb +1 -1
- data/lib/scout/association.rb +28 -9
- data/lib/scout/entity/identifiers.rb +2 -2
- data/lib/scout/entity/property.rb +1 -0
- data/lib/scout/knowledge_base/enrichment.rb +9 -0
- data/lib/scout/knowledge_base/entity.rb +143 -0
- data/lib/scout/knowledge_base/list.rb +95 -0
- data/lib/scout/knowledge_base/query.rb +96 -0
- data/lib/scout/knowledge_base/registry.rb +173 -0
- data/lib/scout/knowledge_base/traverse.rb +329 -0
- data/lib/scout/knowledge_base.rb +91 -0
- data/lib/scout/tsv/annotation.rb +4 -4
- data/lib/scout/tsv/index.rb +0 -2
- data/lib/scout/tsv/parser.rb +1 -1
- data/lib/scout/tsv/stream.rb +3 -3
- data/lib/scout/tsv.rb +2 -0
- data/lib/scout/workflow/step/info.rb +10 -1
- data/scout-gear.gemspec +24 -6
- data/scout_commands/kb/config +33 -0
- data/scout_commands/kb/entities +35 -0
- data/scout_commands/kb/list +39 -0
- data/scout_commands/{db → kb}/query +6 -11
- data/scout_commands/{db → kb}/register +9 -8
- data/scout_commands/{db → kb}/show +6 -16
- data/scout_commands/kb/traverse +66 -0
- data/test/data/person/brothers +1 -1
- data/test/scout/entity/test_identifiers.rb +3 -3
- data/test/scout/knowledge_base/test_enrichment.rb +0 -0
- data/test/scout/knowledge_base/test_entity.rb +38 -0
- data/test/scout/knowledge_base/test_list.rb +40 -0
- data/test/scout/knowledge_base/test_query.rb +39 -0
- data/test/scout/knowledge_base/test_registry.rb +16 -0
- data/test/scout/knowledge_base/test_traverse.rb +245 -0
- data/test/scout/test_association.rb +17 -3
- data/test/scout/test_entity.rb +0 -15
- data/test/scout/test_knowledge_base.rb +27 -0
- data/test/test_helper.rb +17 -0
- metadata +23 -5
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.
|
5
|
+
# stub: scout-gear 10.7.3 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "scout-gear".freeze
|
9
|
-
s.version = "10.7.
|
9
|
+
s.version = "10.7.3".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 = "
|
14
|
+
s.date = "2025-01-17"
|
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",
|
@@ -122,12 +129,16 @@ Gem::Specification.new do |s|
|
|
122
129
|
"scout_commands/alias",
|
123
130
|
"scout_commands/batch/clean",
|
124
131
|
"scout_commands/batch/list",
|
125
|
-
"scout_commands/db/query",
|
126
|
-
"scout_commands/db/register",
|
127
|
-
"scout_commands/db/show",
|
128
132
|
"scout_commands/doc",
|
129
133
|
"scout_commands/find",
|
130
134
|
"scout_commands/glob",
|
135
|
+
"scout_commands/kb/config",
|
136
|
+
"scout_commands/kb/entities",
|
137
|
+
"scout_commands/kb/list",
|
138
|
+
"scout_commands/kb/query",
|
139
|
+
"scout_commands/kb/register",
|
140
|
+
"scout_commands/kb/show",
|
141
|
+
"scout_commands/kb/traverse",
|
131
142
|
"scout_commands/log",
|
132
143
|
"scout_commands/offsite",
|
133
144
|
"scout_commands/rbbt",
|
@@ -158,6 +169,12 @@ Gem::Specification.new do |s|
|
|
158
169
|
"test/scout/entity/test_named_array.rb",
|
159
170
|
"test/scout/entity/test_object.rb",
|
160
171
|
"test/scout/entity/test_property.rb",
|
172
|
+
"test/scout/knowledge_base/test_enrichment.rb",
|
173
|
+
"test/scout/knowledge_base/test_entity.rb",
|
174
|
+
"test/scout/knowledge_base/test_list.rb",
|
175
|
+
"test/scout/knowledge_base/test_query.rb",
|
176
|
+
"test/scout/knowledge_base/test_registry.rb",
|
177
|
+
"test/scout/knowledge_base/test_traverse.rb",
|
161
178
|
"test/scout/offsite/test_ssh.rb",
|
162
179
|
"test/scout/offsite/test_step.rb",
|
163
180
|
"test/scout/offsite/test_sync.rb",
|
@@ -178,6 +195,7 @@ Gem::Specification.new do |s|
|
|
178
195
|
"test/scout/persist/tsv/test_serialize.rb",
|
179
196
|
"test/scout/test_association.rb",
|
180
197
|
"test/scout/test_entity.rb",
|
198
|
+
"test/scout/test_knowledge_base.rb",
|
181
199
|
"test/scout/test_offsite.rb",
|
182
200
|
"test/scout/test_semaphore.rb",
|
183
201
|
"test/scout/test_tsv.rb",
|
@@ -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/
|
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
|
-
|
37
|
+
knowledge_base = KnowledgeBase.load options[:knowledge_base] || :default
|
42
38
|
|
43
|
-
|
39
|
+
list = IndiferentHash.process_options options, :list
|
44
40
|
|
45
|
-
|
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 =
|
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
|
-
|
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
|
-
|
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/
|
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
|
36
|
-
|
31
|
+
puts knowledge_base.all_databases * "\n"
|
37
32
|
else
|
38
33
|
|
39
|
-
raise ParameterException "Database #{name} not found Options: #{Log.fingerprint
|
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
|
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
|
data/test/data/person/brothers
CHANGED
@@ -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
|
-
|
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.list_files["Person"], "bro_and_sis"
|
18
|
+
kb.delete_list("bro_and_sis")
|
19
|
+
|
20
|
+
refute kb.list_files["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.list_files["simple"], "bro_and_sis"
|
34
|
+
|
35
|
+
kb.delete_list("bro_and_sis")
|
36
|
+
|
37
|
+
refute kb.list_files["simple"]
|
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,16 @@
|
|
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
|
+
end
|
16
|
+
|