sooth 0.2.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a0e008c93f017523bc6e99798d7542834d420e7
4
- data.tar.gz: 7a4db4e52debe1fceecd1c6d5e4f72117e01de9c
3
+ metadata.gz: d6ee402b249e9c9a15a067e007f83a932f1024f6
4
+ data.tar.gz: 0a815d99956cc8701d3ac094b37d091bbe282137
5
5
  SHA512:
6
- metadata.gz: cd0f597a68319410bc4022d1fde21c7e62571568e536ebdf281f7eeb0eb336271c960682aa910963dad1a58892b64f0bf7cfc177ce04949238d08c8766675ec0
7
- data.tar.gz: 5c7d01ff70fac54ad884303341c3c9de87d9ef4ad5fd7528b8b52a49c3f2b1eef42b100d4a5d9137dc432fc61b32ac643cf64a245edba96bd756ea4d965cf455
6
+ metadata.gz: c1c1340951c1045048cae75ee46805724b8dac5480493fc50b4e18f189478677725c9dc729c8295677ef9ebdee0a740648f7724f528d4a2c2931157c9d04792d
7
+ data.tar.gz: a076a7603490c70fd4aa9d87ad3f93dfdb53621f3afdecb3aad9260904065a8112c4a877c31130315be3f34e8ecf66ecc15f35e49c1cd647ae854d4b7f8ca9eb
data/README.md CHANGED
@@ -5,7 +5,8 @@
5
5
  Sooth
6
6
  =====
7
7
 
