netica 0.0.21-java → 1.0.0.pre-java
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 +7 -0
- data/.ruby-version +1 -1
- data/README.md +4 -2
- data/examples/ChestClinicv2.dne +110 -0
- data/lib/netica.rb +2 -16
- data/lib/netica/active_network.rb +16 -56
- data/lib/netica/bayes_network.rb +6 -1
- data/lib/netica/node.rb +10 -1
- data/lib/netica/storable_network.rb +74 -0
- data/lib/netica/version.rb +1 -1
- data/spec/netica/active_network_spec.rb +1 -60
- data/spec/netica/storable_network_spec.rb +87 -0
- metadata +20 -24
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 231e9845a73e728268cbc2db7801e44cf3d46c68
|
4
|
+
data.tar.gz: 30512cdcf0a3573a8dfe1c7f5f7546442a87fc14
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d834a08e817f3e579c14906fb70f08680c8f0ab52772757ace63be7293f507f37e863e1127b7b028653e495851c21c5ae24b8e525b2e78a76c6979076f0d56aa
|
7
|
+
data.tar.gz: 16ed7f4c125df781c6b206dd8207db5e8fc22892f6ddde12d37f344b8ec58be691ef6923b6948e894d361e7a9fc1646e44fd60e86ce84d69ef0ce24f72b80690
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
jruby-1.7.
|
1
|
+
jruby-1.7.9
|
data/README.md
CHANGED
@@ -67,9 +67,11 @@ Then, re-read the value of the Belief node.
|
|
67
67
|
|
68
68
|
## Release Notes
|
69
69
|
|
70
|
-
### Version 0.0.
|
70
|
+
### Version 1.0.0.pre
|
71
71
|
|
72
|
-
|
72
|
+
* Split ActiveNetwork's out-of-process storage and retrieval methods into a new subclass, StorableNetwork.
|
73
|
+
* Add filename parameter to StorableNetwork#find, allowing a stored network's .dne file to be updated.
|
74
|
+
* Built and tested with JRuby 1.7.9
|
73
75
|
|
74
76
|
### Version 0.0.20
|
75
77
|
|
@@ -0,0 +1,110 @@
|
|
1
|
+
// ~->[DNET-1]->~
|
2
|
+
|
3
|
+
// File created by an unlicensed user using Netica 5.04 on 10/01/12 at 20:20:06.
|
4
|
+
|
5
|
+
bnet ChestClinic {
|
6
|
+
autoupdate = FALSE;
|
7
|
+
|
8
|
+
node VisitAntarctica {
|
9
|
+
kind = NATURE;
|
10
|
+
discrete = TRUE;
|
11
|
+
chance = CHANCE;
|
12
|
+
states = (visit, no_visit);
|
13
|
+
statetitles = ("Visited Antarctica within the last 3 years", );
|
14
|
+
parents = ();
|
15
|
+
probs =
|
16
|
+
// Visited Antarctica wit no visit
|
17
|
+
(0.01, 0.99);
|
18
|
+
title = "Visit to Antarctica";
|
19
|
+
};
|
20
|
+
|
21
|
+
node Tuberculosis {
|
22
|
+
kind = NATURE;
|
23
|
+
discrete = TRUE;
|
24
|
+
chance = CHANCE;
|
25
|
+
states = (present, absent);
|
26
|
+
parents = (VisitAntarctica);
|
27
|
+
probs =
|
28
|
+
// present absent // VisitAntarctica
|
29
|
+
(0.05, 0.95, // Visited Antarctica wit
|
30
|
+
0.01, 0.99); // no visit ;
|
31
|
+
};
|
32
|
+
|
33
|
+
node Smoking {
|
34
|
+
kind = NATURE;
|
35
|
+
discrete = TRUE;
|
36
|
+
chance = CHANCE;
|
37
|
+
states = (smoker, nonsmoker);
|
38
|
+
parents = ();
|
39
|
+
probs =
|
40
|
+
// smoker nonsmoker
|
41
|
+
(0.5, 0.5);
|
42
|
+
};
|
43
|
+
|
44
|
+
node Cancer {
|
45
|
+
kind = NATURE;
|
46
|
+
discrete = TRUE;
|
47
|
+
chance = CHANCE;
|
48
|
+
states = (present, absent);
|
49
|
+
parents = (Smoking);
|
50
|
+
probs =
|
51
|
+
// present absent // Smoking
|
52
|
+
(0.1, 0.9, // smoker
|
53
|
+
0.01, 0.99); // nonsmoker ;
|
54
|
+
title = "Lung Cancer";
|
55
|
+
};
|
56
|
+
|
57
|
+
node TbOrCa {
|
58
|
+
kind = NATURE;
|
59
|
+
discrete = TRUE;
|
60
|
+
chance = DETERMIN;
|
61
|
+
states = (true, false);
|
62
|
+
parents = (Tuberculosis, Cancer);
|
63
|
+
functable =
|
64
|
+
// Tuberculosis Cancer
|
65
|
+
(true, // present present
|
66
|
+
true, // present absent
|
67
|
+
true, // absent present
|
68
|
+
false); // absent absent ;
|
69
|
+
equation = "TbOrCa (Tuberculosis, Cancer) = Tuberculosis || Cancer";
|
70
|
+
title = "Tuberculosis or Cancer";
|
71
|
+
};
|
72
|
+
|
73
|
+
node XRay {
|
74
|
+
kind = NATURE;
|
75
|
+
discrete = TRUE;
|
76
|
+
chance = CHANCE;
|
77
|
+
states = (abnormal, normal);
|
78
|
+
parents = (TbOrCa);
|
79
|
+
probs =
|
80
|
+
// abnormal normal // TbOrCa
|
81
|
+
(0.98, 0.02, // true
|
82
|
+
0.05, 0.95); // false ;
|
83
|
+
};
|
84
|
+
|
85
|
+
node Bronchitis {
|
86
|
+
kind = NATURE;
|
87
|
+
discrete = TRUE;
|
88
|
+
chance = CHANCE;
|
89
|
+
states = (present, absent);
|
90
|
+
parents = (Smoking);
|
91
|
+
probs =
|
92
|
+
// present absent // Smoking
|
93
|
+
(0.6, 0.4, // smoker
|
94
|
+
0.3, 0.7); // nonsmoker ;
|
95
|
+
};
|
96
|
+
|
97
|
+
node Dyspnea {
|
98
|
+
kind = NATURE;
|
99
|
+
discrete = TRUE;
|
100
|
+
chance = CHANCE;
|
101
|
+
states = (present, absent);
|
102
|
+
parents = (TbOrCa, Bronchitis);
|
103
|
+
probs =
|
104
|
+
// present absent // TbOrCa Bronchitis
|
105
|
+
(0.9, 0.1, // true present
|
106
|
+
0.7, 0.3, // true absent
|
107
|
+
0.8, 0.2, // false present
|
108
|
+
0.1, 0.9); // false absent ;
|
109
|
+
};
|
110
|
+
};
|
data/lib/netica.rb
CHANGED
@@ -1,20 +1,5 @@
|
|
1
1
|
require 'java'
|
2
|
-
|
3
|
-
loaded_netica_j = false
|
4
|
-
|
5
|
-
locations = ['/Library/Java/Extensions/NeticaJ.jar', '/System/Library/Java/Extensions/NeticaJ.jar', '/usr/lib/java/NeticaJ.jar', '/lib/NeticaJ.jar']
|
6
|
-
locations.each do |fname|
|
7
|
-
if !loaded_netica_j && File.exists?(fname)
|
8
|
-
begin
|
9
|
-
require fname
|
10
|
-
loaded_netica_j = true
|
11
|
-
rescue LoadError
|
12
|
-
puts "NeticaJ.jar not found at '#{fname}'"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
raise "NeticaJ library files not found in #{locations}. See https://github.com/disruptive/netica for installation instructions." unless loaded_netica_j
|
2
|
+
require '/lib/NeticaJ.jar'
|
18
3
|
|
19
4
|
require "netica/version"
|
20
5
|
require "netica/environ"
|
@@ -24,6 +9,7 @@ require "netica/node"
|
|
24
9
|
require "netica/node_list"
|
25
10
|
require "netica/bayes_network"
|
26
11
|
require "netica/active_network"
|
12
|
+
require "netica/storable_network"
|
27
13
|
require "netica/java_library_path"
|
28
14
|
|
29
15
|
module Netica
|
@@ -6,7 +6,7 @@ module Netica
|
|
6
6
|
class ActiveNetwork::NodeNotFound < RuntimeError; end
|
7
7
|
class ActiveNetwork::NetworkNotFound < RuntimeError; end
|
8
8
|
|
9
|
-
attr_accessor :network, :token, :created_at, :updated_at, :reloaded_at, :in_use
|
9
|
+
attr_accessor :network, :token, :created_at, :updated_at, :reloaded_at, :in_use, :filepath
|
10
10
|
|
11
11
|
def initialize(token, filepath = nil)
|
12
12
|
Netica::NeticaLogger.info "Initializing #{self.class} for #{token}."
|
@@ -16,7 +16,8 @@ module Netica
|
|
16
16
|
self.in_use = false
|
17
17
|
|
18
18
|
if filepath
|
19
|
-
self.
|
19
|
+
self.filepath = filepath
|
20
|
+
self.network = BayesNetwork.new(filepath)
|
20
21
|
end
|
21
22
|
processor = Netica::Environment.instance
|
22
23
|
processor.active_networks << self
|
@@ -58,21 +59,11 @@ module Netica
|
|
58
59
|
}
|
59
60
|
end
|
60
61
|
|
61
|
-
# Save ActiveNetwork to an associated redis store, if one is defined.
|
62
|
-
#
|
63
|
-
# @return [true,false,nil] outcome of redis.set, or nil if redis is not found
|
64
|
-
def save
|
65
|
-
if Netica::Environment.instance.redis
|
66
|
-
return Netica::Environment.instance.redis.set(token, JSON.dump(state))
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
62
|
# Retrieve ActiveNetwork from current Netica Environment instance
|
71
|
-
# or an associated redis store, if one is defined.
|
72
63
|
#
|
73
64
|
# @param token [String] identifying token for ActiveNetwork sought
|
74
65
|
# @return [ActiveNetwork] ActiveNetwork object found
|
75
|
-
def self.find(token
|
66
|
+
def self.find(token)
|
76
67
|
environment = Netica::Environment.instance
|
77
68
|
Netica::NeticaLogger.info "Searching in #{environment.network_container.class} #{environment.network_container.object_id} (length: #{environment.network_container.length}) for #{token}."
|
78
69
|
environment.network_container.each do |an|
|
@@ -85,62 +76,31 @@ module Netica
|
|
85
76
|
end
|
86
77
|
end
|
87
78
|
Netica::NeticaLogger.info "Network #{token} not found in current instance #{environment.object_id}."
|
88
|
-
if Netica::Environment.instance.redis
|
89
|
-
stored_state = Netica::Environment.instance.redis.get(token)
|
90
|
-
if stored_state && load_from_storage
|
91
|
-
hash = JSON.parse(stored_state)
|
92
|
-
active_network = Object.const_get(hash['class']).new(token)
|
93
|
-
active_network.load_from_saved_state(hash)
|
94
|
-
Netica::NeticaLogger.info "Network #{token} reloaded from saved state: #{hash}"
|
95
|
-
return active_network
|
96
|
-
elsif stored_state
|
97
|
-
return stored_state
|
98
|
-
else
|
99
|
-
Netica::NeticaLogger.info "Network #{token} not found in redis."
|
100
|
-
end
|
101
|
-
end
|
102
79
|
return nil
|
103
80
|
end
|
104
81
|
|
105
82
|
# Destroy the ActiveNetwork
|
106
83
|
#
|
107
|
-
# @
|
108
|
-
|
109
|
-
|
110
|
-
def destroy(memory = true, storage = true)
|
111
|
-
outcome = { token: token, deletion: { memory: nil, redis: nil}}
|
84
|
+
# @return [Hash] outcome of deletion attempt
|
85
|
+
def destroy
|
86
|
+
outcome = { token: token, deletion: { memory: nil }}
|
112
87
|
environment = Netica::Environment.instance
|
113
|
-
|
114
|
-
|
115
|
-
rejection = environment.network_container.reject!{|network| network.token == token}
|
116
|
-
outcome[:deletion][:memory] = rejection.is_a?(Array)
|
117
|
-
end
|
118
|
-
|
119
|
-
if environment.redis && storage == true
|
120
|
-
outcome[:deletion][:redis] = (environment.redis.del(token) > 0)
|
121
|
-
end
|
88
|
+
rejection = environment.network_container.reject!{|network| network.token == token}
|
89
|
+
outcome[:deletion][:memory] = rejection.is_a?(Array)
|
122
90
|
outcome
|
123
91
|
end
|
124
92
|
|
125
|
-
# Destroy a saved network
|
126
|
-
#
|
127
|
-
# @return [Hash] outcome of deletion attempts per storage location
|
128
|
-
def self.destroy_by_token(token)
|
129
|
-
outcome = { token: token, deletion: { memory: nil, redis: nil}}
|
130
|
-
environment = Netica::Environment.instance
|
131
|
-
|
132
|
-
if environment.redis
|
133
|
-
outcome[:deletion][:redis] = (environment.redis.del(token) > 0)
|
134
|
-
end
|
135
|
-
|
136
|
-
outcome
|
137
|
-
end
|
138
93
|
|
139
|
-
# Load ActiveNetwork from a
|
94
|
+
# Load ActiveNetwork from a Hash
|
140
95
|
#
|
141
96
|
# @param hash [Hash] network state to be restored
|
142
97
|
def load_from_saved_state(hash)
|
143
|
-
|
98
|
+
if filepath
|
99
|
+
self.network = BayesNetwork.new(filepath)
|
100
|
+
else
|
101
|
+
self.filepath = hash["network"]["dne_file_path"]
|
102
|
+
self.network = BayesNetwork.new(hash["network"]["dne_file_path"])
|
103
|
+
end
|
144
104
|
self.reloaded_at = Time.now
|
145
105
|
self.network.load_from_state(hash["network"])
|
146
106
|
end
|
data/lib/netica/bayes_network.rb
CHANGED
@@ -42,11 +42,16 @@ module Netica
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def load_from_state(network_hash)
|
45
|
-
Netica::NeticaLogger.info "Loading state from network_hash => #{network_hash}"
|
46
45
|
network_hash["decision_nodes"].each do |node_name, node_value|
|
47
46
|
Netica::NeticaLogger.info "Setting #{node_name} => #{node_value}"
|
48
47
|
node(node_name).value = node_value
|
49
48
|
end
|
49
|
+
|
50
|
+
network_hash["nature_nodes"].each do |node_name, node_value_hash|
|
51
|
+
next unless node_name == 'XRay'
|
52
|
+
Netica::NeticaLogger.info "Setting #{node_name} => #{node_value_hash}"
|
53
|
+
node(node_name).value = node_value_hash
|
54
|
+
end
|
50
55
|
end
|
51
56
|
|
52
57
|
def state
|
data/lib/netica/node.rb
CHANGED
@@ -65,7 +65,16 @@ class Java::NorsysNetica::Node
|
|
65
65
|
finding().setReal(new_value)
|
66
66
|
elsif nature_node?
|
67
67
|
Netica::NeticaLogger.info "Nature Node: Setting #{kind} #{type} node #{self.name} to #{new_value}"
|
68
|
-
|
68
|
+
if new_value.is_a?(Hash)
|
69
|
+
value_array = []
|
70
|
+
states.each do |s|
|
71
|
+
value_array << new_value[s.name]
|
72
|
+
end
|
73
|
+
finding().enter_likelihood(value_array)
|
74
|
+
else
|
75
|
+
finding.enterState(new_value)
|
76
|
+
end
|
77
|
+
Netica::NeticaLogger.info beliefs
|
69
78
|
else
|
70
79
|
throw "Could not set value for #{kind} #{type} node #{self.name} to #{new_value}"
|
71
80
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# provides a persistable object container for a Netica Bayes net.
|
2
|
+
class StorableNetwork < Netica::ActiveNetwork
|
3
|
+
|
4
|
+
# Save StorableNetwork to an associated redis store, if one is defined.
|
5
|
+
#
|
6
|
+
# @return [true,false,nil] outcome of redis.set, or nil if redis is not found
|
7
|
+
def save
|
8
|
+
if Netica::Environment.instance.redis
|
9
|
+
return Netica::Environment.instance.redis.set(token, JSON.dump(state))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Retrieve ActiveNetwork from current Netica Environment instance
|
14
|
+
# or an associated redis store, if one is defined.
|
15
|
+
#
|
16
|
+
# @param token [String] identifying token for ActiveNetwork sought
|
17
|
+
# @return [ActiveNetwork] ActiveNetwork object found
|
18
|
+
def self.find(token, load_from_storage = true, filepath = nil)
|
19
|
+
environment = Netica::Environment.instance
|
20
|
+
redis = environment.redis
|
21
|
+
found_network = super(token)
|
22
|
+
if found_network.nil? && redis
|
23
|
+
stored_state = redis.get(token)
|
24
|
+
if stored_state && load_from_storage
|
25
|
+
hash = JSON.parse(stored_state)
|
26
|
+
found_network = Object::const_get(hash['class']).new(token)
|
27
|
+
found_network.filepath = filepath
|
28
|
+
found_network.load_from_saved_state(hash)
|
29
|
+
Netica::NeticaLogger.info "Network #{token} reloaded from saved state: #{hash}"
|
30
|
+
Netica::NeticaLogger.info "#{token} reloaded state: #{found_network.state}"
|
31
|
+
return found_network
|
32
|
+
elsif stored_state
|
33
|
+
return stored_state
|
34
|
+
else
|
35
|
+
Netica::NeticaLogger.info "Network #{token} not found in redis."
|
36
|
+
end
|
37
|
+
end
|
38
|
+
return nil
|
39
|
+
end
|
40
|
+
|
41
|
+
# Destroy the ActiveNetwork
|
42
|
+
#
|
43
|
+
# @param memory [Boolean] destroy the in-memory object?, default is `true`
|
44
|
+
# @param storage [Boolean] destroy object in redis?, default is `true`
|
45
|
+
# @return [Hash] outcome of deletion attempts per storage location
|
46
|
+
def destroy(memory = true, storage = true)
|
47
|
+
outcome = { token: token, deletion: { memory: nil, redis: nil}}
|
48
|
+
environment = Netica::Environment.instance
|
49
|
+
|
50
|
+
if memory
|
51
|
+
rejection = environment.network_container.reject!{|network| network.token == token}
|
52
|
+
outcome[:deletion][:memory] = rejection.is_a?(Array)
|
53
|
+
end
|
54
|
+
|
55
|
+
if environment.redis && storage == true
|
56
|
+
outcome[:deletion][:redis] = (environment.redis.del(token) > 0)
|
57
|
+
end
|
58
|
+
outcome
|
59
|
+
end
|
60
|
+
|
61
|
+
# Destroy a saved network
|
62
|
+
#
|
63
|
+
# @return [Hash] outcome of deletion attempts per storage location
|
64
|
+
def self.destroy_by_token(token)
|
65
|
+
outcome = { token: token, deletion: { memory: nil, redis: nil}}
|
66
|
+
environment = Netica::Environment.instance
|
67
|
+
|
68
|
+
if environment.redis
|
69
|
+
outcome[:deletion][:redis] = (environment.redis.del(token) > 0)
|
70
|
+
end
|
71
|
+
|
72
|
+
outcome
|
73
|
+
end
|
74
|
+
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"
|
34
|
+
Netica::ActiveNetwork.find("fake_token_identifier").should === @active_network
|
35
35
|
end
|
36
36
|
|
37
37
|
context "the tuberculosis node" do
|
@@ -49,67 +49,8 @@ describe Netica::ActiveNetwork do
|
|
49
49
|
Netica::Environment.instance.active_networks.length.should eq(1)
|
50
50
|
outcome = @active_network.destroy
|
51
51
|
outcome[:deletion][:memory].should be_true
|
52
|
-
outcome[:deletion][:redis].should be_nil
|
53
52
|
Netica::Environment.instance.active_networks.length.should eq(0)
|
54
53
|
end
|
55
54
|
end
|
56
55
|
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
|
-
|
96
|
-
describe "#destroy_by_token" do
|
97
|
-
context "A stored active network" do
|
98
|
-
it "should be deletable" do
|
99
|
-
@active_network.save
|
100
|
-
@active_network.destroy(true, false)
|
101
|
-
@redis.get(@active_network_token).should be_true
|
102
|
-
|
103
|
-
outcome = Netica::ActiveNetwork.destroy_by_token(@active_network_token)
|
104
|
-
outcome[:deletion][:memory].should be_nil
|
105
|
-
outcome[:deletion][:redis].should be_true
|
106
|
-
|
107
|
-
@redis.get(@active_network_token).should be_nil
|
108
|
-
Netica::Environment.instance.active_networks.length.should eq(0)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
56
|
end
|
115
|
-
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StorableNetwork do
|
4
|
+
context "with redis" do
|
5
|
+
before(:all) do
|
6
|
+
Java::NorsysNetica::Environ.__persistent__ = true
|
7
|
+
redis_settings = { :redis => { :host => "127.0.0.1", :port => 6379 }}
|
8
|
+
Netica::Environment.engage(redis_settings)
|
9
|
+
@redis = Redis.new(redis_settings)
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:all) do
|
13
|
+
Netica::Environment.instance.processor.finalize
|
14
|
+
end
|
15
|
+
|
16
|
+
context "with ChestClinic.dne" do
|
17
|
+
before(:all) do
|
18
|
+
@active_network = StorableNetwork.new("storable_fake_token_identifier", "#{File.dirname(__FILE__)}/../../examples/ChestClinic.dne")
|
19
|
+
@active_network_token = @active_network.token
|
20
|
+
end
|
21
|
+
|
22
|
+
after(:all) do
|
23
|
+
@redis.del("storable_fake_token_identifier")
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#save" do
|
27
|
+
it "should be savable" do
|
28
|
+
@redis.get(@active_network_token).should be_nil
|
29
|
+
@active_network.save
|
30
|
+
@redis.get(@active_network_token).should_not be_nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#destroy" do
|
35
|
+
it "should be deletable" do
|
36
|
+
Netica::Environment.instance.active_networks.length.should eq(1)
|
37
|
+
@redis.get(@active_network_token).should_not be_nil
|
38
|
+
outcome = @active_network.destroy
|
39
|
+
outcome[:deletion][:memory].should be_true
|
40
|
+
outcome[:deletion][:redis].should be_true
|
41
|
+
@redis.get(@active_network_token).should be_nil
|
42
|
+
Netica::Environment.instance.active_networks.length.should eq(0)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#destroy_by_token" do
|
47
|
+
context "A stored active network" do
|
48
|
+
it "should be deletable" do
|
49
|
+
@active_network.save
|
50
|
+
@active_network.destroy(true, false)
|
51
|
+
@redis.get(@active_network_token).should be_true
|
52
|
+
|
53
|
+
outcome = StorableNetwork.destroy_by_token(@active_network_token)
|
54
|
+
outcome[:deletion][:memory].should be_nil
|
55
|
+
outcome[:deletion][:redis].should be_true
|
56
|
+
|
57
|
+
@redis.get(@active_network_token).should be_nil
|
58
|
+
Netica::Environment.instance.active_networks.length.should eq(0)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "#find" do
|
64
|
+
it "should be reloadable" do
|
65
|
+
@active_network.network.node("Tuberculosis").value("present").should be_less_than 0.011
|
66
|
+
@active_network.network.node("XRay").value = "abnormal"
|
67
|
+
|
68
|
+
@active_network.network.node("Tuberculosis").value("present").should be_greater_than 0.092
|
69
|
+
@active_network.save
|
70
|
+
|
71
|
+
@active_network.destroy(true, false)
|
72
|
+
|
73
|
+
Netica::Environment.instance.active_networks.length.should eq(0)
|
74
|
+
|
75
|
+
@reloaded_network = StorableNetwork.find(@active_network_token, true)
|
76
|
+
Netica::Environment.instance.active_networks.length.should eq(1)
|
77
|
+
|
78
|
+
@reloaded_network.network.node("Tuberculosis").value("present").should be_greater_than 0.092
|
79
|
+
|
80
|
+
@reloaded_network.destroy
|
81
|
+
Netica::Environment.instance.active_networks.length.should eq(0)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
metadata
CHANGED
@@ -1,32 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netica
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.0.21
|
4
|
+
version: 1.0.0.pre
|
6
5
|
platform: java
|
7
6
|
authors:
|
8
7
|
- Jerry Richardson
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-12-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: redis
|
16
15
|
version_requirements: !ruby/object:Gem::Requirement
|
17
16
|
requirements:
|
18
|
-
- -
|
17
|
+
- - '>='
|
19
18
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
21
|
-
MA==
|
22
|
-
none: false
|
19
|
+
version: '0'
|
23
20
|
requirement: !ruby/object:Gem::Requirement
|
24
21
|
requirements:
|
25
|
-
- -
|
22
|
+
- - '>='
|
26
23
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
28
|
-
MA==
|
29
|
-
none: false
|
24
|
+
version: '0'
|
30
25
|
prerelease: false
|
31
26
|
type: :development
|
32
27
|
description: Netica Bayes Network Management
|
@@ -36,15 +31,16 @@ executables: []
|
|
36
31
|
extensions: []
|
37
32
|
extra_rdoc_files: []
|
38
33
|
files:
|
39
|
-
-
|
40
|
-
-
|
41
|
-
-
|
34
|
+
- .gitignore
|
35
|
+
- .rspec
|
36
|
+
- .ruby-version
|
42
37
|
- CONTRIBUTING.md
|
43
38
|
- Gemfile
|
44
39
|
- LICENSE.txt
|
45
40
|
- README.md
|
46
41
|
- Rakefile
|
47
42
|
- examples/ChestClinic.dne
|
43
|
+
- examples/ChestClinicv2.dne
|
48
44
|
- examples/chest_clinic.rb
|
49
45
|
- lib/netica.rb
|
50
46
|
- lib/netica/active_network.rb
|
@@ -57,43 +53,43 @@ files:
|
|
57
53
|
- lib/netica/node_list.rb
|
58
54
|
- lib/netica/railtie.rb
|
59
55
|
- lib/netica/state.rb
|
56
|
+
- lib/netica/storable_network.rb
|
60
57
|
- lib/netica/version.rb
|
61
58
|
- lib/tasks/netica.rake
|
62
59
|
- log/.gitignore
|
63
60
|
- netica.gemspec
|
64
61
|
- spec/netica/active_network_spec.rb
|
65
62
|
- spec/netica/environment_spec.rb
|
63
|
+
- spec/netica/storable_network_spec.rb
|
66
64
|
- spec/netica_spec.rb
|
67
65
|
- spec/spec_helper.rb
|
68
66
|
homepage: http://disruptive.github.io/netica/
|
69
67
|
licenses:
|
70
68
|
- MIT
|
69
|
+
metadata: {}
|
71
70
|
post_install_message:
|
72
71
|
rdoc_options: []
|
73
72
|
require_paths:
|
74
73
|
- lib
|
75
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
76
75
|
requirements:
|
77
|
-
- -
|
76
|
+
- - '>='
|
78
77
|
- !ruby/object:Gem::Version
|
79
|
-
version:
|
80
|
-
MA==
|
81
|
-
none: false
|
78
|
+
version: '0'
|
82
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
80
|
requirements:
|
84
|
-
- -
|
81
|
+
- - '>'
|
85
82
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
87
|
-
MA==
|
88
|
-
none: false
|
83
|
+
version: 1.3.1
|
89
84
|
requirements: []
|
90
85
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.
|
86
|
+
rubygems_version: 2.1.9
|
92
87
|
signing_key:
|
93
|
-
specification_version:
|
88
|
+
specification_version: 4
|
94
89
|
summary: Tools to manage Bayes Networks with the NeticaJ API
|
95
90
|
test_files:
|
96
91
|
- spec/netica/active_network_spec.rb
|
97
92
|
- spec/netica/environment_spec.rb
|
93
|
+
- spec/netica/storable_network_spec.rb
|
98
94
|
- spec/netica_spec.rb
|
99
95
|
- spec/spec_helper.rb
|