From 07841399367582c082354bd28d2c72ddc9872caf Mon Sep 17 00:00:00 2001 From: spencer kelly Date: Thu, 3 Nov 2022 16:07:44 -0400 Subject: [PATCH] change text params - 1x --- scratch.js | 21 ++++++++++----------- src/1-one/output/api/_fmts.js | 2 ++ src/1-one/output/api/text.js | 18 +++++++++++------- src/3-three/nouns/api/toPlural.js | 2 +- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/scratch.js b/scratch.js index b53217885..fc10f63d3 100644 --- a/scratch.js +++ b/scratch.js @@ -15,18 +15,17 @@ let txt = '' // bug 3 -// let doc = nlp("Dr. John Smith-McDonald...?") +// let doc = nlp("Dr. John Smith-McDonald?") +// // let doc = nlp("Petsmart application? ") // let opts = { // keepPunct: false, -// abbreviations: false, +// punctuation: 'none', +// // abbreviations: false, // case: false, // } -// console.log(doc.text(opts)) +// console.log(doc.match('McDonald').text('machine') + '|') -let doc = nlp('one two three. four five') -console.log(doc.isFull()) - let arr = [ // "keep a cool head", "petsmart application?", @@ -36,11 +35,11 @@ let arr = [ // "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()) -// }) +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 })) diff --git a/src/1-one/output/api/_fmts.js b/src/1-one/output/api/_fmts.js index 061807ce7..3e74efebb 100644 --- a/src/1-one/output/api/_fmts.js +++ b/src/1-one/output/api/_fmts.js @@ -10,6 +10,7 @@ const fmts = { form: 'normal', }, machine: { + keepSpace: false, whitespace: 'some', punctuation: 'some', case: 'none', @@ -17,6 +18,7 @@ const fmts = { form: 'machine', }, root: { + keepSpace: false, whitespace: 'some', punctuation: 'some', case: 'some', diff --git a/src/1-one/output/api/text.js b/src/1-one/output/api/text.js index 4305d19b7..df94e7f3e 100644 --- a/src/1-one/output/api/text.js +++ b/src/1-one/output/api/text.js @@ -8,26 +8,30 @@ const isObject = val => { export default { /** */ text: function (fmt) { - let opts = { - keepSpace: true, - keepPunct: true, - } + let opts = {} if (fmt && typeof fmt === 'string' && fmts.hasOwnProperty(fmt)) { opts = Object.assign({}, fmts[fmt]) } else if (fmt && isObject(fmt)) { - opts = Object.assign({}, opts, fmt)//todo: fixme + opts = Object.assign({}, fmt)//todo: fixme } - if (this.pointer) { + if (opts.keepSpace === undefined && this.pointer) { opts.keepSpace = false + } + if (opts.keepPunct === undefined && this.pointer) { let ptr = this.pointer[0] if (ptr && ptr[1]) { opts.keepPunct = false } else { opts.keepPunct = true } - } else { + } + // set defaults + if (opts.keepPunct === undefined) { opts.keepPunct = true } + if (opts.keepSpace === undefined) { + opts.keepSpace = true + } return textFromDoc(this.docs, opts) }, } diff --git a/src/3-three/nouns/api/toPlural.js b/src/3-three/nouns/api/toPlural.js index e21fa7a87..a6aca7bf9 100644 --- a/src/3-three/nouns/api/toPlural.js +++ b/src/3-three/nouns/api/toPlural.js @@ -20,7 +20,7 @@ const nounToPlural = function (m, parsed) { const { methods, model } = m.world const { toPlural } = methods.two.transform.noun // inflect the root noun - let str = parsed.root.text('normal') + let str = parsed.root.text({ keepPunct: false }) let plural = toPlural(str, model) m.match(parsed.root).replaceWith(plural, keep).tag('Plural', 'toPlural') // should we change the determiner/article?