Skip to content

Commit

Permalink
toPlural fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Nov 3, 2022
1 parent 1ab1e07 commit 373131b
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 21 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ compromise uses semver, and pushes to npm and github frequently

While all _Major_ releases should be reviewed, our only _large_ releases are **v6** in 2016 **v12** in 2019 and **v14** in 2022. Others have been mostly incremental.

<!-- #### [planned breaking]
- fix doc.json(0) inconsistency
-->

<!-- #### 14.6.0 [Unreleased]
- **[new]** - match term id
- **[change]** - tag text by default on .concat('')
- **[change]** - allow changing term prePunctuation
- **[new]** - .wrap() method
-->

Expand Down
1 change: 1 addition & 0 deletions data/lexicon/adjectives/adjectives.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,5 +643,6 @@ export default [
'beside',
'alright',
'top notch',
'self sufficient'
]

3 changes: 3 additions & 0 deletions data/lexicon/nouns/uncountables.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,7 @@ export default [
'arithmetic',
'static',
'logic',
'hunger',
'sushi',
'seating',
]
40 changes: 26 additions & 14 deletions scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,32 @@ let txt = ''


// bug 3
// let doc = nlp("Dr. John Smith-McDonald...")
// let opts = {
// keepPunct: false,
// abbreviations: false,
// case: false,
// }
// console.log(doc.text(opts))
let doc = nlp("Dr. John Smith-McDonald...")
let opts = {
keepPunct: false,
abbreviations: false,
case: false,
}
console.log(doc.text(opts))

// nlp('i drank a margharita').nouns().toPlural().all().text()

let arr = [
// "keep a cool head",
"petsmart application?",
// "attacked by a bear?",
// "Gal's DIARY: He ws quiet 2dy.",
// "All right relax.",
// "HP to be self-sufficient by 2010",
// "the woman isn't dead.",
]
// arr.forEach(str => {
// let doc = nlp(str)
// doc.nouns().toPlural()
// console.log(doc.text())
// })
// let doc = nlp("petsmart application?")
// let m = doc.match('application')
// console.log(doc.text({ punctuation: false }))

// nlp('two turtledoves and a partridge in a pear tree').nouns().isSingular().out('array')

Expand All @@ -49,13 +66,8 @@ let txt = ''
// nlp('~sorta').match('sorta').debug()


// console.log(nlp("telegram for Heywood U. Cuddleme").people().json(0))

// let doc = nlp('i walk and swim gracefully')
// let json = doc.json(0)
// console.log(json)

let arr = [
arr = [

// `If you notice swelling`,
// `and whisk to fully incorporate`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const suffixes = {
a: [
[/(antenn|formul|nebul|vertebr|vit)a$/i, '$1ae'],
[/([ti])a$/i, '$1a'],
[/ia$/i, 'ia'],
],
e: [
[/(kn|l|w)ife$/i, '$1ives'],
Expand Down
6 changes: 3 additions & 3 deletions src/2-two/preTagger/model/lexicon/_data.js

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions src/3-three/nouns/api/toPlural.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const keep = { tags: true }

const hasPlural = function (parsed) {
let { root } = parsed
if (root.has('^(#Uncountable|#Possessive|#ProperNoun|#Place|#Pronoun)+$')) {
if (root.has('^(#Uncountable|#Possessive|#ProperNoun|#Place|#Pronoun|#Acronym)+$')) {
return false
}
return true
Expand All @@ -26,7 +26,17 @@ const nounToPlural = function (m, parsed) {
// should we change the determiner/article?
if (parsed.determiner.has('(a|an)')) {
// 'a captain' -> 'the captains'
m.replace(parsed.determiner, 'the', keep)
// m.replace(parsed.determiner, 'the', keep)
m.remove(parsed.determiner)
}
// should we change the following copula?
let copula = parsed.root.after('not? #Adverb+? [#Copula]', 0)
if (copula.found) {
if (copula.has('is')) {
m.replace(copula, 'are')
} else if (copula.has('was')) {
m.replace(copula, 'were')
}
}
return m
}
Expand Down
11 changes: 10 additions & 1 deletion tests/three/nouns/toPlural.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,16 @@ test('toPlural - longer:', function (t) {
[`the tornado in Barrie swept through downtown`, `the tornados in Barrie swept through downtown`],
[`no cookie until after dinner`, `no cookies until after dinners`],
[`my finger looked green afterwards`, `my fingers looked green afterwards`],
// [`my finger was green afterwards`, `my fingers were green afterwards`],

// ["keep a cool head", "keep cool heads"],
["petsmart application?", "petsmart applications?"],
["attacked by a bear?", "attacked by bears?"],
// ["Gal's DIARY: He ws quiet 2dy.", "Gal's DIARY: He ws quiet 2dy."],
["All right relax.", "All right relax."],
["HP to be self-sufficient by 2010", "HP to be self-sufficient by 2010"],
["the woman", "the women"],
["the woman isn't dead.", "the women are not dead."],
[`my finger was green afterwards`, `my fingers were green afterwards`],
]
arr.forEach(function (a) {
let doc = nlp(a[0])
Expand Down

0 comments on commit 373131b

Please sign in to comment.