forked from JoshuaGrams/steno-jig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
number-sentences.js
72 lines (67 loc) · 2.22 KB
/
number-sentences.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Number Sentences
// ================
// Takes `timeLimit` parameter (floating-point minutes).
function numberSentences(params) {
var seconds = Math.round(60 * params.timeLimit);
exercise = new TypeJig.Exercise([], seconds);
exercise.nouns = TypeJig.WordSets.Nouns.slice();
exercise.actions = [].concat(
TypeJig.WordSets.TransitiveVerbs.map(function(v){return [v, 'v'];}),
TypeJig.WordSets.Adjectives.map(function(a){return [a, 'a'];})
);
randomize(exercise.nouns);
randomize(exercise.actions);
exercise.getText = getNumberText;
exercise.nextSentence = nextNumberSentence;
exercise.nextClause = nextNumberClause;
exercise.name = 'Number Sentences';
exercise.started = false;
return exercise;
}
function getNumberText() {
var sentence = (this.started ? ' ' : '') + this.nextSentence().join(' ');
this.started = true;
return sentence;
}
function nextNumberSentence() {
var type = ['.', '!', '?', ','][randomIntLessThan(4)];
var num = 2 + randomIntLessThan(98);
var noun = pluralize(rotateAndShuffle(this.nouns));
var action = rotateAndShuffle(this.actions);
var tense;
if(type === '?') tense = 0;
else tense = randomIntLessThan(2);
var s = this.nextClause(num, noun, action, tense);
s[s.length-1] += type;
if(type === '?') {
if(action[1] === 'v') {
s.unshift(['Do', 'Did'][randomIntLessThan(2)]);
} else if(action[1] === 'a') {
var verb = ['Are', 'Were'][randomIntLessThan(2)];
s.splice(2, 1);
s.unshift(verb);
}
} else if(type === ',') {
var conj = ['but', 'while', 'so', 'and', 'or'];
s.push(conj[randomIntLessThan(conj.length)]);
var num = 2 + randomIntLessThan(98);
var noun = pluralize(rotateAndShuffle(this.nouns));
var action = rotateAndShuffle(this.actions);
s = s.concat(this.nextClause(num, noun, action, tense));
s[s.length-1] += '.';
}
return s;
}
function nextNumberClause(num, noun, action, tense) {
if(action[1] === 'v') {
var verb = action[0][tense].split(' ');
var num2 = 1 + randomIntLessThan(99);
var noun2 = rotateAndShuffle(this.nouns);
if(num2 > 1) noun2 = pluralize(noun2);
return [].concat(num+'', noun, verb, num2+'', noun2);
} else {
verb = ["are", "were"];
var adjective = action[0].split(' ');
return [].concat(num+'', noun, verb[tense], adjective);
}
}