tworgy-spaced-repetition 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Mat Holroyd
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,45 @@
1
+ = Spaced Repetition
2
+
3
+ Ruby gem that implements the SM-2 algorithm of SuperMemo. See http://www.supermemo.com/english/ol/sm2.htm for more details.
4
+
5
+ The plan is to add more algorithms in the future, e.g. Mnemosyne.
6
+
7
+ == Install
8
+
9
+ gem install tworgy-spaced-repetition
10
+
11
+ == Usage
12
+
13
+ The gem provides a mixin which should be added to a class that represents something you want to remember, e.g. a flash card class. The mixin adds several methods (described below) to calculate the date when the next repetition should occur.
14
+
15
+ Importantly, the mixin depends on several methods existing on the hosting class. The mixin should throw an exception if it cannot find the appropriate methods.
16
+
17
+ class FlashCardExample
18
+ attr_accessor :easiness_factor, :number_repetitions, :quality_of_last_recall, :next_repetition
19
+
20
+ include SuperMemo::SM2
21
+ end
22
+
23
+ Create an instance of the object as per usual
24
+
25
+ fc = FlashCardExample.new
26
+
27
+ Reset the data to begin with
28
+
29
+ fc.reset_spaced_repetition_data
30
+ fc.easiness_factor => 2.5
31
+ fc.number_repetitions => 0
32
+ fc.quality_of_last_recall => nil
33
+ fc.next_repetition => Date.today
34
+
35
+ Calculate the next interval/date (Note: SM2 expects a number between 0-5)
36
+
37
+ fc.process_recall_result(4)
38
+
39
+ fc.repetition_interval => 1 (day)
40
+ fc.next_repetition => tomorrow (Date.today + 1 day)
41
+
42
+ == Notes
43
+
44
+ Currently this gem only includes the SM-2 version of the SuperMemo algorithm. Although more recent versions of the SuperMemo algorithm exist, some popular open source and commercial alternatives to SuperMemo (such as Mnemosyne) base their algorithms on the SM-2 algorithm, as they judge it a superior algorithm to the more recent iterations. The author of Mnemosyne (the leading open source alternative) makes the point that there is a conflict of interest underlying commercial products like SuperMemo, in that companies have a vested interest in claiming the newer algorithms are better regardless of whether they actually are.
45
+
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "tworgy-spaced-repetition"
8
+ gem.summary = %Q{Spaced repetition algorithms and mixins}
9
+ gem.description = %Q{A collection of spaced-reptetition algorithms and mixins e.g. SuperMemo}
10
+ gem.email = "code@tworgy.com"
11
+ gem.homepage = "http://github.com/matholroyd/tworgy-spaced-repetition"
12
+ gem.authors = ["Mat Holroyd"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.files = %w(LICENSE README.rdoc Rakefile) + Dir.glob("{lib,spec}/**/*")
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "tworgy-spaced-repetition #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
@@ -0,0 +1,69 @@
1
+ module SuperMemo
2
+
3
+ # This module can be used as a mixin to add the algorithms as used by
4
+ # SuperMemo 2 (typically referred to as SM2).
5
+ #
6
+ # See the README for more information.
7
+ module SM2
8
+
9
+ def SM2.extended(obj)
10
+ obj.check_spaced_repetition_methods
11
+ end
12
+
13
+ def reset_spaced_repetition_data
14
+ self.easiness_factor = 2.5
15
+ self.number_repetitions = 0
16
+ self.quality_of_last_recall = nil
17
+ self.repetition_interval = nil
18
+ self.next_repetition = Date.today
19
+ end
20
+
21
+ def process_recall_result(quality_of_recall)
22
+ DBC.require(quality_of_recall >= 0)
23
+ DBC.require(quality_of_recall <= 5)
24
+
25
+ if quality_of_recall < 3
26
+ self.number_repetitions = 0
27
+ else
28
+ self.number_repetitions += 1
29
+ self.easiness_factor = calculate_easiness_factor(easiness_factor, quality_of_recall)
30
+ end
31
+
32
+ case number_repetitions
33
+ when 0
34
+ self.repetition_interval = 0
35
+ when 1
36
+ self.repetition_interval = 1
37
+ when 2
38
+ self.repetition_interval = 6
39
+ else
40
+ self.repetition_interval = repetition_interval * easiness_factor
41
+ end
42
+
43
+ self.next_repetition = Date.today + repetition_interval
44
+ end
45
+
46
+ def check_spaced_repetition_methods
47
+ begin
48
+ send(:easiness_factor)
49
+ send(:number_repetitions)
50
+ send(:quality_of_last_recall)
51
+ send(:next_repetition)
52
+ send(:repetition_interval)
53
+ rescue NoMethodError => e
54
+ DBC.assert(false, e.message)
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def calculate_easiness_factor(easiness_factor, quality_of_recall)
61
+ q = quality_of_recall
62
+ ef_old = easiness_factor
63
+
64
+ result = ef_old - 0.8 + (0.28*q) - (0.02*q*q)
65
+ result < 1.3 ? 1.3 : result
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1 @@
1
+ # require 'tworgy/testing'
@@ -0,0 +1 @@
1
+ require 'spaced-repetition/sm2'
@@ -0,0 +1,81 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
2
+
3
+ describe SuperMemo::SM2 do
4
+
5
+ describe 'include mixin' do
6
+
7
+ it 'should work fine when including' do
8
+ class Temp
9
+ attr_accessor :easiness_factor, :number_repetitions, :quality_of_last_recall, :next_repetition, :repetition_interval
10
+ include SuperMemo::SM2
11
+ end
12
+
13
+ t = Temp.new
14
+ t.check_spaced_repetition_methods
15
+ end
16
+
17
+ it 'should raise DBC exception if class including is missing fields' do
18
+ class Temp2
19
+ include SuperMemo::SM2
20
+ end
21
+ t = Temp2.new
22
+
23
+ lambda {
24
+ t.check_spaced_repetition_methods
25
+ }.should raise_error(DBC::AssertconditionException)
26
+ end
27
+
28
+ end
29
+
30
+ describe 'exclude mixin' do
31
+
32
+ before :each do
33
+ @flash_card = {
34
+ :easiness_factor => nil,
35
+ :number_repetitions => nil,
36
+ :quality_of_last_recall => nil,
37
+ :next_repetition => nil,
38
+ :repetition_interval => nil,
39
+ :question => "Who is the most awesome of them all?",
40
+ :answer => 'Me!'
41
+ }.ostructify
42
+
43
+ @flash_card.extend SuperMemo::SM2
44
+ @flash_card.reset_spaced_repetition_data
45
+ end
46
+
47
+ it 'should raise DBC exception if class extended is missing fields' do
48
+ lambda { nil.extend SuperMemo::SM2 }.should raise_error(DBC::AssertconditionException)
49
+ end
50
+
51
+ it 'should initialize values' do
52
+ @flash_card.easiness_factor.should == 2.5
53
+ @flash_card.number_repetitions.should == 0
54
+ @flash_card.repetition_interval.should == nil
55
+ @flash_card.quality_of_last_recall.should == nil
56
+ @flash_card.next_repetition.should == Date.today
57
+ end
58
+
59
+ it 'should schedule next repetition for tomorrow if repetition_interval = 0 and quality_of_last_recall = 4' do
60
+ @flash_card.process_recall_result(4)
61
+
62
+ @flash_card.number_repetitions.should == 1
63
+ @flash_card.repetition_interval.should == 1
64
+ @flash_card.next_repetition.should == (Date.today + 1)
65
+ @flash_card.easiness_factor.should be_close(2.5, 0.01)
66
+ end
67
+
68
+ it 'should schedule next repetition for 6 days if repetition_interval = 1 and quality_of_last_recall = 4' do
69
+ @flash_card.process_recall_result(4)
70
+ @flash_card.process_recall_result(4)
71
+
72
+ @flash_card.number_repetitions.should == 2
73
+ @flash_card.repetition_interval.should == 6
74
+ @flash_card.next_repetition.should == (Date.today + 6)
75
+ @flash_card.easiness_factor.should be_close(2.5, 0.01)
76
+ end
77
+
78
+ end
79
+
80
+
81
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
2
+
3
+ describe 'rspec helper' do
4
+ # it 'should capture nothing' do
5
+ # capture_stderr {
6
+ # 1 + 1
7
+ # 1.to_s
8
+ # }.should == ""
9
+ # end
10
+ #
11
+ # it 'should capture errors on stderr' do
12
+ # capture_stderr {
13
+ # [].id
14
+ # }.should =~ /Object#id will be deprecated/
15
+ # end
16
+ #
17
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'rubygems'
5
+ require 'tworgy-ruby'
6
+ require 'tworgy-spaced-repetition'
7
+ require 'tworgy-spaced-repetition-testing'
8
+ require 'spec'
9
+ require 'spec/autorun'
10
+
11
+ Spec::Runner.configure do |config|
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tworgy-spaced-repetition
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Mat Holroyd
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-22 00:00:00 +11:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
25
+ description: A collection of spaced-reptetition algorithms and mixins e.g. SuperMemo
26
+ email: code@tworgy.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - LICENSE
36
+ - README.rdoc
37
+ - Rakefile
38
+ - lib/spaced-repetition/sm2.rb
39
+ - lib/tworgy-spaced-repetition-testing.rb
40
+ - lib/tworgy-spaced-repetition.rb
41
+ - spec/lib/spaced-repetition/sm2_spec.rb
42
+ - spec/lib/spaced-repetition/testing_spec.rb
43
+ - spec/spec.opts
44
+ - spec/spec_helper.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/matholroyd/tworgy-spaced-repetition
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --charset=UTF-8
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.5
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Spaced repetition algorithms and mixins
73
+ test_files:
74
+ - spec/lib/spaced-repetition/sm2_spec.rb
75
+ - spec/lib/spaced-repetition/testing_spec.rb
76
+ - spec/spec_helper.rb