-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdict-readablepassphrase.js
More file actions
3123 lines (3021 loc) · 226 KB
/
Copy pathdict-readablepassphrase.js
File metadata and controls
3123 lines (3021 loc) · 226 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file This is a port of the C# ReadablePassphraseGenerator, by Murray Grant
* @author Steven Zeck <saintly@innocent.com>
* @version 1.0.1
* @license Apache-2
*
*
* ReadablePassphrase objects generate random english sentences
* @param {(string|object)} [template] - create a sentence using the given template (either a string name of a predefined template, or an RPSentenceTemplate object)
* @param {(string|object)} [mutator] - use a mutator to add random uppercase & numbers (either a string name of a predefined mutator, or an RPMutator object)
*/
function ReadablePassphrase( template, mutator ) {
this.parts = [];
this.length = 0;
this.usedWords = {};
this.mutator = new RPMutator( mutator );
if( template ) this.addTemplate( template );
return this;
}
/**
* ReadablePassphrase.randomness() is used by all ReadablePassphrase objects as a source of randomness.
* It uses a weak source of randomness by default.
* If using ReadablePassphrase in a production environment, you should replace this function with a better one
* @param {number} [multiplier=1] - get a value between 0 and multiplier (including 0, but not including multiplier)
* @return {number} A random, floating-point number between 0 and 1 (or multiplier, if provided)
*/
ReadablePassphrase.randomness = function( multiplier ) { return Math.random() * ( multiplier || 1 ); }
/**
* Convenience function: get a random integer
* @param {number} [multiplier=2] Get a random number betweeen 0 and multiplier (including 0 but not including multiplier)
* @return {number} A random integer
*/
ReadablePassphrase.randomInt = function( multiplier ) { return Math.floor( ReadablePassphrase.randomness( multiplier || 2 ) ); }
/**
* Get a list of names of predefined templates
* @return {string[]} A list of predefined templates, in no particular order
*/
ReadablePassphrase.templates = function () {
var templates = [];
for( var templateName in RPSentenceTemplate.templates ) templates.push( templateName );
return templates;
}
/**
* Get a list of names of predefined mutators
* @return {string[]} A list of predefined mutators, in no particular order
*/
ReadablePassphrase.mutators = function () {
var mutators = [];
for( var mutatorName in RPMutator.mutators ) mutators.push( mutatorName );
return mutators;
}
/**
* Get the number of bits of entropy in a template + mutator
* @param {string} template - name of the given template (not a template object)
* @param {(string|object)} [mutator] - either a string name of a predefined mutator, or an RPMutator object
* @return {number} floating-point number of bits
*/
ReadablePassphrase.entropyOf = function ( template, mutator ) {
mutator = mutator ? new RPMutator( mutator ) : null;
return RPSentenceTemplate.entropyOf( template ) + ( mutator ? mutator.entropy() : 0 );
}
/**
* Get the string representation of the generated phrase
* @return {string} A phrase, eg "the milk will eat the angry decision"
*/
ReadablePassphrase.prototype.toString = function () {
var phrase = [];
for( var wordNum=0; wordNum < this.parts.length; wordNum++ ) phrase.push( this.parts[ wordNum ].value );
return this.mutator.mutate( phrase.join(' ') );
}
// ****** methods called by addTemplate() *******
/**
* Add a template to the end of the current phrase.
* Called automatically by the constructor if you pass a template to the constructor.
* @param {(string|object)} template - use the given template (either a string name of a predefined template, or an RPSentenceTemplate object)
*/
ReadablePassphrase.prototype.addTemplate = function ( template ) {
if( typeof(template) == 'string' ) template = RPSentenceTemplate.byName( template );
this.template = template;
for( var templateNumber = 0; templateNumber < template.length; templateNumber++ ) {
var thisTemplate = template[ templateNumber ];
var finalize = this.addClause( new RPRandomFactors( thisTemplate ) );
if( finalize ) break; // some verb templates cause premature completion
}
// Cleanup: 'a' before vowel => 'an'
for( var wordNum=0; wordNum < this.parts.length; wordNum++ ) {
var thisWord = this.parts[ wordNum ];
if( thisWord.hasTypes(['article','indefinite']) ) {
var nextWord = this.parts[ wordNum + 1 ];
if( !nextWord ) break;
if( nextWord.value.match(/^[aeiou]/) ) thisWord.value = thisWord.indefiniteBeforeVowel;
}
}
}
/**
* Get the last clause in the phrase, or null if the phrase is empty
* @return {object} an RPWord() object or null
*/
ReadablePassphrase.prototype.last = function () { return ( this.length > 0 ) ? this.parts[ this.length - 1 ] : null; }
/**
* Add a clause to the current passphrase
* @param {object} factors - an object representing a clause (see README for examples)
* @return {boolean} returns true if no more clauses should be added after this
*/
ReadablePassphrase.prototype.addClause = function ( factors ) {
switch( factors.type ) {
case 'noun': return this.addNoun( factors );
case 'verb': return this.addVerb( factors );
case 'conjunction': this.appendWord( RPWordList.conjunctions.getRandomWord( this.usedWords ) ); return false;
case 'directSpeech': this.appendWord( RPWordList.speechVerbs.getRandomWord( this.usedWords ) ); return false;
default: throw 'Unexpected clause type: ' + factors.type;
}
}
/**
* Add an RPWord() object to the end of the current passphrase
* @param {object} word - an RPWord object
* @return {object} returns the current ReadablePassphrase object
*/
ReadablePassphrase.prototype.appendWord = function( word ) { return this.insertWord( word, this.length ); }
/**
* Insert an RPWord() object at any position in the current passphrase
* @param {object} word - an RPWord object
* @param {number} position - a number representing the position in the current set of RPWords to add the new one
* @return {object} returns the current ReadablePassphrase object
*/
ReadablePassphrase.prototype.insertWord = function( word, position ) {
this.parts.splice( position, 0, word );
this.usedWords[ word.value ] = true;
this.length++;
// console.log('Adding ' + word.value + ' to sentence');
return this;
}
/**
* Add a Verb clause to the current passphrase
* @param {object} factors - an object representing a verb clause (see README for examples)
* @return {boolean} returns true if no more clauses should be added after this (triggered by some intransitive verbs)
*/
ReadablePassphrase.prototype.addVerb = function ( factors ) {
// calculating whether the verb should be plural...
var firstNoun = null, firstIndefinitePronoun = null, pluralVerb = null, insertInterrogative = 0;
for( var wordNumber=0; wordNumber < this.length; wordNumber++ ) {
var thisWord = this.parts[ wordNumber ];
if( !firstNoun && thisWord.hasTypes( 'noun' ) ) firstNoun = thisWord;
else if( thisWord.hasTypes('speechVerb') ) {
firstNoun = null;
insertInterrogative = wordNumber + 1;
}
else if( !firstIndefinitePronoun && thisWord.hasTypes('indefinitePronoun') ) firstIndefinitePronoun = thisWord;
}
if( firstNoun ) pluralVerb = firstNoun.hasTypes('plural') ? true : false;
else if( firstIndefinitePronoun ) pluralVerb = firstIndefinitePronoun.hasTypes('plural') ? true : false;
else pluralVerb = false;
// console.log('FirstNoun: ' + firstNoun + ', indefPronoun: ' + firstIndefinitePronoun + ' is plural: ' + pluralVerb);
var selectTransitive = true, removeAccusativeNoun = false, addPreposition = false;
var intransitiveType = factors.byName('intransitive');
if( intransitiveType && ( RPWordListVerb.getRandomTransitivity() == 'intransitive' ) ) {
// console.log('Adding intransitive, type = ' + intransitiveType);
selectTransitive = false;
switch( intransitiveType ) {
case 'noNounClause': removeAccusativeNoun = true; break;
case 'preposition': addPreposition = true; break;
default: throw 'Unexpected intransitive type: ' + intransitiveType;
}
}
var makeInterrogative = factors.byName('interrogative'), tense = factors.byName('subtype');
// console.log('Make interrogative: ' + makeInterrogative + ', tense: ' + tense);
if( makeInterrogative ) {
this.insertWord( RPWordList.interrogatives.getRandomWord( pluralVerb ), insertInterrogative, this.usedWords );
pluralVerb = true;
tense = 'presentPlural';
}
var includeAdverb = factors.byName('adverb') ? ( ( ReadablePassphrase.randomness( 2 ) >= 1 ) ? 'before' : 'after' ) : 'no';
if( includeAdverb == 'before' ) this.appendWord( RPWordList.adverbs.getRandomWord( this.usedWords ) );
this.appendWord( RPWordList[ selectTransitive ? 'verbs' : 'intransitiveVerbs' ].getRandomWord( tense, pluralVerb, this.usedWords ) );
if( includeAdverb == 'after' ) this.appendWord( RPWordList.adverbs.getRandomWord( this.usedWords ) );
if( addPreposition ) this.appendWord( RPWordList.prepositions.getRandomWord( this.usedWords ) );
if( removeAccusativeNoun ) return true; // Returning true means the sentence is done
return false;
}
/**
* Add a Noun clause to the current passphrase
* @param {object} factors - an object representing a noun clause (see README for examples)
* @return {boolean} returns true if no more clauses should be added after this (currently always false)
*/
ReadablePassphrase.prototype.addNoun = function ( factors ) {
var n = factors.byName('subtype');
switch( n ) {
case 'common': return this.addCommonNoun( factors ); break;
case 'nounFromAdjective': return this.addNounFromAdjective( factors ); break;
case 'proper': this.appendWord( RPWordList.properNouns.getRandomWord( this.usedWords ) ); return false;
default:
console.log( this );
throw 'Unknown noun subtype: ' + n;
}
}
/**
* Add a common Noun clause to the current passphrase (eg. "dog", "cat", "justice")
* @param {object} factors - an object representing a noun clause (see README for examples)
* @return {boolean} returns true if no more clauses should be added after this (currently always false)
*/
ReadablePassphrase.prototype.addCommonNoun = function ( factors ) {
var isPlural = this.addNounPrelude( factors );
if(factors.byName('number') && (isPlural || factors.mustBeTrue('singular') )) {
if( !isPlural && !(this.length && this.last().hasTypes(['article','indefinite'])) ) this.appendWord( RPWordList.numbers.getSingularNumberWord() );
else if( isPlural ) this.appendWord( RPWordList.numbers.getPluralNumberWord() );
}
if(factors.byName('adjective')) this.appendWord( RPWordList.adjectives.getRandomWord( this.usedWords ) );
this.appendWord( RPWordList.nouns.getRandomWord( isPlural, this.usedWords ) );
return false;
}
/**
* Construct a Noun clause from an adjective and add it to the current passphrase, eg. "a green thing"
* @param {object} factors - an object representing a noun clause (see README for examples)
* @return {boolean} returns true if no more clauses should be added after this (currently always false)
*/
ReadablePassphrase.prototype.addNounFromAdjective = function ( factors ) {
var isPlural = this.addNounPrelude( factors );
this.appendWord( RPWordList.adjectives.getRandomWord(this.usedWords) );
var isPersonal = ReadablePassphrase.randomness( 2 ) >= 1 ? true : false;
this.appendWord( RPWordList.indefinitePronouns.getRandomWord( isPersonal, isPlural, this.usedWords ) );
return false;
}
/**
* Add a prelude to a noun to the current passphrase, eg. "before the"
* @param {object} factors - an object representing a noun clause (see README for examples)
* @return {boolean} returns true if the following noun should be plural
*/
ReadablePassphrase.prototype.addNounPrelude = function ( factors ) {
if( factors.byName('preposition') &&
( !this.last() || !this.last().hasTypes('preposition') )
) {
this.appendWord( RPWordList.prepositions.getRandomWord( this.usedWords ) );
}
var isPlural = ! factors.byName('singular');
switch( factors.byName( isPlural ? 'articlePlural' : 'articleSingular' ) ) {
case 'none': break; // shouldn't come up for Singular
case 'definite': this.appendWord( RPWordList.articles.getRandomDefiniteArticle() ); break;
case 'indefinite': this.appendWord( RPWordList.articles.getRandomIndefiniteArticle() ); break; // shouldn't come up for Plural
case 'demonstrative': this.appendWord( RPWordList.demonstratives.getRandomWord( isPlural ) ); break;
case 'personalPronoun': this.appendWord( RPWordList.personalPronouns.getRandomWord( isPlural, this.usedWords ) ); break;
default: throw 'Unknown case result from computeFactor';
}
return isPlural;
}
/**
* This object mutates sentences by making some words (or parts of words) uppercase and adding numbers inside the sentence
* @param {(string|object)} mutatorSpec - either a string name of a predefined mutator, or an object describing the mutator
*/
function RPMutator ( mutatorSpec ) {
this.upper = { type: 'none' };
this.numbers = { type: 'none' };
if( !mutatorSpec ) return;
else if( typeof(mutatorSpec) == 'string' ) mutatorSpec = RPMutator.mutators[ mutatorSpec ];
function parseSpec ( spec ) { // helper function
if( spec.length ) spec = { type: spec[0], count: spec[1] };
if( spec.type != 'none' && ( !spec.count || isNaN(spec.count) || ( spec.count < 1 ) ) ) spec.count = 0;
return spec;
}
this.upper = parseSpec( mutatorSpec.upper );
this.numbers = parseSpec( mutatorSpec.numbers );
}
/**
* Predefined mutators
*/
RPMutator.mutators = {
'standard': { upper: [ 'WholeWord', 1 ], numbers: [ 'EndOfWord', 2 ] },
'random' : { upper: [ 'random' ], numbers: [ 'random' ] },
};
/**
* Mutate a string according to the mutator specification
* @param {string} string - a string to mutate, should be multiple words with spaces in between
* @return {string} a mutated string
*/
RPMutator.prototype.mutate = function ( string ) {
var words = string.split(' '); // we already have parts[], but a part might have multiple words in it
if( this.upper && this.upper.type != 'none' ) {
var count = this.upper.count || ( ReadablePassphrase.randomInt( words.length ) + 1 );
if( count > words.length ) count = words.length;
var availableWords = [], chosenUpper = [];
for(var i=0; i<words.length; i++ ) availableWords.push(i);
while( count-- > 0 ) chosenUpper.push( availableWords.splice(ReadablePassphrase.randomInt(availableWords.length),1) );
var upperTechniques = [ 'StartOfWord', 'WholeWord', 'Anywhere', 'RunOfLetters' ], upperType = this.upper.type;
chosenUpper.forEach(function ( wordNumber ) {
var thisWord = words[ wordNumber ], thisTechnique = upperType, start = 0, end = 0;
if( thisTechnique == 'random' ) thisTechnique = upperTechniques[ReadablePassphrase.randomInt(upperTechniques.length)];
switch( thisTechnique ) {
case 'StartOfWord': end = 1; break;
case 'WholeWord': end = thisWord.length; break;
case 'Anywhere': start = ReadablePassphrase.randomInt(thisWord.length); end = start + 1; break;
case 'RunOfLetters':
start = ReadablePassphrase.randomInt(thisWord.length - 1);
end = start + 2 + ReadablePassphrase.randomInt(thisWord.length - start);
break;
default: throw "Unknown word uppercasing technique: " + thisTechnique;
}
words[wordNumber] = "" + thisWord.slice(0,start) + thisWord.slice(start,end).toUpperCase() + thisWord.slice(end,thisWord.length);
});
}
if( this.numbers && this.numbers.type != 'none' ) {
var count = this.numbers.count || ( ReadablePassphrase.randomInt( 5 ) + 1 );
while( count-- > 0 ) {
var thisTechnique = this.numbers.type;
if( thisTechnique == 'StartOrEndOfWord' ) thisTechnique = ( ReadablePassphrase.randomness(2) >= 1 ) ? 'StartOfWord' : 'EndOfWord';
var chosenWord = ( thisTechnique == 'EndOfPhrase' ) ? ( words.length - 1 ) : ReadablePassphrase.randomInt(words.length);
var thisWord = words[ chosenWord ], thisNumber = ReadablePassphrase.randomInt(10).toString();
switch( thisTechnique ) {
case 'StartOfWord': thisWord = "" + thisNumber + thisWord; break;
case 'EndOfWord':
case 'EndOfPhrase': thisWord += thisNumber; break;
case 'random':
case 'Anywhere':
var thisPosition = ReadablePassphrase.randomInt(thisWord.length);
thisWord = thisWord.slice(0,thisPosition) + thisNumber + thisWord.slice(thisPosition,thisWord.length);
break;
default: throw "Unknown number insertion technique: " + thisTechnique;
}
words[ chosenWord ] = thisWord;
}
}
return words.join(' ');
}
/**
* Estimate the entropy added by a mutator
* (actual entropy would vary based on number & length of words in the string)
* @return {number} floating-point number of bits
*/
RPMutator.prototype.entropy = function () {
var averageNumberOfWords = 9, averageWordLength = 5, entropy = 0;
if( this.upper && this.upper.type != 'none' ) {
var count = this.upper.count || Math.floor(averageNumberOfWords / 2);
var thisEntropy = Math.log2(averageNumberOfWords); // choice of a random word
switch( this.upper.type ) {
case 'StartOfWord':
case 'WholeWord':
thisEntropy += 0; // these are predictable, so no bonus for position
break;
case 'Anywhere':
thisEntropy += Math.log2(averageWordLength);
break;
case 'RunOfLetters':
thisEntropy += Math.log2(averageWordLength) * 2;
break;
case 'random':
// 2 bits for choice of 4, then average entropy of choices
thisEntropy += 2 + ( Math.log2(averageWordLength) * 3 / 5 );
break;
default: throw "Unknown word uppercasing technique: " + this.upper.type;
}
entropy += thisEntropy * count;
}
if( this.numbers && this.numbers.type != 'none' ) {
var count = this.numbers.count || ( ReadablePassphrase.randomInt( 5 ) + 1 );
var thisEntropy = Math.log2(10); // random number
switch( this.numbers.type ) {
case 'StartOfWord':
case 'EndOfWord':
thisEntropy += Math.log2(averageNumberOfWords); // choice of word
break;
case 'EndOfPhrase':
thisEntropy += 0; // no bonus for fixed location
break;
case 'random':
case 'Anywhere':
thisEntropy += Math.log2(averageNumberOfWords) + Math.log2(averageWordLength);
break;
default: throw "Unknown number insertion technique: " + this.numbers.type;
}
entropy += thisEntropy * count;
}
return entropy;
}
/**
* This object represents a word in a sentence, plus some attributes that describe the type of word
* @param {(string|string[])} types - a string, or array of strings describing the type of the word, eg [ 'verb', 'intransitive' ]
* @param {string} value - the text representation of this word
*/
function RPWord( types, value ) {
this.value = value;
this.types = {};
this.addTypes( types );
return this;
}
/**
* Add one or more types to this word
* @param {(string|string[])} types - a string, or array of strings describing the type of the word, eg [ 'verb', 'intransitive' ]
* @return {object} returns this RPWord() object
*/
RPWord.prototype.addTypes = function ( types ) {
if( typeof(types) != 'object' ) types = [ types ];
var obj = this;
types.forEach(function( type ) { obj.types[ type ] = true; });
return this;
}
/**
* Returns true if the word has all the given types
* @param {(string|string[])} types - a string, or array of strings you want to check for, eg [ 'verb', 'transitive' ]
* @return {boolean} true if the word has all the requested types, false if any are missing
*/
RPWord.prototype.hasTypes = function ( types ) {
if( typeof(types) != 'object' ) types = [ types ];
for( var typeNum=0; typeNum < types.length; typeNum++ ) {
if( !this.types[ types[typeNum] ] ) return false;
}
return true;
}
/**
* This object represents a pool of words of a similar type, with the assumption that you will request random members from the pool
* @param {string} type - a string describing the type of all words in this list
* @param {string[]} wordArray - an array of words
*/
function RPWordList( type, wordArray ) {
this.list = wordArray;
this.type = type;
this.length = wordArray.length;
return this;
}
/**
* Get a random word from the pool.
* Note that passing alreadyChosen{} actually weakens the overall strength of the passphrase slightly
* @param {object} [alreadyChosen] - if a hash of words that are already chosen is provided, this will avoid returning one already chosen
* @return {object} an RPWord() object with the chosen word
*/
RPWordList.prototype.getRandomWord = function( alreadyChosen ) {
var word, attempts = 100;
do {
word = this.list[ ReadablePassphrase.randomInt( this.length ) ];
if( attempts-- < 1 ) throw 'Exceeded max attempts in RPWordListPlural.getRandomWord() for type ' + this.type;
} while( alreadyChosen && alreadyChosen[ word ] );
return new RPWord( this.type, word );
}
/**
* This object represents a pool of word pairs of a similar type, with the first element in each pair being the singular form and the second the plural
* @param {string} type - a string describing the type of all words in this list
* @param {object[]} wordArray - an array of a word pairs, eg [[ 'mouse', 'mice ], ['dog','dogs' ]]
*/
function RPWordListPlural( type, pluralWordArray ) {
RPWordList.call(this, type, pluralWordArray);
for( var wordNum=0; wordNum < this.list.length; wordNum++ ) {
var thisWord = this.list[ wordNum ];
if( typeof(thisWord) == 'string' ) this.list[ wordNum ] = [ thisWord, thisWord + 's' ];
}
return this;
}
/**
* Get a random word from the pool.
* Note that passing alreadyChosen{} actually weakens the overall strength of the passphrase slightly
* @param {boolean} [isPlural] - true if the plural form of the word is being requested
* @param {object} [alreadyChosen] - if a hash of words that are already chosen is provided, this will avoid returning one already chosen
* @return {object} an RPWord() object with the chosen word
*/
RPWordListPlural.prototype.getRandomWord = function( isPlural, alreadyChosen ) {
var word = null, attempts = 100;
do {
word = this.list[ ReadablePassphrase.randomInt( this.length ) ][ isPlural ? 1 : 0 ];
if( attempts-- < 1 ) throw 'Exceeded max attempts in RPWordListPlural.getRandomWord() for type ' + this.type;
} while( !word || ( alreadyChosen && alreadyChosen[ word ] ) );
return new RPWord( [ this.type, isPlural ? 'plural' : 'singular' ], word );
}
/**
* This object represents a pool of verbs, with each verb having multiple possible tenses
* @param {string} transitiveType - either 'transitive' or 'intransitive' depending on the type of verbs in the list
* @param {object[]} verbArray - an array of a verbs, each represented as a 14-element array of tenses (see RPWordListVerb.tenses for order)
*/
function RPWordListVerb( transitiveType, verbArray ) {
this.list = [];
if( typeof(RPWordListVerb.tenses[0]) == 'string') { // compile the tenses
for( var specNum=0; specNum < RPWordListVerb.tenses.length; specNum++ ) {
var thisSpec = RPWordListVerb.tenses[specNum];
var specObj = { fullTense: thisSpec, tense: null, continuous: false, plural: false };
var tenseMatch = thisSpec.match(/^(past|present|future|perfect|subjunctive)/);
if( tenseMatch ) specObj.tense = tenseMatch[0];
if( thisSpec.match(/Continuous/) ) specObj.continuous = true;
if( thisSpec.match(/Plural/) ) specObj.plural = true;
RPWordListVerb.tenses[specNum] = specObj;
}
// console.log( RPWordListVerb.tenses );
}
for( var verbNum=0; verbNum < verbArray.length; verbNum++ ) {
var thisVerb = verbArray[ verbNum ];
if( typeof(thisVerb) == 'string' ) thisVerb = [ thisVerb ];
var baseWord = thisVerb[0], baseWordTrim = thisVerb[0].replace(/e$/,'');
for( var specNum=0; specNum < RPWordListVerb.tenses.length; specNum++ ) {
var thisSpec = RPWordListVerb.tenses[ specNum ];
var thisWord = thisVerb[ specNum ] || RPWordListVerb.unpackDefaults[ specNum ];
thisWord = thisWord.replace('&1e',baseWordTrim + 'e').replace('&1i',baseWordTrim + 'i').replace('&1',baseWord);
var types = [ 'verb', thisSpec.fullTense, thisSpec.tense, ( thisSpec.plural ? 'plural' : 'singular' ), transitiveType ];
if( thisSpec.continuous ) types.push('continuous');
this.list.push( new RPWord( types, thisWord ) );
}
}
// console.log( this );
this.length = this.list.length;
return this;
}
/**
* Static array representing the tenses of each element in a verb passed to RPWordListVerb
*/
RPWordListVerb.tenses = ['presentPlural','presentSingular','futurePlural','futureSingular','pastContinuousPlural','pastContinuousSingular','pastPlural','pastSingular','perfectPlural','perfectSingular','presentContinuousPlural','presentContinuousSingular','subjunctivePlural','subjunctiveSingular'];
/**
* Static array representing the default unpacking technique for simple verbs; &1 is replaced by the first word
*/
RPWordListVerb.unpackDefaults = ['','&1s','will &1','will &1','were &1ing','was &1ing','&1ed','&1ed','have &1ed','has &1ed','are &1ing','is &1ing','might &1','might &1'];
/**
* Returns 'transitive' or 'intransitive', biased toward whichever pool is bigger. Eg, 5 transitive + 1 intransitive returns 'transitive' 5:1
* @return {string} 'transitive' or 'intransitive'
*/
RPWordListVerb.getRandomTransitivity = function () {
return RPRandomFactors.computeFactor([ RPWordList.verbs.length, RPWordList.intransitiveVerbs.length ]) ? 'transitive' : 'intransitive';
}
/**
* Get a random word from the pool.
* Note that passing alreadyChosen{} actually weakens the overall strength of the passphrase slightly
* @param {string} [tense] - name of the tense being requested, eg. 'pastContinuousPlural'
* @param {boolean} [isPlural] - true if the plural form of the word is being requested
* @param {object} [alreadyChosen] - if a hash of words that are already chosen is provided, this will avoid returning one already chosen
* @return {object} an RPWord() object with the chosen word
*/
RPWordListVerb.prototype.getRandomWord = function ( tense, isPlural, alreadyChosen ) {
var types = [];
if( typeof(isPlural) == 'boolean' ) types.push( isPlural ? 'plural' : 'singular' );
if( tense && tense == 'continuousPast' ) types.push('continuous','past');
else if ( tense ) types.push( tense );
var options = [];
for( var wordNum=0; wordNum < this.list.length; wordNum++ ) {
var thisWord = this.list[ wordNum ];
if( ( !alreadyChosen || !alreadyChosen[ thisWord.value ] ) && thisWord.hasTypes( types ) ) options.push( thisWord );
}
if( !options.length ) throw "No verbs match criteria!";
return options[ ReadablePassphrase.randomInt( options.length ) ];
}
/**
* This object represents a pool of random articles. Currently there is only 1 article in the list "a", "an" or "the"
* @param {object[]} articleArray - an array of article objects {definite: ..., indefinite: ..., indefiniteBeforeVowel: ...}
*/
function RPWordListArticle( articleArray ) {
this.list = articleArray;
this.length = articleArray.length;
}
/**
* Get a random definite article from the pool. Currently always returns 'the'
* @return {object} an RPWord() object with the chosen word
*/
RPWordListArticle.prototype.getRandomDefiniteArticle = function () { return this.getRandomWord( true ); }
/**
* Get a random indefinite article from the pool. Currently always returns 'a/an'
* @return {object} an RPWord() object with the chosen word
*/
RPWordListArticle.prototype.getRandomIndefiniteArticle = function () { return this.getRandomWord( false ); }
/**
* Get a random article from the pool
* @param {boolean} definite - if true, returns a definite article (eg. 'the'), otherwise an indefinite one.
* @return {object} an RPWord() object with the chosen word
*/
RPWordListArticle.prototype.getRandomWord = function( definite ) {
var word = this.list[ ReadablePassphrase.randomInt( this.list.length ) ];
var returnWord = new RPWord( [ 'article', definite ? 'definite' : 'indefinite' ], definite ? word.definite : word.indefinite, word );
if( !definite ) returnWord.indefiniteBeforeVowel = word.indefiniteBeforeVowel;
return returnWord;
}
/**
* This object represents a pool of random numbers.
* @param {number} start - an integer representing where the lowest number to return
* @param {number} end - an integer representing the highest number to return
*/
function RPWordListNumber( start, end ) {
this.start = start;
this.end = end;
this.length = 1 + end - start;
}
/**
* Get a random singular number (always returns '1')
* @return {object} an RPWord() object with the chosen word
*/
RPWordListNumber.prototype.getSingularNumberWord = function() {
return new RPWord( ['number', 'requiresSingularNoun' ], '1' );
}
/**
* Get a random plural number (between 2 and 'end', inclusive)
* @return {object} an RPWord() object with the chosen word
*/
RPWordListNumber.prototype.getPluralNumberWord = function() {
var start = this.start;
if( start < 2 ) start = 2;
var thisNumber = ReadablePassphrase.randomInt( this.end - this.start ) + this.start;
return new RPWord( ['number' ], thisNumber.toString() );
}
/**
* This object represents a pool of indefinite pronouns. There is currently 1 personal pronoun, and 1 impersonal
* @param {object[]} indefinitePronounArray - an array of indefinitePronoun objects {personal: [bool], singular: ..., plural: ...}
*/
function RPWordListIndefinitePronoun( indefinitePronounArray ) {
this.list = indefinitePronounArray;
this.length = indefinitePronounArray.length;
this.personal = [];
this.impersonal = [];
for( var pronounNum = 0; pronounNum < indefinitePronounArray.length; pronounNum++ ) {
var thisPronoun = indefinitePronounArray[ pronounNum ];
if( thisPronoun.personal ) this.personal.push( thisPronoun );
else this.impersonal.push( thisPronoun );
}
}
/**
* Get a random word from the pool.
* @param {string} [personal] - true if a personal pronoun is being requested
* @param {boolean} [plural] - true if the plural form of the word is being requested
* @return {object} an RPWord() object with the chosen word
*/
RPWordListIndefinitePronoun.prototype.getRandomWord = function( personal, plural ) {
var searchList = this.list;
if( personal ) searchList = this.personal;
else if( typeof(personal) != 'undefined' ) searchList = this.impersonal;
var word = searchList[ ReadablePassphrase.randomInt( searchList.length ) ];
var returnWord = new RPWord( [ 'indefinitePronoun', 'pronoun', 'indefinite', ( plural ? 'plural' : 'singular' ) ], word[ plural ? 'plural' : 'singular' ], word );
return returnWord;
}
/**
* This object represents a set of random factors
* A factor is a name, followed by a specification. If a spec is a boolean, string or number, then it will be returned as-is.
* If a spec is a 2-element array, then it will become a boolean with probability true A out of (A+B) times, eg [ 1, 4 ] is true 20% of the time.
* If a spec is an object, it will become a string with probability according to all values in the object, eg { a: 1, b: 2, c: 1, d: 0 } returns 'b' 50% of the time.
* @param {object} spec - an object describing the specification and weights of various factors
*/
function RPRandomFactors ( spec ) {
for( var prop in spec ) this[prop] = spec[prop];
}
/**
* Get the value of a factor according to the weights assigned to it.
* @param {string} factorName - name of the factor being requested
* @return {string|boolean} returns the string (out of a set of choices) or boolean (out of a 2-element array) randomly chosen for this factor
*/
RPRandomFactors.prototype.byName = function ( factorName ) {
return RPRandomFactors.computeFactor( this[factorName] )
}
/**
* Returns true if the given factor must always be true
* @param {string} factorName - name of the factor
* @return {boolean} true if the factor must always be true, false if there is any chance it might be false
*/
RPRandomFactors.prototype.mustBeTrue = function ( factorName ) { return this.chanceOf(factorName,true) == 1 ? true : false; }
/* Function unused ----
RPRandomFactors.prototype.mustBeFalse = function ( factorName ) { return this.chanceOf(factorName,false) == 1 ? true : false; }
*/
/**
* Returns the odds that a given factor will have the given value
* @param {string} factorName - name of the factor
* @param {*} value - possible value of the factor, or boolean to find out if the factor could be true/false at all
* @return {number} floating-point probability between 0 and 1, eg 0.25
*/
RPRandomFactors.prototype.chanceOf = function ( factorName, value ) {
switch( typeof(this[factorName]) ) {
case 'boolean':
value = value ? true : false;
return ( this[factorName] == value ) ? 1 : 0;
case 'string':
case 'number':
if( typeof(value) == 'boolean' ) {
if( value ) return this[factorName] ? 1 : 0;
else return this[factorName] ? 0 : 1;
}
return ( this[factorName] == value ) ? 1 : 0;
case 'object':
if( this[factorName].length === undefined ) {
var total = 0, thisWeight = this[factorName][value];
for( var weightFactor in this[factorName] ) {
total += this[factorName][weightFactor];
}
if( !total ) return 0;
if( typeof(value) == 'boolean' ) {
if( value ) return total ? 1 : 0;
else return total ? 0 : 1;
}
return thisWeight / total;
} else if( this[factorName].length == 2 ) {
var total = this[factorName][0] + this[factorName][1];
return value ? this[factorName][0] / total : this[factorName][1] / total;
}
default: throw "Cannot compute chance of unknown object type: " + typeof(this[factorName]) + ' factor: ' + factorName;
}
}
/**
* Returns the number of bits of entropy in a factor. Eg a straight [ 1, 1 ] is a 50% chance = 1 bit
* @param {string} factorName - name of the factor
* @return {number} floating-point number of bits
*/
RPRandomFactors.prototype.entropyOf = function ( factorName ) { // return number of bits of entropy in a factor
switch( typeof(this[factorName]) ) {
case 'boolean':
case 'string':
case 'number':
return 0;
case 'object':
if( this[factorName].length === undefined ) {
var total = 0, totalEntropy = 0;
for( var weightFactor in this[factorName] ) total += this[factorName][weightFactor];
for( var weightFactor in this[factorName] ) {
var thisChance = this[factorName][weightFactor] / total;
if( thisChance ) totalEntropy += Math.abs( thisChance * Math.log2( thisChance ) );
}
return totalEntropy;
} else if( this[factorName].length == 2 ) {
var a = this[factorName][0], b = this[factorName][1], total = this[factorName][0] + this[factorName][1];
return ( ( a / total ) * Math.log2( a / total ) + ( b / total ) * Math.log2( b / total ) );
}
default: throw "Cannot compute chance of unknown object type: " + typeof(this[factorName]) + ' factor: ' + factorName;
}
}
/* Function unused ----
RPRandomFactors.prototype.all = function() {
var computed = {};
for( var factor in this ) computed[factor] = RPRandomFactors.computeFactor( this[factor] );
return computed;
}
*/
/**
* Static function that computes a random value for a specification, see RPRandomFactors() for possible specs
* @param {*} factor - specification
* @return {*} value of the factor, randomly-chosen if possible
*/
RPRandomFactors.computeFactor = function ( factor ) {
switch( typeof( factor ) ) {
case 'boolean':
case 'string':
case 'number':
return factor;
case 'object':
if( factor.length === undefined ) {
var weights = [], totalWeight = 0;
for( var weightFactor in factor ) {
totalWeight += factor[ weightFactor ];
weights.push({ value: weightFactor, weight: totalWeight });
}
if( totalWeight == 0 ) return false;
var chosenWeight = ReadablePassphrase.randomness( totalWeight );
for( var checkWeight=0; checkWeight < weights.length; checkWeight++ ) {
if( chosenWeight < weights[ checkWeight ].weight ) {
return weights[ checkWeight ].value;
break;
}
}
return false;
} else if( factor.length == 2 ) {
var chosenWeight = ReadablePassphrase.randomness( factor[0] + factor[1] );
return ( chosenWeight > factor[0] ) ? false : true;
} else throw "Unknown object type in computation";
break;
default:
break;
}
return null;
}
/**
* This object represents a pattern for constructing a sentence. See the README for constructing new sentence templates.
* @param {object[]} template - an array of clause objects
*/
function RPSentenceTemplate ( template ) {
this.length = template.length;
for( var i=0; i < template.length; i++ ) {
var el = template[ i ];
if( typeof(el) == 'string' ) this[ i ] = { type: el };
else if( typeof(el) == 'object' && el.length ) { // reassemble packed templates
switch( el[0] ) {
case 'noun':
this[ i ] = {
type: 'noun', subtype: { common: el[1], proper: el[2], nounFromAdjective: el[3] },
article: { none: el[4], definite: el[5], indefinite: el[6], demonstrative: el[7], personalPronoun: el[8] },
adjective: el[9], preposition: el[10], number: el[11], singular: el[12]
}; break;
case 'verb':
this[ i ] = {
type: 'verb', subtype: { present: el[1], past: el[2], future: el[3], continuous: el[4], continuousPast: el[5], perfect: el[6], subjunctive: el[7] },
adverb: el[8], interrogative: el[9],
intransitive: { noNounClause: el[10], preposition: el[11] }
}; break;
default: throw "Error unpacking template spec array, unknown type: " + thisElement[0];
}
}
else this[ i ] = el;
if( this[i].type == 'noun' && this[i].article && !this[i].articleSingular ) { // unpack article weights into Singular and Plural for convenience later
var s = {}, p = {};
for( var articleType in this[i].article ) p[articleType] = s[articleType] = this[i].article[articleType];
delete s['none']; delete p['indefinite']; delete this[i]['article']; // singular nouns must have an article, plural can't have indefinite
this[i].articleSingular = s; this[i].articlePlural = p;
}
}
return this;
}
/**
* Returns the number of bits of entropy in the template
* @return {number} floating-point number of bits
*/
RPSentenceTemplate.prototype.entropy = function () {
var totalEntropy = 0, currentMultiplier = 1;
function len2log( listName ) { return Math.log2( RPWordList[listName].length ); } // helper function
for( var templateNum=0; templateNum < this.length; templateNum++ ) switch( this[templateNum].type ) {
case 'conjunction': totalEntropy += len2log('conjunctions') * currentMultiplier; break;
case 'directSpeech': totalEntropy += len2log('speechVerbs') * currentMultiplier; break;
case 'noun':
var factors = new RPRandomFactors(this[templateNum]), thisEntropy = 0;
thisEntropy += factors.entropyOf('subtype');
thisEntropy += factors.chanceOf('subtype','proper') * len2log('properNouns');
var preludeEntropy = (
factors.entropyOf('preposition') + factors.entropyOf('singular') +
( factors.chanceOf('preposition',true) * len2log('prepositions') ) +
( factors.chanceOf('singular',true) * (
factors.entropyOf('articleSingular') +
( factors.chanceOf('articleSingular','definite') * len2log('articles') ) +
( factors.chanceOf('articleSingular','indefinite') * len2log('articles') ) +
( factors.chanceOf('articleSingular','demonstrative') * len2log('demonstratives') ) +
( factors.chanceOf('articleSingular','personalPronoun') * len2log('personalPronouns') )
)
) +
( factors.chanceOf('singular',false) * (
factors.entropyOf('articlePlural') +
( factors.chanceOf('articlePlural','definite') * len2log('articles') ) +
( factors.chanceOf('articlePlural','demonstrative') * len2log('demonstratives') ) +
( factors.chanceOf('articlePlural','personalPronoun') * len2log('articles') )
)
)
);
thisEntropy += factors.chanceOf('subtype','common') * (
len2log('nouns') + factors.entropyOf('adjective') + preludeEntropy +
( factors.chanceOf('adjective',true) * len2log('adjectives') ) +
( factors.chanceOf('singular',false) * factors.chanceOf('number',true) * len2log('numbers') )
);
thisEntropy += factors.chanceOf('subtype','nounFromAdjective') * ( len2log('indefinitePronouns') + preludeEntropy + len2log('adjectives') );
totalEntropy += thisEntropy * currentMultiplier;
break;
case 'verb':
var factors = new RPRandomFactors(this[templateNum]), intLen = RPWordList.intransitiveVerbs.length, tranLen = RPWordList.verbs.length;
var totalLen = intLen + tranLen;
var chanceOfIntransitive = intLen / totalLen;
var thisEntropy = (
factors.entropyOf('interrogative') + factors.entropyOf('adverb') + factors.entropyOf('adverb') +
( chanceOfIntransitive * Math.log2( chanceOfIntransitive ) + ( tranLen / totalLen ) * Math.log2( tranLen / totalLen ) ) +
( factors.chanceOf('interrogative',true) * len2log('interrogatives') ) +
( factors.chanceOf('adverb',true) * ( len2log('adverbs') + 1 ) ) +
( chanceOfIntransitive * factors.chanceOf('intransitive','preposition') * len2log('prepositions') )
);
totalEntropy += thisEntropy * currentMultiplier;
currentMultiplier *= 1 - ( chanceOfIntransitive * factors.chanceOf('intransitive','noNounClause') );
break;
default: throw "Unknown clause type in entropy";
}
return totalEntropy;
}
/**
* Static function to return the number of bits of entropy in the given template
* @param {string} templateName - name of the template
* @return {number} floating-point number of bits
*/
RPSentenceTemplate.entropyOf = function ( templateName ) {
var template = RPSentenceTemplate.templates[ templateName ];
if( typeof(template[0]) == 'string' ) { // it's a collection of templates, not a template itself
var entropy = 0;
template.forEach(function ( templateName ) { entropy += RPSentenceTemplate.entropyOf( templateName ); });
return ( entropy / template.length ) + Math.log2( template.length ); // gain some entropy for choosing a random template
}
return template.entropy();
}
/**
* Static function to return a template of the given name
* (if the template is a collection of other templates, returns a random template from the collection)
* @param {string} templateName - name of the template
* @return {object} RPSentenceTemplate() object
*/
RPSentenceTemplate.byName = function ( templateName ) {
var template = RPSentenceTemplate.templates[ templateName ];
if( typeof(template[0]) == 'string' ) { // it's a collection of templates, not a template itself
templateName = template[ ReadablePassphrase.randomInt( template.length ) ];
template = RPSentenceTemplate.templates[ templateName ];
}
template.name = templateName;
return template;
}
/*
* ******************* DATA *******************
* RPSentence.templates = A set of sentence templates, used to construct predefined sentences
* RPWordList.{wordtype} = A static global object that wraps a list of parts of some kind
*/
RPSentenceTemplate.templates = {
// Shorthand to select a random template out of a set of similar ones
'random': [ 'normal', 'normalAnd', 'normalSpeech', 'strong', 'strongAnd', 'strongSpeech', 'insane', 'insaneAnd', 'insaneSpeech' ],
'randomShort': [ 'normal', 'normalEqual', 'normalRequired', 'strong', 'insane', 'strongEqual' ],
'randomLong': [ 'normalAnd', 'normalSpeech', 'normalEqualSpeech', 'normalRequiredAnd', 'normalRequiredSpeech', 'insaneEqual', 'normalEqualAnd', 'strongRequired', 'strongSpeech', 'strongAnd' ],
'randomForever': [ 'strongEqualSpeech', 'insaneAnd', 'insaneSpeech', 'strongEqualAnd', 'insaneRequired', 'strongRequired', 'strongRequiredSpeech', 'insaneEqualSpeech', 'insaneEqualAnd', 'strongRequiredAnd', 'insaneRequiredSpeech', 'insaneRequiredAnd' ],
// actual templates
normal: new RPSentenceTemplate([['noun',12,1,2,5,4,4,0,2,false,false,[1,5],true],['verb',10,8,8,0,0,0,0,false,[1,8],0,0],['noun',1,0,0,5,4,4,0,2,false,false,false,true]]),
normalAnd: new RPSentenceTemplate([['noun',12,1,2,5,4,4,0,2,false,false,[1,5],true],['verb',10,8,8,0,0,0,0,false,[1,8],0,0],['noun',1,0,0,5,4,4,0,2,false,false,false,true],'conjunction',['noun',1,0,0,5,4,4,0,2,false,false,false,true]]),
normalSpeech: new RPSentenceTemplate([['noun',7,1,0,0,4,4,0,2,false,false,false,true],'directSpeech',['noun',12,1,2,5,4,4,0,2,false,false,[1,5],true],['verb',10,8,8,0,0,0,0,false,[1,8],0,0],['noun',1,0,0,5,4,4,0,2,false,false,false,true]]),
normalEqual: new RPSentenceTemplate([['noun',1,1,1,1,1,1,0,1,false,false,[1,1],true],['verb',1,1,1,0,0,0,0,false,[1,1],0,0],['noun',1,0,0,1,1,1,0,1,false,false,false,true]]),
normalEqualAnd: new RPSentenceTemplate([['noun',1,1,1,1,1,1,0,1,false,false,[1,1],true],['verb',1,1,1,0,0,0,0,false,[1,1],0,0],['noun',1,0,0,1,1,1,0,1,false,false,false,true],'conjunction',['noun',1,0,0,1,1,1,0,1,false,false,false,true]]),
normalEqualSpeech: new RPSentenceTemplate([['noun',1,1,0,0,1,1,0,1,false,false,false,true],'directSpeech',['noun',1,1,1,1,1,1,0,1,false,false,[1,1],true],['verb',1,1,1,0,0,0,0,false,[1,1],0,0],['noun',1,0,0,1,1,1,0,1,false,false,false,true]]),
normalRequired: new RPSentenceTemplate([['noun',1,1,1,0,1,1,0,1,false,false,true,true],['verb',1,1,1,0,0,0,0,false,[1,1],0,0],['noun',1,0,0,0,1,1,0,1,false,false,false,true]]),
normalRequiredAnd: new RPSentenceTemplate([['noun',1,1,1,0,1,1,0,1,false,false,true,true],['verb',1,1,1,0,0,0,0,false,[1,1],0,0],['noun',1,0,0,0,1,1,0,1,false,false,false,true],'conjunction',['noun',1,0,0,0,1,1,0,1,false,false,false,true]]),
normalRequiredSpeech: new RPSentenceTemplate([['noun',1,1,0,0,1,1,0,1,false,false,false,true],'directSpeech',['noun',1,1,1,0,1,1,0,1,false,false,true,true],['verb',1,1,1,0,0,0,0,false,[1,1],0,0],['noun',1,0,0,0,1,1,0,1,false,false,false,true]]),
strong: new RPSentenceTemplate([['noun',12,1,2,5,4,4,1,2,false,false,[1,4],[7,3]],['verb',10,10,10,5,5,5,2,false,[1,8],0,4],['noun',1,0,0,5,4,4,1,2,[3,6],[1,15],false,true]]),
strongAnd: new RPSentenceTemplate([['noun',12,1,2,5,4,4,1,2,false,false,[1,4],[7,3]],['verb',10,10,10,5,5,5,2,false,[1,8],0,4],['noun',1,0,0,5,4,4,1,2,[3,6],[1,15],false,true],'conjunction',['noun',1,0,0,5,4,4,1,2,[3,6],false,false,true]]),
strongSpeech: new RPSentenceTemplate([['noun',7,1,0,0,4,4,1,2,false,false,false,[7,3]],'directSpeech',['noun',12,1,2,5,4,4,1,2,false,false,[1,4],[7,3]],['verb',10,10,10,5,5,5,2,false,[1,8],0,4],['noun',1,0,0,5,4,4,1,2,[3,6],[1,15],false,true]]),
strongEqual: new RPSentenceTemplate([['noun',1,1,1,1,1,1,1,1,false,false,[1,1],[1,1]],['verb',1,1,1,1,1,1,1,false,[1,1],0,1],['noun',1,0,0,1,1,1,1,1,[1,1],[1,1],false,true]]),
strongEqualAnd: new RPSentenceTemplate([['noun',1,1,1,1,1,1,1,1,false,false,[1,1],[1,1]],['verb',1,1,1,1,1,1,1,false,[1,1],0,1],['noun',1,0,0,1,1,1,1,1,[1,1],[1,1],false,true],'conjunction',['noun',1,0,0,1,1,1,1,1,[1,1],false,false,true]]),
strongEqualSpeech: new RPSentenceTemplate([['noun',1,1,0,0,1,1,1,1,false,false,false,[1,1]],'directSpeech',['noun',1,1,1,1,1,1,1,1,false,false,[1,1],[1,1]],['verb',1,1,1,1,1,1,1,false,[1,1],0,1],['noun',1,0,0,1,1,1,1,1,[1,1],[1,1],false,true]]),
strongRequired: new RPSentenceTemplate([['noun',1,1,1,0,1,1,1,1,false,false,true,[1,1]],['verb',1,1,1,1,1,1,1,false,[1,1],0,1],['noun',1,0,0,0,1,1,1,1,true,true,false,true]]),
strongRequiredAnd: new RPSentenceTemplate([['noun',1,1,1,0,1,1,1,1,false,false,true,[1,1]],['verb',1,1,1,1,1,1,1,false,[1,1],0,1],['noun',1,0,,0,1,1,1,1,true,true,false,true],'conjunction',['noun',1,0,0,0,1,1,1,1,true,false,false,true]]),
strongRequiredSpeech: new RPSentenceTemplate([['noun',1,1,0,0,1,1,1,1,false,false,false,[1,1]],'directSpeech',['noun',1,1,1,0,1,1,1,1,false,false,true,[1,1]],['verb',1,1,1,1,1,1,1,false,[1,1],0,1],['noun',1,0,0,0,1,1,1,1,true,true,false,true]]),
insane: new RPSentenceTemplate([['noun',8,0,1,5,4,4,1,2,[3,6],false,[1,3],[7,3]],['verb',10,10,10,5,5,5,5,[3,10],[1,8],1,5],['noun',1,0,0,5,4,4,1,2,[3,6],[2,8],false,[7,3]]]),
insaneAnd: new RPSentenceTemplate([['noun',8,0,1,5,4,4,1,2,[3,6],false,[1,3],[7,3]],['verb',10,10,10,5,5,5,5,[3,10],[1,8],1,5],['noun',1,0,0,5,4,4,1,2,[3,6],[2,8],false,[7,3]],'conjunction',['noun',1,0,0,5,4,4,1,2,[3,6],false,false,[7,3]]]),
insaneSpeech: new RPSentenceTemplate([['noun',7,1,0,0,4,4,1,2,[3,6],false,false,[7,3]],'directSpeech',['noun',8,0,1,5,4,4,1,2,[3,6],false,[1,3],[7,3]],['verb',10,10,10,5,5,5,5,[3,10],[1,8],1,5],['noun',1,0,0,5,4,4,1,2,[3,6],[2,8],false,[7,3]]]),
insaneEqual: new RPSentenceTemplate([['noun',1,0,1,1,1,1,1,1,[1,1],false,true,[1,1]],['verb',1,1,1,1,1,1,1,[1,1],[1,1],1,1],['noun',1,0,0,1,1,1,1,1,[1,1],[1,1],false,[1,1]]]),