Skip to content

Commit

Permalink
change text params - 1x
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Nov 3, 2022
1 parent 5977bfa commit 0784139
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
21 changes: 10 additions & 11 deletions scratch.js
Expand Up @@ -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?",
Expand All @@ -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 }))
Expand Down
2 changes: 2 additions & 0 deletions src/1-one/output/api/_fmts.js
Expand Up @@ -10,13 +10,15 @@ const fmts = {
form: 'normal',
},
machine: {
keepSpace: false,
whitespace: 'some',
punctuation: 'some',
case: 'none',
unicode: 'some',
form: 'machine',
},
root: {
keepSpace: false,
whitespace: 'some',
punctuation: 'some',
case: 'some',
Expand Down
18 changes: 11 additions & 7 deletions src/1-one/output/api/text.js
Expand Up @@ -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)
},
}
2 changes: 1 addition & 1 deletion src/3-three/nouns/api/toPlural.js
Expand Up @@ -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?
Expand Down

0 comments on commit 0784139

Please sign in to comment.