Skip to content

Commit

Permalink
inflection bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Jan 14, 2015
1 parent 6396e9a commit 9900747
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 147 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Spencer Kelly <[email protected]> (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"
Expand Down
42 changes: 26 additions & 16 deletions src/parents/noun/conjugate/inflect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -301,7 +307,6 @@ var inflect = (function() {

]


var pluralize = function(str) {
var low = str.toLowerCase()
//uncountable
Expand All @@ -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, '')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
*/
// 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')
130 changes: 0 additions & 130 deletions src/parents/noun/conjugate/test/test_inflections.js

This file was deleted.

0 comments on commit 9900747

Please sign in to comment.