netica 0.0.17-java → 0.0.19-java
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -0
- data/Rakefile +2 -0
- data/lib/netica/active_network.rb +22 -9
- data/lib/netica/version.rb +1 -1
- data/spec/netica/active_network_spec.rb +44 -2
- metadata +2 -2
data/README.md
CHANGED
@@ -67,6 +67,15 @@ Then, re-read the value of the Belief node.
|
|
67
67
|
|
68
68
|
## Release Notes
|
69
69
|
|
70
|
+
### Version 0.0.19
|
71
|
+
|
72
|
+
Add `load_from_storage` parameter to ActiveNetwork#find so we can retrieve the state of a network in storage without instantiating it. Defaults to true.
|
73
|
+
|
74
|
+
### Version 0.0.18
|
75
|
+
|
76
|
+
* Return a hash from ActiveNetwork#destroy indicating the outcome of deletion in each storage location.
|
77
|
+
* Make the java_library_path task visible in `rake -vT`
|
78
|
+
|
70
79
|
### Version 0.0.17
|
71
80
|
|
72
81
|
* We don't wait, we sleep when a network is locked.
|
data/Rakefile
CHANGED
@@ -72,7 +72,7 @@ module Netica
|
|
72
72
|
#
|
73
73
|
# @param token [String] identifying token for ActiveNetwork sought
|
74
74
|
# @return [ActiveNetwork] ActiveNetwork object found
|
75
|
-
def self.find(token)
|
75
|
+
def self.find(token, load_from_storage = true)
|
76
76
|
environment = Netica::Environment.instance
|
77
77
|
Netica::NeticaLogger.info "Searching in #{environment.network_container.class} #{environment.network_container.object_id} (length: #{environment.network_container.length}) for #{token}."
|
78
78
|
environment.network_container.each do |an|
|
@@ -87,12 +87,14 @@ module Netica
|
|
87
87
|
Netica::NeticaLogger.info "Network #{token} not found in current instance #{environment.object_id}."
|
88
88
|
if Netica::Environment.instance.redis
|
89
89
|
stored_state = Netica::Environment.instance.redis.get(token)
|
90
|
-
if stored_state
|
90
|
+
if stored_state && load_from_storage
|
91
91
|
hash = JSON.parse(stored_state)
|
92
92
|
active_network = Object.const_get(hash['class']).new(token)
|
93
93
|
active_network.load_from_saved_state(hash)
|
94
94
|
Netica::NeticaLogger.info "Network #{token} reloaded from saved state: #{hash}"
|
95
95
|
return active_network
|
96
|
+
elsif stored_state
|
97
|
+
return stored_state
|
96
98
|
else
|
97
99
|
Netica::NeticaLogger.info "Network #{token} not found in redis."
|
98
100
|
end
|
@@ -100,22 +102,33 @@ module Netica
|
|
100
102
|
return nil
|
101
103
|
end
|
102
104
|
|
103
|
-
|
105
|
+
# Destroy the ActiveNetwork
|
106
|
+
#
|
107
|
+
# @param memory [Boolean] destroy the in-memory object?, default is `true`
|
108
|
+
# @param storage [Boolean] destroy object in redis?, default is `true`
|
109
|
+
# @return [Hash] outcome of deletion attempts per storage location
|
110
|
+
def destroy(memory = true, storage = true)
|
111
|
+
outcome = { token: token, deletion: { memory: nil, redis: nil}}
|
104
112
|
environment = Netica::Environment.instance
|
105
|
-
|
106
|
-
if
|
107
|
-
environment.
|
113
|
+
|
114
|
+
if memory
|
115
|
+
rejection = environment.network_container.reject!{|network| network.token == token}
|
116
|
+
outcome[:deletion][:memory] = rejection.is_a?(Array)
|
108
117
|
end
|
118
|
+
|
119
|
+
if environment.redis && storage
|
120
|
+
outcome[:deletion][:redis] = (environment.redis.del(token) > 0)
|
121
|
+
end
|
122
|
+
outcome
|
109
123
|
end
|
110
124
|
|
111
|
-
#
|
125
|
+
# Load ActiveNetwork from a saved state
|
112
126
|
#
|
113
127
|
# @param hash [Hash] network state to be restored
|
114
|
-
# @return [Hash] network state and object class name
|
115
128
|
def load_from_saved_state(hash)
|
116
129
|
self.network = BayesNetwork.new(hash["network"]["dne_file_path"])
|
117
|
-
self.network.load_from_state(hash["network"])
|
118
130
|
self.reloaded_at = Time.now
|
131
|
+
self.network.load_from_state(hash["network"])
|
119
132
|
end
|
120
133
|
end
|
121
134
|
end
|
data/lib/netica/version.rb
CHANGED
@@ -31,7 +31,7 @@ describe Netica::ActiveNetwork do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should be returned when searched for" do
|
34
|
-
Netica::ActiveNetwork.find("fake_token_identifier").should === @active_network
|
34
|
+
Netica::ActiveNetwork.find("fake_token_identifier", false).should === @active_network
|
35
35
|
end
|
36
36
|
|
37
37
|
context "the tuberculosis node" do
|
@@ -47,10 +47,52 @@ describe Netica::ActiveNetwork do
|
|
47
47
|
|
48
48
|
it "should be deletable" do
|
49
49
|
Netica::Environment.instance.active_networks.length.should eq(1)
|
50
|
-
@active_network.destroy
|
50
|
+
outcome = @active_network.destroy
|
51
|
+
outcome[:deletion][:memory].should be_true
|
52
|
+
outcome[:deletion][:redis].should be_nil
|
51
53
|
Netica::Environment.instance.active_networks.length.should eq(0)
|
52
54
|
end
|
53
55
|
end
|
54
56
|
end
|
57
|
+
|
58
|
+
context "with redis" do
|
59
|
+
before(:all) do
|
60
|
+
Java::NorsysNetica::Environ.__persistent__ = true
|
61
|
+
redis_settings = { :redis => { :host => "127.0.0.1", :port => 6379 }}
|
62
|
+
Netica::Environment.engage(redis_settings)
|
63
|
+
@redis = Redis.new(redis_settings)
|
64
|
+
end
|
65
|
+
|
66
|
+
after(:all) do
|
67
|
+
Netica::Environment.instance.processor.finalize
|
68
|
+
end
|
69
|
+
|
70
|
+
context "with ChestClinic.dne" do
|
71
|
+
before(:all) do
|
72
|
+
@active_network = Netica::ActiveNetwork.new("fake_token_identifier", "#{File.dirname(__FILE__)}/../../examples/ChestClinic.dne")
|
73
|
+
@active_network_token = @active_network.token
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#save" do
|
77
|
+
it "should be savable" do
|
78
|
+
@redis.get(@active_network_token).should be_nil
|
79
|
+
@active_network.save
|
80
|
+
@redis.get(@active_network_token).should_not be_nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "#destroy" do
|
85
|
+
it "should be deletable" do
|
86
|
+
Netica::Environment.instance.active_networks.length.should eq(1)
|
87
|
+
@redis.get(@active_network_token).should_not be_nil
|
88
|
+
outcome = @active_network.destroy
|
89
|
+
outcome[:deletion][:memory].should be_true
|
90
|
+
outcome[:deletion][:redis].should be_true
|
91
|
+
@redis.get(@active_network_token).should be_nil
|
92
|
+
Netica::Environment.instance.active_networks.length.should eq(0)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
55
97
|
end
|
56
98
|
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: netica
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.19
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- Jerry Richardson
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-11-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|