natural 6.10.2 → 6.10.4

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.
Files changed (44) hide show
  1. package/.gitconfig +3 -0
  2. package/.github/workflows/node.js.yml +1 -1
  3. package/.github/workflows/npm-publish.yml +4 -4
  4. package/lib/natural/brill_pos_tagger/index.d.ts +32 -26
  5. package/lib/natural/brill_pos_tagger/lib/Brill_POS_Tagger.js +33 -31
  6. package/lib/natural/brill_pos_tagger/lib/Brill_POS_Tester.js +33 -35
  7. package/lib/natural/brill_pos_tagger/lib/Brill_POS_Trainer.js +326 -324
  8. package/lib/natural/brill_pos_tagger/lib/Corpus.js +140 -138
  9. package/lib/natural/brill_pos_tagger/lib/Lexicon.js +78 -76
  10. package/lib/natural/brill_pos_tagger/lib/Predicate.js +19 -17
  11. package/lib/natural/brill_pos_tagger/lib/RuleSet.js +58 -56
  12. package/lib/natural/brill_pos_tagger/lib/RuleTemplate.js +11 -9
  13. package/lib/natural/brill_pos_tagger/lib/Sentence.js +21 -20
  14. package/lib/natural/brill_pos_tagger/lib/TransformationRule.js +58 -58
  15. package/lib/natural/classifiers/bayes_classifier.js +24 -29
  16. package/lib/natural/classifiers/classifier.js +136 -121
  17. package/lib/natural/classifiers/logistic_regression_classifier.js +33 -37
  18. package/lib/natural/classifiers/maxent/Classifier.js +81 -79
  19. package/lib/natural/classifiers/maxent/Context.js +11 -9
  20. package/lib/natural/classifiers/maxent/Distribution.js +107 -105
  21. package/lib/natural/classifiers/maxent/Element.js +12 -10
  22. package/lib/natural/classifiers/maxent/Feature.js +56 -54
  23. package/lib/natural/classifiers/maxent/FeatureSet.js +40 -38
  24. package/lib/natural/classifiers/maxent/GISScaler.js +110 -109
  25. package/lib/natural/classifiers/maxent/POS/ME_Corpus.js +26 -31
  26. package/lib/natural/classifiers/maxent/POS/ME_Sentence.js +37 -42
  27. package/lib/natural/classifiers/maxent/POS/POS_Element.js +119 -124
  28. package/lib/natural/classifiers/maxent/Sample.js +96 -94
  29. package/lib/natural/classifiers/maxent/SimpleExample/SE_Element.js +14 -20
  30. package/lib/natural/inflectors/fr/count_inflector.js +1 -1
  31. package/lib/natural/inflectors/fr/noun_inflector.js +179 -196
  32. package/lib/natural/inflectors/ja/noun_inflector.js +67 -84
  33. package/lib/natural/inflectors/noun_inflector.js +124 -139
  34. package/lib/natural/inflectors/present_verb_inflector.js +34 -48
  35. package/lib/natural/inflectors/singular_plural_inflector.js +62 -61
  36. package/lib/natural/tfidf/tfidf.js +118 -114
  37. package/lib/natural/trie/trie.js +161 -159
  38. package/lib/natural/util/directed_edge.js +49 -0
  39. package/lib/natural/util/edge_weighted_digraph.js +54 -74
  40. package/lib/natural/util/index.js +1 -0
  41. package/lib/natural/util/longest_path_tree.js +54 -52
  42. package/lib/natural/util/shortest_path_tree.js +56 -54
  43. package/lib/natural/util/topological.js +17 -15
  44. package/package.json +1 -1
@@ -23,148 +23,133 @@ THE SOFTWARE.
23
23
  'use strict'
24
24
 
25
25
  const SingularPluralInflector = require('./singular_plural_inflector')
26
- const util = require('util')
27
26
  const FormSet = require('./form_set')
28
27
 