8
- Sooth is a simple stochastic predictive model. It is used by [MegaHAL](https://github.com/jasonhutchens/megahal).
8
+ Sooth is a simple stochastic predictive model. It is used by
9
+ [MegaHAL](https://github.com/jasonhutchens/megahal), a learning chatterbot.
9
10
 
10
11
  Getting Started
11
12
  ---------------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -20,6 +20,12 @@ void method_sooth_native_deallocate(void * predictor);
20
20
  * class Predictor
21
21
  * def initialize(error_symbol)
22
22
  * end
23
+ * def clear
24
+ * end
25
+ * def load(filename)
26
+ * end
27
+ * def save(filename)
28
+ * end
23
29
  * def observe(bigram, symbol)
24
30
  * # (native code)
25
31
  * end
@@ -39,6 +45,26 @@ void method_sooth_native_deallocate(void * predictor);
39
45
  */
40
46
  VALUE method_sooth_native_initialize(VALUE self, VALUE error_symbol);
41
47
 
48
+ /*
49
+ * Clear the predictor to a fresh slate.
50
+ */
51
+ VALUE method_sooth_native_clear(VALUE self);
52
+
53
+ /*
54
+ * Load the predictor from the specified filename. The predictor will be cleared
55
+ * before the file is loaded.
56
+ *
57
+ * @param [String] filename The path of the file to be loaded.
58
+ */
59
+ VALUE method_sooth_native_load(VALUE self, VALUE filename);
60
+
61
+ /*
62
+ * Save the predictor to a file that can be loaded or merged later.
63
+ *
64
+ * @param [String] filename The path of the file to be merge.
65
+ */
66
+ VALUE method_sooth_native_save(VALUE self, VALUE filename);
67
+
42
68
  /*
43
69
  * Add an observation of the given symbol in the context of the bigram.
44
70
  *
@@ -90,6 +116,10 @@ void Init_sooth_native()
90
116
  rb_define_alloc_func(SoothNative, method_sooth_native_allocate);
91
117
  rb_define_method(SoothNative, "initialize", method_sooth_native_initialize, 1);
92
118
 
119
+ rb_define_method(SoothNative, "clear", method_sooth_native_clear, 0);
120
+ rb_define_method(SoothNative, "load", method_sooth_native_load, 1);
121
+ rb_define_method(SoothNative, "save", method_sooth_native_save, 1);
122
+
93
123
  rb_define_method(SoothNative, "observe", method_sooth_native_observe, 2);
94
124
  rb_define_method(SoothNative, "count", method_sooth_native_count, 1);
95
125
  rb_define_method(SoothNative, "select", method_sooth_native_select, 2);
@@ -130,6 +160,33 @@ method_sooth_native_initialize(VALUE self, VALUE error_symbol)
130
160
 
131
161
  //------------------------------------------------------------------------------
132
162
 
163
+ VALUE
164
+ method_sooth_native_clear(VALUE self)
165
+ {
166
+ SoothPredictor * predictor = NULL;
167
+ Data_Get_Struct(self, SoothPredictor, predictor);
168
+ sooth_predictor_clear(predictor);
169
+ return Qnil;
170
+ }
171
+
172
+ //------------------------------------------------------------------------------
173
+
174
+ VALUE
175
+ method_sooth_native_load(VALUE self, VALUE filename)
176
+ {
177
+ return Qnil;
178
+ }
179
+
180
+ //------------------------------------------------------------------------------
181
+
182
+ VALUE
183
+ method_sooth_native_save(VALUE self, VALUE filename)
184
+ {
185
+ return Qnil;
186
+ }
187
+
188
+ //------------------------------------------------------------------------------
189
+
133
190
  VALUE
134
191
  method_sooth_native_observe(VALUE self, VALUE bigram, VALUE symbol)
135
192
  {
@@ -18,7 +18,6 @@ sooth_predictor_init()
18
18
  }
19
19
 
20
20
  predictor->error_symbol = 0;
21
-
22
21
  predictor->contexts = NULL;
23
22
  predictor->contexts_size = 0;
24
23
 
@@ -28,7 +27,7 @@ sooth_predictor_init()
28
27
  //------------------------------------------------------------------------------
29
28
 
30
29
  void
31
- sooth_predictor_free(SoothPredictor * predictor)
30
+ sooth_predictor_clear(SoothPredictor * predictor)
32
31
  {
33
32
  for (uint64_t i = 0; i < predictor->contexts_size; ++i)
34
33
  {
@@ -41,7 +40,14 @@ sooth_predictor_free(SoothPredictor * predictor)
41
40
  free(predictor->contexts);
42
41
  predictor->contexts = NULL;
43
42
  predictor->contexts_size = 0;
43
+ }
44
44
 
45
+ //------------------------------------------------------------------------------
46
+
47
+ void
48
+ sooth_predictor_free(SoothPredictor * predictor)
49
+ {
50
+ sooth_predictor_clear(predictor);
45
51
  free(predictor);
46
52
  }
47
53
 
@@ -54,10 +60,15 @@ sooth_predictor_save(const char * const filename, SoothPredictor * predictor)
54
60
 
55
61
  //------------------------------------------------------------------------------
56
62
 
57
- SoothPredictor *
58
- sooth_predictor_load(const char * const filename)
63
+ void sooth_predictor_merge(const char * const filename, SoothPredictor * predictor)
64
+ {
65
+ }
66
+ //------------------------------------------------------------------------------
67
+
68
+ void sooth_predictor_load(const char * const filename, SoothPredictor * predictor)
59
69
  {
60
- return NULL;
70
+ sooth_predictor_clear(predictor);
71
+ sooth_predictor_merge(predictor, filename);
61
72
  }
62
73
 
63
74
  //------------------------------------------------------------------------------
@@ -18,9 +18,11 @@ SoothPredictor;
18
18
  //------------------------------------------------------------------------------
19
19
 
20
20
  SoothPredictor * sooth_predictor_init();
21
+ void sooth_predictor_clear(SoothPredictor * predictor);
21
22
  void sooth_predictor_free(SoothPredictor * predictor);
23
+ void sooth_predictor_merge(const char * const filename, SoothPredictor * predictor);
24
+ void sooth_predictor_load(const char * const filename, SoothPredictor * predictor);
22
25
  void sooth_predictor_save(const char * const filename, SoothPredictor * predictor);
23
- SoothPredictor * sooth_predictor_load(const char * const filename);
24
26
  uint32_t sooth_predictor_observe(SoothPredictor * predictor, uint32_t bigram[2], uint32_t symbol);
25
27
  uint64_t sooth_predictor_count(SoothPredictor * predictor, uint32_t bigram[2]);
26
28
  uint32_t sooth_predictor_select(SoothPredictor * predictor, uint32_t bigram[2], uint64_t limit);
data/sooth.gemspec CHANGED
@@ -2,17 +2,17 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: sooth 0.2.0 ruby lib
5
+ # stub: sooth 0.3.0 ruby lib
6
6
  # stub: ext/sooth_native/extconf.rb
7
7
 
8
8
  Gem::Specification.new do |s|
9
9
  s.name = "sooth"
10
- s.version = "0.2.0"
10
+ s.version = "0.3.0"
11
11
 
12
12
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
13
13
  s.require_paths = ["lib"]
14
14
  s.authors = ["Jason Hutchens"]
15
- s.date = "2014-12-10"
15
+ s.date = "2014-12-11"
16
16
  s.description = "Sooth is a simple stochastic predictive model."
17
17
  s.email = "jasonhutchens@gmail.com"
18
18
  s.extensions = ["ext/sooth_native/extconf.rb"]
@@ -88,4 +88,18 @@ describe Sooth::Predictor do
88
88
  expect(predictor.select([3,2], 4)).to eq(42)
89
89
  end
90
90
  end
91
+
92
+ describe "#clear" do
93
+
94
+ it "clears to a blank slate" do
95
+ expect(predictor.observe([1,2], 3)).to eq(1)
96
+ expect(predictor.observe([1,2], 3)).to eq(2)
97
+ expect(predictor.observe([1,2], 3)).to eq(3)
98
+ predictor.clear
99
+ expect(predictor.observe([1,2], 3)).to eq(1)
100
+ expect(predictor.observe([1,2], 3)).to eq(2)
101
+ expect(predictor.observe([1,2], 3)).to eq(3)
102
+ end
103
+
104
+ end
91
105
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sooth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Hutchens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-10 00:00:00.000000000 Z
11
+ date: 2014-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec