netica 0.0.10-java → 0.0.15-java
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/netica.rb +2 -2
- data/lib/netica/active_network.rb +17 -7
- data/lib/netica/environ.rb +11 -0
- data/lib/netica/environment.rb +17 -4
- data/lib/netica/version.rb +1 -1
- data/spec/netica/active_network_spec.rb +4 -0
- data/spec/netica/environment_spec.rb +10 -0
- metadata +3 -2
data/lib/netica.rb
CHANGED
@@ -2,6 +2,7 @@ require 'java'
|
|
2
2
|
require '/lib/NeticaJ.jar'
|
3
3
|
|
4
4
|
require "netica/version"
|
5
|
+
require "netica/environ"
|
5
6
|
require "netica/environment"
|
6
7
|
require "netica/netica_logger"
|
7
8
|
require "netica/node"
|
@@ -10,9 +11,8 @@ require "netica/bayes_network"
|
|
10
11
|
require "netica/active_network"
|
11
12
|
require "netica/java_library_path"
|
12
13
|
|
13
|
-
Java::NorsysNetica::Environ.__persistent__ = true
|
14
|
-
|
15
14
|
module Netica
|
16
15
|
include_package "norsys.netica"
|
16
|
+
Java::NorsysNetica::Environ.__persistent__ = true
|
17
17
|
require "netica/railtie" if defined?(Rails)
|
18
18
|
end
|
@@ -6,13 +6,15 @@ 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
|
9
|
+
attr_accessor :network, :token, :created_at, :updated_at, :reloaded_at, :in_use
|
10
10
|
|
11
11
|
def initialize(token, filepath = nil)
|
12
|
-
Netica::NeticaLogger.info "
|
12
|
+
Netica::NeticaLogger.info "Initializing #{self.class} for #{token}."
|
13
13
|
self.created_at = Time.now
|
14
14
|
self.updated_at = Time.now
|
15
|
-
self.token
|
15
|
+
self.token = token
|
16
|
+
self.in_use = false
|
17
|
+
|
16
18
|
if filepath
|
17
19
|
self.network = BayesNetwork.new(filepath)
|
18
20
|
end
|
@@ -36,7 +38,7 @@ module Netica
|
|
36
38
|
self.updated_at = Time.now
|
37
39
|
return node.incr()
|
38
40
|
else
|
39
|
-
raise ActiveNetwork::NodeNotFound
|
41
|
+
raise ActiveNetwork::NodeNotFound, "Node #{nodeName} not found in network."
|
40
42
|
end
|
41
43
|
else
|
42
44
|
raise ActiveNetwork::NetworkNotFound
|
@@ -71,10 +73,18 @@ module Netica
|
|
71
73
|
# @param token [String] identifying token for ActiveNetwork sought
|
72
74
|
# @return [ActiveNetwork] ActiveNetwork object found
|
73
75
|
def self.find(token)
|
74
|
-
Netica::Environment.instance
|
75
|
-
|
76
|
+
environment = Netica::Environment.instance
|
77
|
+
Netica::NeticaLogger.info "Searching in #{environment.network_container.class} #{environment.network_container.object_id} (length: #{environment.network_container.length}) for #{token}."
|
78
|
+
environment.network_container.each do |an|
|
79
|
+
if an.token == token
|
80
|
+
until !an.in_use
|
81
|
+
Netica::NeticaLogger.info "Network #{token} is locked."
|
82
|
+
wait 1000
|
83
|
+
end
|
84
|
+
return an
|
85
|
+
end
|
76
86
|
end
|
77
|
-
Netica::NeticaLogger.info "Network #{token} not found in current instance."
|
87
|
+
Netica::NeticaLogger.info "Network #{token} not found in current instance #{environment.object_id}."
|
78
88
|
if Netica::Environment.instance.redis
|
79
89
|
stored_state = Netica::Environment.instance.redis.get(token)
|
80
90
|
if stored_state
|
data/lib/netica/environment.rb
CHANGED
@@ -4,9 +4,8 @@ require 'redis'
|
|
4
4
|
module Netica
|
5
5
|
class Environment
|
6
6
|
include Singleton
|
7
|
-
|
8
|
-
@@
|
9
|
-
@@explorations = []
|
7
|
+
|
8
|
+
@@network_container = []
|
10
9
|
@@processor = nil
|
11
10
|
@@redis = nil
|
12
11
|
@@logfile = nil
|
@@ -26,9 +25,19 @@ module Netica
|
|
26
25
|
else
|
27
26
|
@@processor = Java::NorsysNetica::Environ.new(nil)
|
28
27
|
end
|
28
|
+
#@@processor.control_concurrency("ExternalThreads", "OptimizeSafely")
|
29
|
+
@@processor.control_concurrency("ExternalThreads", "Serialize")
|
29
30
|
if settings[:redis]
|
30
31
|
@@redis = Redis.new(settings[:redis])
|
31
32
|
end
|
33
|
+
|
34
|
+
if settings[:network_container]
|
35
|
+
@@network_container = settings[:network_container]
|
36
|
+
else
|
37
|
+
@@network_container = @@processor.active_networks
|
38
|
+
end
|
39
|
+
|
40
|
+
NeticaLogger.info "@@network_container is #{@@network_container.class} #{@@network_container.object_id}."
|
32
41
|
NeticaLogger.info "Initializing the Netica Environment #{@@processor.object_id}"
|
33
42
|
end
|
34
43
|
|
@@ -37,7 +46,11 @@ module Netica
|
|
37
46
|
end
|
38
47
|
|
39
48
|
def active_networks
|
40
|
-
@@
|
49
|
+
@@network_container
|
50
|
+
end
|
51
|
+
|
52
|
+
def network_container
|
53
|
+
@@network_container
|
41
54
|
end
|
42
55
|
|
43
56
|
def redis
|
data/lib/netica/version.rb
CHANGED
@@ -26,6 +26,10 @@ describe Netica::ActiveNetwork do
|
|
26
26
|
it "should export its state as a hash" do
|
27
27
|
@active_network.network.state.should be_an_instance_of(Hash)
|
28
28
|
end
|
29
|
+
|
30
|
+
it "should be returned when searched for" do
|
31
|
+
Netica::ActiveNetwork.find("fake_token_identifier").should === @active_network
|
32
|
+
end
|
29
33
|
|
30
34
|
context "the tuberculosis node" do
|
31
35
|
it "should be less than 0.02 initially" do
|
@@ -12,5 +12,15 @@ describe Netica::Environment do
|
|
12
12
|
Netica::NeticaLogger.info "Test logfile entry"
|
13
13
|
Netica::Environment.instance.processor.finalize
|
14
14
|
end
|
15
|
+
|
16
|
+
context "with a specified storage container" do
|
17
|
+
it 'should store active_networks in the storage container' do
|
18
|
+
@active_networks = []
|
19
|
+
Netica::Environment.engage(:network_container => @active_networks)
|
20
|
+
Netica::ActiveNetwork.new("fake_token_identifier", "#{File.dirname(__FILE__)}/../../examples/ChestClinic.dne")
|
21
|
+
@active_networks.length.should == 1
|
22
|
+
Netica::Environment.instance.processor.finalize
|
23
|
+
end
|
24
|
+
end
|
15
25
|
end
|
16
26
|
end
|
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.15
|
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-07-
|
12
|
+
date: 2013-07-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- lib/netica.rb
|
50
50
|
- lib/netica/active_network.rb
|
51
51
|
- lib/netica/bayes_network.rb
|
52
|
+
- lib/netica/environ.rb
|
52
53
|
- lib/netica/environment.rb
|
53
54
|
- lib/netica/java_library_path.rb
|
54
55
|
- lib/netica/netica_logger.rb
|