29
- // Changing the prototype of a native type is bad practice
30
- /*
31
- function attach () {
32
- const inflector = this
33
-
34
- String.prototype.singularizeNoun = function () {
35
- return inflector.singularize(this)
36
- }
37
-
38
- String.prototype.pluralizeNoun = function () {
39
- return inflector.pluralize(this)
28
+ class NounInflector extends SingularPluralInflector {
29
+ constructor () {
30
+ super()
31
+ this.ambiguous = [
32
+ 'bison', 'bream', 'carp', 'chassis', 'christmas', 'cod', 'corps', 'debris', 'deer',
33
+ 'diabetes', 'equipment', 'elk', 'fish', 'flounder', 'gallows', 'graffiti',
34
+ 'headquarters', 'herpes', 'highjinks', 'homework', 'information',
35
+ 'mackerel', 'mews', 'money', 'news', 'rice', 'rabies', 'salmon', 'series',
36
+ 'sheep', 'shrimp', 'species', 'swine', 'tennis', 'trout', 'tuna', 'whiting', 'wildebeest'
37
+ ]
38
+
39
+ this.customPluralForms = []
40
+ this.customSingularForms = []
41
+ this.singularForms = new FormSet()
42
+ this.pluralForms = new FormSet()
43
+
44
+ // this.attach = attach
45
+
46
+ this.addIrregular('child', 'children')
47
+ this.addIrregular('man', 'men')
48
+ this.addIrregular('person', 'people')
49
+ this.addIrregular('sex', 'sexes')
50
+ this.addIrregular('mouse', 'mice')
51
+ this.addIrregular('ox', 'oxen')
52
+ this.addIrregular('foot', 'feet')
53
+ this.addIrregular('tooth', 'teeth')
54
+ this.addIrregular('goose', 'geese')
55
+ this.addIrregular('ephemeris', 'ephemerides')
56
+ this.addIrregular('cloth', 'clothes')
57
+ this.addIrregular('hero', 'heroes')
58
+ this.addIrregular('torso', 'torsi')
59
+
60
+ // see if it is possible to unify the creation of both the singular and
61
+ // plural regexes or maybe even just have one list. with a complete list
62
+ // of rules it may only be possible for some regular forms, but worth a shot
63
+ this.pluralForms.regularForms.push([/([aeiou]y)$/i, '$1s'])
64
+ this.pluralForms.regularForms.push([/y$/i, 'ies'])
65
+ this.pluralForms.regularForms.push([/ife$/i, 'ives'])
66
+ this.pluralForms.regularForms.push([/(antenn|formul|nebul|vertebr|vit)a$/i, '$1ae'])
67
+ this.pluralForms.regularForms.push([/(octop|vir|radi|nucle|fung|cact|stimul|alumn|calcul|hippopotam|macrofung|phoet|syllab|troph)us$/i, '$1i'])
68
+ this.pluralForms.regularForms.push([/(buffal|tomat|tornad)o$/i, '$1oes'])
69
+ this.pluralForms.regularForms.push([/(sis)$/i, 'ses'])
70
+ this.pluralForms.regularForms.push([/(matr|vert|ind|cort)(ix|ex)$/i, '$1ices'])
71
+ this.pluralForms.regularForms.push([/sses$/i, 'sses'])
72
+ this.pluralForms.regularForms.push([/(x|ch|ss|sh|s|z)$/i, '$1es'])
73
+ this.pluralForms.regularForms.push([/^(?!talis|.*hu)(.*)man$/i, '$1men'])
74
+ this.pluralForms.regularForms.push([/(.*)/i, '$1s'])
75
+
76
+ // Words ending in -ff or -ffe you just add s to make the plural.
77
+ // Sheriffs | Giraffes
78
+ // this.pluralForms.regularForms.push([/(.+ffe?)$/i, '$1s'])
79
+
80
+ // words ending in f that just add s:
81
+ // roof - roofs
82
+ // chief - chiefs
83
+ // oaf -oafs
84
+ // this.pluralForms.regularForms.push([/([^f]+f)$/i, '$1s'])
85
+
86
+ // Example of words using the -f / -fe to -ves rule
87
+ // leaf - leaves
88
+ // wolf - wolves
89
+ // calf - calves
90
+ // half - halves
91
+ // knife - knives
92
+ // loaf - loaves
93
+ // life - lives
94
+ // wife - wives
95
+ // shelf - shelves
96
+ // thief - thieves
97
+ // yourself - yourselves
98
+ this.addIrregular('leaf', 'leaves')
99
+ this.addIrregular('wolf', 'wolves')
100
+ this.addIrregular('calf', 'calves')
101
+ this.addIrregular('half', 'halves')
102
+ this.addIrregular('knife', 'knives')
103
+ this.addIrregular('loaf', 'loaves')
104
+ this.addIrregular('life', 'lives')
105
+ this.addIrregular('wife', 'wives')
106
+ this.addIrregular('shelf', 'shelves')
107
+ this.addIrregular('thief', 'thieves')
108
+ this.addIrregular('yourself', 'yourselves')
109
+
110
+ // Some words have multiple valid plural forms endings with -ves or -s:
111
+ // scarf - scarfs/scarves
112
+ // dwarf - dwarfs / dwarves
113
+ // wharf - wharfs / wharves
114
+ // handkerchief - handkerchiefs / handkerchieves
115
+ // this.pluralForms.regularForms.push([/(.*r)f/i, '$1ves'])
116
+
117
+ // Singular inflections
118
+
119
+ // Some words have multiple valid plural forms endings with -ves or -s:
120
+ // scarf - scarfs/scarves
121
+ // dwarf - dwarfs / dwarves
122
+ // wharf - wharfs / wharves
123
+ // handkerchief - handkerchiefs / handkerchieves
124
+ this.singularForms.regularForms.push([/(.*)ves$/i, '$1f'])
125
+
126
+ // expenses - expense
127
+ // defenses - defense
128
+ this.singularForms.regularForms.push([/(.*)nses$/i, '$1nse'])
129
+
130
+ this.singularForms.regularForms.push([/([^v])ies$/i, '$1y'])
131
+ this.singularForms.regularForms.push([/ives$/i, 'ife'])
132
+ this.singularForms.regularForms.push([/(antenn|formul|nebul|vertebr|vit)ae$/i, '$1a'])
133
+ this.singularForms.regularForms.push([/(octop|vir|radi|nucle|fung|cact|stimul|alumn|calcul|hippopotam|macrofung|phoet|syllab|troph)(i)$/i, '$1us'])
134
+ this.singularForms.regularForms.push([/(buffal|tomat|tornad)(oes)$/i, '$1o'])
135
+ this.singularForms.regularForms.push([/(analy|naly|synop|parenthe|diagno|the)ses$/i, '$1sis'])
136
+ this.singularForms.regularForms.push([/(vert|ind|cort)(ices)$/i, '$1ex'])
137
+ // our pluralizer won''t cause this form of appendix (appendicies)
138
+ // but we should handle it
139
+ this.singularForms.regularForms.push([/(matr|append)(ices)$/i, '$1ix'])
140
+ this.singularForms.regularForms.push([/(x|ch|ss|sh|s|z)es$/i, '$1'])
141
+ this.singularForms.regularForms.push([/men$/i, 'man'])
142
+ this.singularForms.regularForms.push([/ss$/i, 'ss'])
143
+ this.singularForms.regularForms.push([/s$/i, ''])
144
+
145
+ this.pluralize = function (token) {
146
+ return this.ize(token, this.pluralForms, this.customPluralForms)
147
+ }
148
+
149
+ this.singularize = function (token) {
150
+ return this.ize(token, this.singularForms, this.customSingularForms)
151
+ }
40
152
  }
41
153
  }
42
- */
43
-
44
- const NounInflector = function () {
45
- this.ambiguous = [
46
- 'bison', 'bream', 'carp', 'chassis', 'christmas', 'cod', 'corps', 'debris', 'deer',
47
- 'diabetes', 'equipment', 'elk', 'fish', 'flounder', 'gallows', 'graffiti',
48
- 'headquarters', 'herpes', 'highjinks', 'homework', 'information',
49
- 'mackerel', 'mews', 'money', 'news', 'rice', 'rabies', 'salmon', 'series',
50
- 'sheep', 'shrimp', 'species', 'swine', 'tennis', 'trout', 'tuna', 'whiting', 'wildebeest'
51
- ]
52
-
53
- this.customPluralForms = []
54
- this.customSingularForms = []
55
- this.singularForms = new FormSet()
56
- this.pluralForms = new FormSet()
57
-
58
- // this.attach = attach
59
-
60
- this.addIrregular('child', 'children')
61
- this.addIrregular('man', 'men')
62
- this.addIrregular('person', 'people')
63
- this.addIrregular('sex', 'sexes')
64
- this.addIrregular('mouse', 'mice')
65
- this.addIrregular('ox', 'oxen')
66
- this.addIrregular('foot', 'feet')
67
- this.addIrregular('tooth', 'teeth')
68
- this.addIrregular('goose', 'geese')
69
- this.addIrregular('ephemeris', 'ephemerides')
70
- this.addIrregular('cloth', 'clothes')
71
- this.addIrregular('hero', 'heroes')
72
- this.addIrregular('torso', 'torsi')
73
-
74
- // see if it is possible to unify the creation of both the singular and
75
- // plural regexes or maybe even just have one list. with a complete list
76
- // of rules it may only be possible for some regular forms, but worth a shot
77
- this.pluralForms.regularForms.push([/([aeiou]y)$/i, '$1s'])
78
- this.pluralForms.regularForms.push([/y$/i, 'ies'])
79
- this.pluralForms.regularForms.push([/ife$/i, 'ives'])
80
- this.pluralForms.regularForms.push([/(antenn|formul|nebul|vertebr|vit)a$/i, '$1ae'])
81
- this.pluralForms.regularForms.push([/(octop|vir|radi|nucle|fung|cact|stimul|alumn|calcul|hippopotam|macrofung|phoet|syllab|troph)us$/i, '$1i'])
82
- this.pluralForms.regularForms.push([/(buffal|tomat|tornad)o$/i, '$1oes'])
83
- this.pluralForms.regularForms.push([/(sis)$/i, 'ses'])
84
- this.pluralForms.regularForms.push([/(matr|vert|ind|cort)(ix|ex)$/i, '$1ices'])
85
- this.pluralForms.regularForms.push([/sses$/i, 'sses'])
86
- this.pluralForms.regularForms.push([/(x|ch|ss|sh|s|z)$/i, '$1es'])
87
- this.pluralForms.regularForms.push([/^(?!talis|.*hu)(.*)man$/i, '$1men'])
88
- this.pluralForms.regularForms.push([/(.*)/i, '$1s'])
89
-
90
- // Words ending in -ff or -ffe you just add s to make the plural.
91
- // Sheriffs | Giraffes
92
- // this.pluralForms.regularForms.push([/(.+ffe?)$/i, '$1s'])
93
-
94
- // words ending in f that just add s:
95
- // roof - roofs
96
- // chief - chiefs
97
- // oaf -oafs
98
- // this.pluralForms.regularForms.push([/([^f]+f)$/i, '$1s'])
99
-
100
- // Example of words using the -f / -fe to -ves rule
101
- // leaf - leaves
102
- // wolf - wolves
103
- // calf - calves
104
- // half - halves
105
- // knife - knives
106
- // loaf - loaves
107
- // life - lives
108
- // wife - wives
109
- // shelf - shelves
110
- // thief - thieves
111
- // yourself - yourselves
112
- this.addIrregular('leaf', 'leaves')
113
- this.addIrregular('wolf', 'wolves')
114
- this.addIrregular('calf', 'calves')
115
- this.addIrregular('half', 'halves')
116
- this.addIrregular('knife', 'knives')
117
- this.addIrregular('loaf', 'loaves')
118
- this.addIrregular('life', 'lives')
119
- this.addIrregular('wife', 'wives')
120
- this.addIrregular('shelf', 'shelves')
121
- this.addIrregular('thief', 'thieves')
122
- this.addIrregular('yourself', 'yourselves')
123
-
124
- // Some words have multiple valid plural forms endings with -ves or -s:
125
- // scarf - scarfs/scarves
126
- // dwarf - dwarfs / dwarves
127
- // wharf - wharfs / wharves
128
- // handkerchief - handkerchiefs / handkerchieves
129
- // this.pluralForms.regularForms.push([/(.*r)f/i, '$1ves'])
130
-
131
- // Singular inflections
132
-
133
- // Some words have multiple valid plural forms endings with -ves or -s:
134
- // scarf - scarfs/scarves
135
- // dwarf - dwarfs / dwarves
136
- // wharf - wharfs / wharves
137
- // handkerchief - handkerchiefs / handkerchieves
138
- this.singularForms.regularForms.push([/(.*)ves$/i, '$1f'])
139
-
140
- // expenses - expense
141
- // defenses - defense
142
- this.singularForms.regularForms.push([/(.*)nses$/i, '$1nse'])
143
-
144
- this.singularForms.regularForms.push([/([^v])ies$/i, '$1y'])
145
- this.singularForms.regularForms.push([/ives$/i, 'ife'])
146
- this.singularForms.regularForms.push([/(antenn|formul|nebul|vertebr|vit)ae$/i, '$1a'])
147
- this.singularForms.regularForms.push([/(octop|vir|radi|nucle|fung|cact|stimul|alumn|calcul|hippopotam|macrofung|phoet|syllab|troph)(i)$/i, '$1us'])
148
- this.singularForms.regularForms.push([/(buffal|tomat|tornad)(oes)$/i, '$1o'])
149
- this.singularForms.regularForms.push([/(analy|naly|synop|parenthe|diagno|the)ses$/i, '$1sis'])
150
- this.singularForms.regularForms.push([/(vert|ind|cort)(ices)$/i, '$1ex'])
151
- // our pluralizer won''t cause this form of appendix (appendicies)
152
- // but we should handle it
153
- this.singularForms.regularForms.push([/(matr|append)(ices)$/i, '$1ix'])
154
- this.singularForms.regularForms.push([/(x|ch|ss|sh|s|z)es$/i, '$1'])
155
- this.singularForms.regularForms.push([/men$/i, 'man'])
156
- this.singularForms.regularForms.push([/ss$/i, 'ss'])
157
- this.singularForms.regularForms.push([/s$/i, ''])
158
-
159
- this.pluralize = function (token) {
160
- return this.ize(token, this.pluralForms, this.customPluralForms)
161
- }
162
-
163
- this.singularize = function (token) {
164
- return this.ize(token, this.singularForms, this.customSingularForms)
165
- }
166
- }
167
-
168
- util.inherits(NounInflector, SingularPluralInflector)
169
154
 
