@jdeighan/spaced-rep
v1.0.1
Published
implementation of spaced repetition
Downloads
1
Readme
The spaced repetition algorithm
The algorithm is implemented via a WordList
object in
the following methods:
- getNextWordToLearn()
- resultWas()
The WordList
class extends the BaseWordList
class.
A BaseWordList object contains
Words, each of which is
a hash with language codes as keys (e.g. 'en' is English,
'zh' is Chinese, etc.) where the values are the given
word in the given language. The method
getUnseenreturns the words in order of "importance", roughly amount
of usage or difficulty. Each
Word` object (hash) also
includes the following keys:
index - order of the Word in the `BaseWordList`
state - undef for words in the `unseen set`
'working' for words in the 'working set'
'learned' for words in the 'learned set'
dueAt - timestamp when word is due if in 'working set'
lHistory - array of result values if in 'working set'
numCorrect - number of correct reviews if in 'learned set'
In a WordList
object:
Any words in the
LearnedWords
object exist in only one of 3 sets: 1) Theunseen
set, 2) theworking
set or 3) thelearned
setInitially, all words in the
WordList
are in theunseen
set. TheBaseWordList
class maintains the words in an ordered array and has a property namednextUnseenWordPos
, initially 0. The words at this position and higher are implicitly theunseen
set. When the methodgetUnseen()
is called, the word at this position is returned and the property is incremented by 1.Each word in the
learned set
is stored in the arraylLearned[n] where n is the number of times this word was correctly identified in a review (i.e. after passing the
workingphase). That is, lLearned is an array of arrays. The word will also have a key named
numCorrect` which is set to n.Each
Word
in theworking set
has a field namedhistory
which is an array of results achieved during testing (currently only RIGHT=1, WRONG=2). It also has a field nameddueAt
specifying the date and time that the word is dueBoth the
working set
and thelearned set
are maintained in the order of thedueAt
field
Algorithm for getNextWordToLearn()
if we want a review word
find 1st word in lLearned that is not state 'review'
mark it as state 'review'
return it
else
find 1st word in lWorking that is not state 'working'
if it exists and is due
mark it as state 'working
return it
else if lWorking.size < workingSetSize
get another word from 'unseen set'
push it onto lWorking
set state to 'working
return that word
elsif next word in the working set
exists and is due
return that word
elsif size of working set
< workingSetSize
retrieve next word in unseen set
if word is defined
place that word in the working set
return that word
else
we're done!!!
A Word can be in any of 3 states: 1) 'unseen', 2) 'learning' or 3) 'learned'. All words are initially in the 'unseen' state. The following events are possible:
State 'unseen' FETCH setState 'learning', {lHistory: []}
State 'learning' TEST setState 'testing', {outcome: undef}
State 'testing' TEST_OUTCOME assert defined(outcome, lHistory) append outcome to lHistory while lHistory.size > 5 remove 1st item in lHistory if lHistory is 5 correct setState 'learned', {numReviews: 0} else setState 'learning'
State 'learned' REVIEW setState 'reviewing', {outcome: undef}
State 'reviewing' REVIEW_OUTCOME assert defined(outcome) if outcome == RIGHT increment numReviews setState 'learned' else setState 'learning', {lHistory: []}