diff --git a/package.json b/package.json index 0c334af3a..897cc7c70 100755 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Spencer Kelly (http://spencermounta.in)", "name": "nlp_compromise", "description": "natural language processing in the browser", - "version": "0.3.0", + "version": "0.3.1", "repository": { "type": "git", "url": "git://github.com/spencermountain/nlp-node.git" diff --git a/src/parents/noun/conjugate/inflect.js b/src/parents/noun/conjugate/inflect.js index 26f9eb347..88c4cb4a9 100644 --- a/src/parents/noun/conjugate/inflect.js +++ b/src/parents/noun/conjugate/inflect.js @@ -3,6 +3,12 @@ //https://github.com/pksunkara/inflect/blob/master/lib/defaults.js var inflect = (function() { + + var titlecase=function(str){ + if(str==null){return ''} + return str.charAt(0).toUpperCase() + str.slice(1) + } + var irregulars = [ ['child', 'children'], ['person', 'people'], @@ -301,7 +307,6 @@ var inflect = (function() { ] - var pluralize = function(str) { var low = str.toLowerCase() //uncountable @@ -313,15 +318,15 @@ var inflect = (function() { return r[0] == low }) if (found[0]) { - if (low == str) { - return found[0][1] + if (titlecase(low) == str) { //handle capitalisation properly + return titlecase(found[0][1]) } else { - return found[0][1].charAt(0).toUpperCase() + string.slice(1) + return found[0][1] } } //inflect first word of preposition-phrase if (str.match(/([a-z]*) (of|in|by|for) [a-z]/)) { - var first = str.match(/^([a-z]*) (of|in|by|for) [a-z]/)[1] + var first = (str.match(/^([a-z]*) (of|in|by|for) [a-z]/)||[])[1] if (first) { var better_first = pluralize(first) return better_first + str.replace(first, '') @@ -425,10 +430,10 @@ var inflect = (function() { return r[1] == low }) if (found[0]) { - if (low == str) { - return found[0][0] + if (titlecase(low) == str) { //handle capitalisation properly + return titlecase(found[0][0]) } else { - return found[0][0].charAt(0).toUpperCase() + string.slice(1) + return found[0][0] } } //inflect first word of preposition-phrase @@ -521,12 +526,17 @@ var inflect = (function() { // console.log(inflect.inflect('bus')) // console.log(inflect.inflect('statistics')) +// bus +// kiss +// console.log(nlp.noun('crisis').pluralize() == 'crises') +// console.log(nlp.noun('analysis').pluralize() == 'analyses') +// console.log(nlp.noun('neurosis').pluralize() == 'neuroses') -/* - -bus -kiss - console.log(nlp.noun('crisis').pluralize() == 'crises') - console.log(nlp.noun('analysis').pluralize() == 'analyses') - console.log(nlp.noun('neurosis').pluralize() == 'neuroses') -*/ \ No newline at end of file +// console.log(inflect.singularize('Indices')=='Index') +// console.log(inflect.singularize('indices')=='index') +// console.log(inflect.pluralize('index')=='indices') +// console.log(inflect.pluralize('Index')=='Indices') +// console.log(inflect.inflect('Indices').singular=='Index') +// console.log(inflect.inflect('indices').singular=='index') +// console.log(inflect.inflect('index').plural=='indices') +// console.log(inflect.inflect('Index').plural=='Indices') diff --git a/src/parents/noun/conjugate/test/test_inflections.js b/src/parents/noun/conjugate/test/test_inflections.js deleted file mode 100644 index 1e4e83814..000000000 --- a/src/parents/noun/conjugate/test/test_inflections.js +++ /dev/null @@ -1,130 +0,0 @@ -var inflect = require("../inflect") - -var test = [ - ["snake", "snakes"], - ["ski", "skis"], - ["Barrymore", "Barrymores"], - ["witch", "witches"], - ["box", "boxes"], - ["gas", "gases"], - ["bus", "buses"], - ["kiss", "kisses"], - ["Jones", "Joneses"], - ["child", "children"], - ["woman", "women"], - ["man", "men"], - ["person", "people"], - ["goose", "geese"], - ["mouse", "mice"], - ["barracks", "barracks"], - ["deer", "deer"], - ["nucleus", "nuclei"], - ["syllabus", "syllabi"], - ["fungus", "fungi"], - ["cactus", "cacti"], - ["thesis", "theses"], - ["crisis", "crises"], - ["phenomenon", "phenomena"], - ["index", "indices"], - ["appendix", "appendices"], - ["criterion", "criteria"], - ["berry", "berries"], - ["activity", "activities"], - ["daisy", "daisies"], - ["church", "churches"], - ["bus", "buses"], - ["fox", "foxes"], - ["stomach", "stomachs"], - ["epoch", "epochs"], - ["knife", "knives"], - ["half", "halves"], - ["scarf", "scarves"], - ["chief", "chiefs"], - ["spoof", "spoofs"], - ["solo", "solos"], - ["zero", "zeros"], - ["avocado", "avocados"], - ["studio", "studios"], - ["zoo", "zoos"], - ["embryo", "embryos"], - ["hero", "heroes"], - ["banjo", "banjos"], - ["cargo", "cargos"], - ["flamingo", "flamingos"], - ["fresco", "frescos"], - ["ghetto", "ghettos"], - ["halo", "halos"], - ["mango", "mangos"], - ["memento", "mementos"], - ["motto", "mottos"], - ["tornado", "tornados"], - ["tuxedo", "tuxedos"], - ["volcano", "volcanos"], - ["crisis", "crises"], - ["analysis", "analyses"], - ["neurosis", "neuroses"], - ["aircraft", "aircraft"], - ["bass", "bass"], - ["bison", "bison"], - ["deer", "deer"], - ["fish", "fish"], - ["fowl", "fowl"], - ["halibut", "halibut"], - ["moose", "moose"], - ["salmon", "salmon"], - ["sheep", "sheep"], - ["spacecraft", "spacecraft"], - ["tuna", "tuna"], - ["trout", "trout"], - ["armadillo", "armadillos"], - ["auto", "autos"], - ["bravo", "bravos"], - ["bronco", "broncos"], - ["casino", "casinos"], - ["combo", "combos"], - ["gazebo", "gazebos"], - ["kilo", "kilos"], - ["kimono", "kimonos"], - ["logo", "logos"], - ["memo", "memos"], - ["poncho", "ponchos"], - ["photo", "photos"], - ["pimento", "pimentos"], - ["pro", "pros"], - ["sombrero", "sombreros"], - ["taco", "tacos"], - ["memo", "memos"], - ["torso", "torsos"], - ["xylophone", "xylophones"], - ["quintuplet", "quintuplets"], - ["worrywart", "worrywarts"], - ["nerd", "nerds"], - ["lollipop", "lollipops"], - ["eyebrow", "eyebrows"], - - // ["man of steel", "men of steel"], - // ["wolf of wall street", "wolves of wall street"], - // ["salt of the earth", "salt of the earth"], - -] -test.forEach(function(t) { - var str = "console.log(nlp.noun.singularize('" + t[1] + "')=='" + t[0] + "')" - // console.log(str) - var p = inflect.pluralize(t[0]) - if (!(p == t[1])) { - console.log(t) - } - var s = inflect.singularize(t[1]) - if (!(s == t[0])) { - console.log(t) - } - // console.log(p+" "+ (p==t[1])) - -}) -// console.log(singularize("poppies")) -// console.log(singularize("geniuses")) - -//NOT WORKING singularize-direction -// [ 'half', 'halves' ] -// [ 'scarf', 'scarves' ] -// [ 'neurosis', 'neuroses' ] \ No newline at end of file