170
155
  module.exports = NounInflector
@@ -20,58 +20,44 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
20
  THE SOFTWARE.
21
21
  */
22
22
 
23
- const util = require('util')
24
23
  const SingularPluralInflector = require('./singular_plural_inflector')
25
24
  const FormSet = require('./form_set')
26
25
 
27
- /*
28
- function attach () {
29
- const inflector = this
30
-
31
- String.prototype.singularizePresentVerb = function () {
32
- return inflector.singularize(this)
33
- }
34
-
35
- String.prototype.pluralizePresentVerb = function () {
36
- return inflector.pluralize(this)
26
+ class VerbInflector extends SingularPluralInflector {
27
+ constructor () {
28
+ super()
29
+ this.ambiguous = [
30
+ 'will'
31
+ ]
32
+
33
+ // this.attach = attach
34
+
35
+ this.customPluralForms = []
36
+ this.customSingularForms = []
37
+ this.singularForms = new FormSet()
38
+ this.pluralForms = new FormSet()
39
+
40
+ this.addIrregular('am', 'are')
41
+ this.addIrregular('is', 'are')
42
+ this.addIrregular('was', 'were')
43
+ this.addIrregular('has', 'have')
44
+
45
+ this.singularForms.regularForms.push([/ed$/i, 'ed'])
46
+ this.singularForms.regularForms.push([/ss$/i, 'sses'])
47
+ this.singularForms.regularForms.push([/x$/i, 'xes'])
48
+ this.singularForms.regularForms.push([/(h|z|o)$/i, '$1es'])
49
+ this.singularForms.regularForms.push([/$zz/i, 'zzes'])
50
+ this.singularForms.regularForms.push([/([^a|e|i|o|u])y$/i, '$1ies'])
51
+ this.singularForms.regularForms.push([/$/i, 's'])
52
+
53
+ this.pluralForms.regularForms.push([/sses$/i, 'ss'])
54
+ this.pluralForms.regularForms.push([/xes$/i, 'x'])
55
+ this.pluralForms.regularForms.push([/([cs])hes$/i, '$1h'])
56
+ this.pluralForms.regularForms.push([/zzes$/i, 'zz'])
57
+ this.pluralForms.regularForms.push([/([^h|z|o|i])es$/i, '$1e'])
58
+ this.pluralForms.regularForms.push([/ies$/i, 'y'])// flies->fly
59
+ this.pluralForms.regularForms.push([/e?s$/i, ''])
37
60
  }
38
61
  }
39
- */
40
-
41
- const VerbInflector = function () {
42
- this.ambiguous = [
43
- 'will'
44
- ]
45
-
46
- // this.attach = attach
47
-
48
- this.customPluralForms = []
49
- this.customSingularForms = []
50
- this.singularForms = new FormSet()
51
- this.pluralForms = new FormSet()
52
-
53
- this.addIrregular('am', 'are')
54
- this.addIrregular('is', 'are')
55
- this.addIrregular('was', 'were')
56
- this.addIrregular('has', 'have')
57
-
58
- this.singularForms.regularForms.push([/ed$/i, 'ed'])
59
- this.singularForms.regularForms.push([/ss$/i, 'sses'])
60
- this.singularForms.regularForms.push([/x$/i, 'xes'])
61
- this.singularForms.regularForms.push([/(h|z|o)$/i, '$1es'])
62
- this.singularForms.regularForms.push([/$zz/i, 'zzes'])
63
- this.singularForms.regularForms.push([/([^a|e|i|o|u])y$/i, '$1ies'])
64
- this.singularForms.regularForms.push([/$/i, 's'])
65
-
66
- this.pluralForms.regularForms.push([/sses$/i, 'ss'])
67
- this.pluralForms.regularForms.push([/xes$/i, 'x'])
68
- this.pluralForms.regularForms.push([/([cs])hes$/i, '$1h'])
69
- this.pluralForms.regularForms.push([/zzes$/i, 'zz'])
70
- this.pluralForms.regularForms.push([/([^h|z|o|i])es$/i, '$1e'])
71
- this.pluralForms.regularForms.push([/ies$/i, 'y'])// flies->fly
72
- this.pluralForms.regularForms.push([/e?s$/i, ''])
73
- }
74
-
75
- util.inherits(VerbInflector, SingularPluralInflector)
76
62
 
