netica 0.0.8-java → 0.0.9-java
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/netica.rb +2 -0
- data/lib/netica/active_network.rb +12 -5
- data/lib/netica/bayes_network.rb +9 -4
- data/lib/netica/environment.rb +1 -1
- data/lib/netica/node.rb +1 -1
- data/lib/netica/version.rb +1 -1
- data/spec/netica/active_network_spec.rb +1 -0
- metadata +2 -2
data/lib/netica.rb
CHANGED
@@ -10,6 +10,8 @@ require "netica/bayes_network"
|
|
10
10
|
require "netica/active_network"
|
11
11
|
require "netica/java_library_path"
|
12
12
|
|
13
|
+
Java::NorsysNetica::Environ.__persistent__ = true
|
14
|
+
|
13
15
|
module Netica
|
14
16
|
include_package "norsys.netica"
|
15
17
|
require "netica/railtie" if defined?(Rails)
|
@@ -6,10 +6,12 @@ module Netica
|
|
6
6
|
class ActiveNetwork::NodeNotFound < RuntimeError; end
|
7
7
|
class ActiveNetwork::NetworkNotFound < RuntimeError; end
|
8
8
|
|
9
|
-
attr_accessor :network, :token
|
9
|
+
attr_accessor :network, :token, :created_at, :updated_at, :reloaded_at
|
10
10
|
|
11
11
|
def initialize(token, filepath = nil)
|
12
12
|
Netica::NeticaLogger.info "initializing active network for #{token}"
|
13
|
+
self.created_at = Time.now
|
14
|
+
self.updated_at = Time.now
|
13
15
|
self.token = token
|
14
16
|
if filepath
|
15
17
|
self.network = BayesNetwork.new(filepath)
|
@@ -30,6 +32,7 @@ module Netica
|
|
30
32
|
if network
|
31
33
|
node = network.node(nodeName)
|
32
34
|
if node
|
35
|
+
self.updated_at = Time.now
|
33
36
|
return node.incr()
|
34
37
|
else
|
35
38
|
raise ActiveNetwork::NodeNotFound
|
@@ -41,12 +44,14 @@ module Netica
|
|
41
44
|
|
42
45
|
# Export the state of the ActiveNetwork as a Hash
|
43
46
|
#
|
44
|
-
# @param nodeName [String] name of the node to be incremented
|
45
47
|
# @return [Hash] network state and object class name
|
46
48
|
def state
|
47
49
|
{
|
48
|
-
:network
|
49
|
-
:class
|
50
|
+
:network => network.state,
|
51
|
+
:class => self.class.to_s,
|
52
|
+
:created_at => self.created_at,
|
53
|
+
:updated_at => self.updated_at,
|
54
|
+
:reloaded_at => self.reloaded_at
|
50
55
|
}
|
51
56
|
end
|
52
57
|
|
@@ -75,6 +80,7 @@ module Netica
|
|
75
80
|
hash = JSON.parse(stored_state)
|
76
81
|
active_network = Object.const_get(hash['class']).new(token)
|
77
82
|
active_network.load_from_saved_state(hash)
|
83
|
+
Netica::NeticaLogger.info "Network #{token} reloaded from saved state: #{hash}"
|
78
84
|
return active_network
|
79
85
|
else
|
80
86
|
Netica::NeticaLogger.info "Network #{token} not found in redis."
|
@@ -90,6 +96,7 @@ module Netica
|
|
90
96
|
def load_from_saved_state(hash)
|
91
97
|
self.network = BayesNetwork.new(hash["network"]["dne_file_path"])
|
92
98
|
self.network.load_from_state(hash["network"])
|
99
|
+
self.reloaded_at = Time.now
|
93
100
|
end
|
94
101
|
end
|
95
|
-
end
|
102
|
+
end
|
data/lib/netica/bayes_network.rb
CHANGED
@@ -5,6 +5,7 @@ module Netica
|
|
5
5
|
attr_accessor :current_network, :dne_file_path
|
6
6
|
|
7
7
|
def initialize(dne_file_path = nil)
|
8
|
+
Netica::NeticaLogger.info "Initializing #{self.class} #{self.object_id}"
|
8
9
|
if dne_file_path
|
9
10
|
self.dne_file_path = dne_file_path
|
10
11
|
load_dne_file
|
@@ -41,15 +42,19 @@ module Netica
|
|
41
42
|
end
|
42
43
|
|
43
44
|
def load_from_state(network_hash)
|
44
|
-
NeticaLogger.info "Loading state from network_hash => #{network_hash}"
|
45
|
+
Netica::NeticaLogger.info "Loading state from network_hash => #{network_hash}"
|
45
46
|
network_hash["decision_nodes"].each do |node_name, node_value|
|
46
|
-
NeticaLogger.info "Setting #{node_name} => #{node_value}"
|
47
|
+
Netica::NeticaLogger.info "Setting #{node_name} => #{node_value}"
|
47
48
|
node(node_name).value = node_value
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
52
|
def state
|
52
|
-
{
|
53
|
+
{
|
54
|
+
:dne_file_path => dne_file_path,
|
55
|
+
:decision_nodes => node_hash(decision_nodes),
|
56
|
+
:nature_nodes => node_hash(nature_nodes)
|
57
|
+
}
|
53
58
|
end
|
54
59
|
|
55
60
|
def node_hash(nodes)
|
@@ -86,4 +91,4 @@ module Netica
|
|
86
91
|
self.current_network.compile()
|
87
92
|
end
|
88
93
|
end
|
89
|
-
end
|
94
|
+
end
|
data/lib/netica/environment.rb
CHANGED
data/lib/netica/node.rb
CHANGED
data/lib/netica/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netica
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: java
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|