netica 0.0.5-java → 0.0.6-java
Sign up to get free protection for your applications and to get access to all the features.
- data/CONTRIBUTING.md +8 -0
- data/README.md +5 -6
- data/Rakefile +1 -0
- data/lib/netica.rb +2 -0
- data/lib/netica/active_network.rb +23 -2
- data/lib/netica/bayes_network.rb +6 -4
- data/lib/netica/environment.rb +4 -0
- data/lib/netica/java_library_path.rb +14 -0
- data/lib/netica/railtie.rb +9 -0
- data/lib/netica/version.rb +1 -1
- data/lib/tasks/netica.rake +8 -0
- data/spec/netica/active_network_spec.rb +1 -1
- metadata +6 -2
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
1. Fork it
|
4
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
5
|
+
3. Make your changes, including any tests.
|
6
|
+
4. Once your tests pass, commit your changes (`git commit -am 'Add some feature'`)
|
7
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
8
|
+
6. Create new Pull Request
|
data/README.md
CHANGED
@@ -65,14 +65,13 @@ Then, re-read the value of the Belief node.
|
|
65
65
|
0.09241089224815369
|
66
66
|
=> 0.09241089224815369
|
67
67
|
|
68
|
+
## Release Notes
|
68
69
|
|
69
|
-
|
70
|
+
### Version 0.0.6
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
75
|
-
5. Create new Pull Request
|
72
|
+
* Changed BayesNetwork#getNode to BayesNetwork#node
|
73
|
+
* Find a location for the NeticaJ.jar file using `rake netica:java_library_path`
|
74
|
+
* Expand documentation
|
76
75
|
|
77
76
|
## Legal
|
78
77
|
|
data/Rakefile
CHANGED
data/lib/netica.rb
CHANGED
@@ -8,7 +8,9 @@ require "netica/node"
|
|
8
8
|
require "netica/node_list"
|
9
9
|
require "netica/bayes_network"
|
10
10
|
require "netica/active_network"
|
11
|
+
require "netica/java_library_path"
|
11
12
|
|
12
13
|
module Netica
|
13
14
|
include_package "norsys.netica"
|
15
|
+
require "netica/railtie" if defined?(Rails)
|
14
16
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Netica
|
2
2
|
require 'json'
|
3
3
|
|
4
|
+
# provides a persistable object container for a Netica Bayes net.
|
4
5
|
class ActiveNetwork
|
5
6
|
attr_accessor :network, :token
|
6
7
|
|
@@ -18,10 +19,18 @@ module Netica
|
|
18
19
|
token
|
19
20
|
end
|
20
21
|
|
22
|
+
# Increment a specified network node
|
23
|
+
#
|
24
|
+
# @param nodeName [String] name of the node to be incremented
|
25
|
+
# @return [true,false,nil] outcome of the incr() attempt
|
21
26
|
def incr_node(nodeName)
|
22
|
-
network.
|
27
|
+
network.node(nodeName).incr() if network
|
23
28
|
end
|
24
29
|
|
30
|
+
# Export the state of the ActiveNetwork as a Hash
|
31
|
+
#
|
32
|
+
# @param nodeName [String] name of the node to be incremented
|
33
|
+
# @return [Hash] network state and object class name
|
25
34
|
def state
|
26
35
|
{
|
27
36
|
:network => network.state,
|
@@ -29,12 +38,20 @@ module Netica
|
|
29
38
|
}
|
30
39
|
end
|
31
40
|
|
41
|
+
# Save ActiveNetwork to an associated redis store, if one is defined.
|
42
|
+
#
|
43
|
+
# @return [true,false,nil] outcome of redis.set, or nil if redis is not found
|
32
44
|
def save
|
33
45
|
if Netica::Environment.instance.redis
|
34
|
-
Netica::Environment.instance.redis.set(token, JSON.dump(state))
|
46
|
+
return Netica::Environment.instance.redis.set(token, JSON.dump(state))
|
35
47
|
end
|
36
48
|
end
|
37
49
|
|
50
|
+
# Retrieve ActiveNetwork from current Netica Environment instance
|
51
|
+
# or an associated redis store, if one is defined.
|
52
|
+
#
|
53
|
+
# @param token [String] identifying token for ActiveNetwork sought
|
54
|
+
# @return [ActiveNetwork] ActiveNetwork object found
|
38
55
|
def self.find(token)
|
39
56
|
Netica::Environment.instance.active_networks.each do |an|
|
40
57
|
return an if an.token == token
|
@@ -51,6 +68,10 @@ module Netica
|
|
51
68
|
return nil
|
52
69
|
end
|
53
70
|
|
71
|
+
# Export the state of the ActiveNetwork as a Hash
|
72
|
+
#
|
73
|
+
# @param hash [Hash] network state to be restored
|
74
|
+
# @return [Hash] network state and object class name
|
54
75
|
def load_from_saved_state(hash)
|
55
76
|
self.network = BayesNetwork.new(hash["network"]["dne_file_path"])
|
56
77
|
network.load_from_state(hash["network"])
|
data/lib/netica/bayes_network.rb
CHANGED
@@ -9,9 +9,11 @@ module Netica
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
# retrieve
|
13
|
-
#
|
14
|
-
#
|
12
|
+
# retrieve the node from the associated network whose name matches
|
13
|
+
# the "nodeName" supplied.
|
14
|
+
#
|
15
|
+
# @param nodeName [String] Name of the node to find
|
16
|
+
# @return [Node]
|
15
17
|
def node(nodeName)
|
16
18
|
nodes.select{ |n| n if n.name == nodeName }[0]
|
17
19
|
end
|
@@ -31,7 +33,7 @@ module Netica
|
|
31
33
|
def load_from_state(network_hash)
|
32
34
|
NeticaLogger.info "network_hash => #{network_hash}"
|
33
35
|
network_hash["decision_nodes"].each do |node_name, node_value|
|
34
|
-
|
36
|
+
node(node_name).value = node_value
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
data/lib/netica/environment.rb
CHANGED
@@ -11,6 +11,10 @@ module Netica
|
|
11
11
|
@@redis = nil
|
12
12
|
@@logfile = nil
|
13
13
|
|
14
|
+
# Initializes logging, a Netica Environ object and a connection to
|
15
|
+
# redis, if defined.
|
16
|
+
#
|
17
|
+
# @param settings [Hash] Settings for initialization
|
14
18
|
def self.engage(settings = {})
|
15
19
|
if settings[:logfile]
|
16
20
|
@@logfile = settings[:logfile]
|
@@ -0,0 +1,14 @@
|
|
1
|
+
include Java
|
2
|
+
java_import java.lang.System
|
3
|
+
|
4
|
+
module Netica
|
5
|
+
class Tools
|
6
|
+
def self.library_path
|
7
|
+
str = "Place NeticaJ.jar in one of the following locations:\n"
|
8
|
+
System.getProperties["java.library.path"].split(':').each do |pth|
|
9
|
+
str << " => #{pth}\n" unless pth == '.'
|
10
|
+
end
|
11
|
+
str
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
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.6
|
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-04-
|
12
|
+
date: 2013-04-23 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Netica Bayes Network Management
|
15
15
|
email:
|
@@ -20,6 +20,7 @@ extra_rdoc_files: []
|
|
20
20
|
files:
|
21
21
|
- ".gitignore"
|
22
22
|
- ".rspec"
|
23
|
+
- CONTRIBUTING.md
|
23
24
|
- Gemfile
|
24
25
|
- LICENSE.txt
|
25
26
|
- README.md
|
@@ -30,11 +31,14 @@ files:
|
|
30
31
|
- lib/netica/active_network.rb
|
31
32
|
- lib/netica/bayes_network.rb
|
32
33
|
- lib/netica/environment.rb
|
34
|
+
- lib/netica/java_library_path.rb
|
33
35
|
- lib/netica/netica_logger.rb
|
34
36
|
- lib/netica/node.rb
|
35
37
|
- lib/netica/node_list.rb
|
38
|
+
- lib/netica/railtie.rb
|
36
39
|
- lib/netica/state.rb
|
37
40
|
- lib/netica/version.rb
|
41
|
+
- lib/tasks/netica.rake
|
38
42
|
- netica.gemspec
|
39
43
|
- spec/netica/active_network_spec.rb
|
40
44
|
- spec/netica/environment_spec.rb
|