77
63
  module.exports = VerbInflector
@@ -20,90 +20,91 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
20
  THE SOFTWARE.
21
21
  */
22
22
 
23
- const TenseInflector = function () {
23
+ const uppercaseify = (token) => {
24
+ return token.toUpperCase()
24
25
  }
25
26
 
26
- TenseInflector.prototype.addSingular = function (pattern, replacement) {
27
- this.customSingularForms.push([pattern, replacement])
27
+ const capitalize = (token) => {
28
+ return token[0].toUpperCase() + token.slice(1)
28
29
  }
29
30
 
30
- TenseInflector.prototype.addPlural = function (pattern, replacement) {
31
- this.customPluralForms.push([pattern, replacement])
31
+ const lowercaseify = (token) => {
32
+ return token.toLowerCase()
32
33
  }
33
34
 
34
- TenseInflector.prototype.ize = function (token, formSet, customForms) {
35
- const restoreCase = this.restoreCase(token)
36
- return restoreCase(this.izeRegExps(token, customForms) || this.izeAbiguous(token) ||
37
- this.izeRegulars(token, formSet) || this.izeRegExps(token, formSet.regularForms) ||
38
- token)
39
- }
35
+ class TenseInflector {
36
+ addSingular (pattern, replacement) {
37
+ this.customSingularForms.push([pattern, replacement])
38
+ }
40
39
 
41
- TenseInflector.prototype.izeAbiguous = function (token) {
42
- if (this.ambiguous.indexOf(token.toLowerCase()) > -1) { return token.toLowerCase() }
40
+ addPlural (pattern, replacement) {
41
+ this.customPluralForms.push([pattern, replacement])
42
+ }
43
43
 
44
- return false
45
- }
44
+ ize (token, formSet, customForms) {
45
+ const restoreCase = this.restoreCase(token)
46
+ return restoreCase(this.izeRegExps(token, customForms) || this.izeAbiguous(token) ||
47
+ this.izeRegulars(token, formSet) || this.izeRegExps(token, formSet.regularForms) ||
48
+ token)
49
+ }
46
50
 
47
- TenseInflector.prototype.pluralize = function (token) {
48
- return this.ize(token, this.pluralForms, this.customPluralForms)
49
- }
51
+ izeAbiguous (token) {
52
+ if (this.ambiguous.indexOf(token.toLowerCase()) > -1) { return token.toLowerCase() }
50
53
 
51
- TenseInflector.prototype.singularize = function (token) {
52
- return this.ize(token, this.singularForms, this.customSingularForms)
53
- }
54
+ return false
55
+ }
54
56
 
55
- const uppercaseify = function (token) {
56
- return token.toUpperCase()
57
- }
58
- const capitalize = function (token) {
59
- return token[0].toUpperCase() + token.slice(1)
60
- }
61
- const lowercaseify = function (token) {
62
- return token.toLowerCase()
63
- }
57
+ pluralize (token) {
58
+ return this.ize(token, this.pluralForms, this.customPluralForms)
59
+ }
60
+
61
+ singularize (token) {
62
+ return this.ize(token, this.singularForms, this.customSingularForms)
63
+ }
64
64
 
65
- TenseInflector.prototype.restoreCase = function (token) {
66
- if (token[0] === token[0].toUpperCase()) {
67
- if (token[1] && token[1] === token[1].toLowerCase()) {
68
- return capitalize
65
+ restoreCase (token) {
66
+ if (token[0] === token[0].toUpperCase()) {
67
+ if (token[1] && token[1] === token[1].toLowerCase()) {
68
+ return capitalize
69
+ } else {
70
+ return uppercaseify
71
+ }
69
72
  } else {
70
- return uppercaseify
73
+ return lowercaseify
71
74
  }
72
- } else {
73
- return lowercaseify
74
75
  }
75
- }
76
76
 
77
- TenseInflector.prototype.izeRegulars = function (token, formSet) {
78
- token = token.toLowerCase()
79
- // if (formSet.irregularForms.hasOwnProperty(token) && formSet.irregularForms[token]) {
80
- if (formSet.irregularForms[token]) {
81
- return formSet.irregularForms[token]
77
+ izeRegulars (token, formSet) {
78
+ token = token.toLowerCase()
79
+ // if (formSet.irregularForms.hasOwnProperty(token) && formSet.irregularForms[token]) {
80
+ if (formSet.irregularForms[token]) {
81
+ return formSet.irregularForms[token]
82
+ }
83
+
84
+ return false
82
85
  }
83
86
 
84
- return false
85
- }
87
+ addForm (singularTable, pluralTable, singular, plural) {
88
+ singular = singular.toLowerCase()
89
+ plural = plural.toLowerCase()
90
+ pluralTable[singular] = plural
91
+ singularTable[plural] = singular
92
+ }
86
93
 
87
- TenseInflector.prototype.addForm = function (singularTable, pluralTable, singular, plural) {
88
- singular = singular.toLowerCase()
89
- plural = plural.toLowerCase()
90
- pluralTable[singular] = plural
91
- singularTable[plural] = singular
92
- }
94
+ addIrregular (singular, plural) {
95
+ this.addForm(this.singularForms.irregularForms, this.pluralForms.irregularForms, singular, plural)
96
+ }
93
97
 
94
- TenseInflector.prototype.addIrregular = function (singular, plural) {
95
- this.addForm(this.singularForms.irregularForms, this.pluralForms.irregularForms, singular, plural)
96
- }
98
+ izeRegExps (token, forms) {
99
+ let i, form
100
+ for (i = 0; i < forms.length; i++) {
101
+ form = forms[i]
97
102
 
98
- TenseInflector.prototype.izeRegExps = function (token, forms) {
99
- let i, form
100
- for (i = 0; i < forms.length; i++) {
101
- form = forms[i]
103
+ if (token.match(form[0])) { return token.replace(form[0], form[1]) }
104
+ }
102
105
 
103
- if (token.match(form[0])) { return token.replace(form[0], form[1]) }
106
+ return false
104
107
  }
105
-
106
- return false
107
108
  }
108
109
 
109
110
  module.exports = TenseInflector