netica 0.0.8-java → 0.0.9-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.
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 => network.state,
49
- :class => self.class.to_s
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
@@ -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
- { :dne_file_path => dne_file_path, :decision_nodes => node_hash(decision_nodes), :nature_nodes => node_hash(nature_nodes) }
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
@@ -48,4 +48,4 @@ module Netica
48
48
  @@logfile
49
49
  end
50
50
  end
51
- end
51
+ end
data/lib/netica/node.rb CHANGED
@@ -97,7 +97,7 @@ class Java::NorsysNetica::Node
97
97
 
98
98
  def free
99
99
  begin
100
- NeticaLogger.info "Deleting #{self.to_s}"
100
+ Netica::NeticaLogger.info "Deleting #{self.to_s}"
101
101
  finalize()
102
102
  delete()
103
103
  states.each{|s| s==nil or s.free() }
@@ -1,3 +1,3 @@
1
1
  module Netica
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  describe Netica::ActiveNetwork do
4
4
  describe "#new" do
5
5
  before(:all) do
6
+ Java::NorsysNetica::Environ.__persistent__ = true
6
7
  Netica::Environment.engage
7
8
  end
8
9
  after(:all) do
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.8
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-05-30 00:00:00.000000000 Z
12
+ date: 2013-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis