scout-ai 1.1.6 → 1.1.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.
@@ -0,0 +1,61 @@
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/network/knowledge_base'
5
+
6
+ class TestKnowledgeBaseRadialExpand < Test::Unit::TestCase
7
+ def test_radial_expand_outward
8
+ TmpFile.with_dir do |dir|
9
+ kb = KnowledgeBase.new dir
10
+ kb.register :brothers, datafile_test(:person).brothers, undirected: true
11
+
12
+ seeds = ["Miki"]
13
+ visited, edges = kb.radial_expand(:brothers, seeds, depth: 1, direction: :out)
14
+
15
+ assert_include visited, "Miki"
16
+ assert_include visited, "Isa"
17
+ assert edges.any? { |e| [e.source, e.target].sort == %w[Isa Miki].sort }
18
+ end
19
+ end
20
+
21
+ def test_radial_layers
22
+ TmpFile.with_dir do |dir|
23
+ kb = KnowledgeBase.new dir
24
+ kb.register :brothers, datafile_test(:person).brothers, undirected: true
25
+
26
+ seeds = ["Miki"]
27
+ layers, _edges = kb.radial_layers(:brothers, seeds, depth: 2, direction: :out)
28
+
29
+ # layers[0] should be seeds
30
+ assert_equal [seeds], layers.first(1)
31
+ # At least Isa should appear in layer 1
32
+ assert_include layers[1], "Isa"
33
+ end
34
+ end
35
+
36
+ def test_radial_expand_filter
37
+ TmpFile.with_dir do |dir|
38
+ kb = KnowledgeBase.new dir
39
+ kb.register :brothers, datafile_test(:person).brothers, undirected: true
40
+
41
+ seeds = ["Miki"]
42
+ visited, edges = kb.radial_expand(:brothers, seeds, depth: 1, direction: :out,
43
+ filter: ->(item){ false })
44
+
45
+ assert_equal ["Miki"], visited
46
+ assert_equal [], edges
47
+ end
48
+ end
49
+
50
+ def test_subgraph_around
51
+ TmpFile.with_dir do |dir|
52
+ kb = KnowledgeBase.new dir
53
+ kb.register :brothers, datafile_test(:person).brothers, undirected: true
54
+
55
+ seeds = ["Miki"]
56
+ edges = kb.subgraph_around(:brothers, seeds, depth: 1, direction: :out)
57
+
58
+ assert edges.any? { |e| [e.source, e.target].sort == %w[Isa Miki].sort }
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,56 @@
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/network/paths'
5
+
6
+ class TestNetworkPaths < Test::Unit::TestCase
7
+ def test_breadth_first_distances
8
+ adjacency = {
9
+ 'A' => %w[B C],
10
+ 'B' => %w[D],
11
+ 'C' => %w[D E],
12
+ 'D' => %w[F],
13
+ 'E' => [],
14
+ 'F' => []
15
+ }
16
+
17
+ distances = Paths.breadth_first(adjacency, 'A', 2)
18
+
19
+ assert_equal 0, distances['A']
20
+ assert_equal 1, distances['B']
21
+ assert_equal 1, distances['C']
22
+ assert_equal 2, distances['D']
23
+ assert_equal 2, distances['E']
24
+ # F should not be reached within 2 steps
25
+ assert_nil distances['F']
26
+ end
27
+
28
+ def test_neighborhood_from_single_source
29
+ adjacency = {
30
+ 'A' => %w[B C],
31
+ 'B' => %w[D],
32
+ 'C' => %w[D E],
33
+ 'D' => %w[F],
34
+ 'E' => [],
35
+ 'F' => []
36
+ }
37
+
38
+ neigh = Paths.neighborhood(adjacency, 'A', 2)
39
+
40
+ # Order is not guaranteed; compare as sets
41
+ assert_equal %w[A B C D E].sort, neigh.sort
42
+ end
43
+
44
+ def test_neighborhood_from_multiple_sources
45
+ adjacency = {
46
+ 'A' => %w[B],
47
+ 'B' => %w[C],
48
+ 'X' => %w[Y],
49
+ 'Y' => %w[Z]
50
+ }
51
+
52
+ neigh = Paths.neighborhood(adjacency, %w[A X], 1)
53
+
54
+ assert_equal %w[A B X Y].sort, neigh.sort
55
+ end
56
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout-ai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
@@ -147,6 +147,9 @@ files:
147
147
  - lib/scout/model/python/torch/load_and_save.rb
148
148
  - lib/scout/model/util/run.rb
149
149
  - lib/scout/model/util/save.rb
150
+ - lib/scout/network/entity.rb
151
+ - lib/scout/network/knowledge_base.rb
152
+ - lib/scout/network/paths.rb
150
153
  - python/scout_ai/__init__.py
151
154
  - python/scout_ai/huggingface/data.py
152
155
  - python/scout_ai/huggingface/eval.py
@@ -203,6 +206,9 @@ files:
203
206
  - test/scout/model/python/torch/test_helpers.rb
204
207
  - test/scout/model/test_base.rb
205
208
  - test/scout/model/util/test_save.rb
209
+ - test/scout/network/test_entity.rb
210
+ - test/scout/network/test_knowledge_base.rb
211
+ - test/scout/network/test_paths.rb
206
212
  - test/test_helper.rb
207
213
  homepage: http://github.com/mikisvaz/scout-ai
208
214
  licenses:
@@ -222,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
228
  - !ruby/object:Gem::Version
223
229
  version: '0'
224
230
  requirements: []
225
- rubygems_version: 3.7.0.dev
231
+ rubygems_version: 3.7.2
226
232
  specification_version: 4
227
233
  summary: AI gear for scouts
228
234
  test_files: []