From 329f52b066826bb101ef7bd789d5105cd6704569 Mon Sep 17 00:00:00 2001 From: spencer kelly Date: Mon, 10 Jun 2024 08:24:32 -0400 Subject: [PATCH] fix #1113 toNumbers return vals --- scratch.js | 4 ++-- src/3-three/numbers/numbers/api.js | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/scratch.js b/scratch.js index 113bc548e..46b5971d4 100644 --- a/scratch.js +++ b/scratch.js @@ -4,10 +4,10 @@ import nlp from './src/three.js' // nlp.plugin(plg) // nlp.verbose('tagger') -const text_1 = 'There are twenty-four apples and 12000 oranges on the table.' +const text_1 = '90 hertz' const doc = nlp(text_1) -doc.values(0).toNumber().debug() +doc.values().toNumber().debug() // let doc = nlp(` `).debug() diff --git a/src/3-three/numbers/numbers/api.js b/src/3-three/numbers/numbers/api.js index 4801cf300..352fe621c 100644 --- a/src/3-three/numbers/numbers/api.js +++ b/src/3-three/numbers/numbers/api.js @@ -52,18 +52,20 @@ const addMethod = function (View) { /** convert to numeric form like '8' or '8th' */ toNumber() { - let m = this.if('#TextValue') - m.forEach(val => { + let res = this.map(val => { + if (!this.has('#TextValue')) { + return val + } let obj = parse(val) if (obj.num === null) { - return + return val } let fmt = val.has('#Ordinal') ? 'Ordinal' : 'Cardinal' let str = format(obj, fmt) val.replaceWith(str, { tags: true }) - val.tag('NumericValue') + return val.tag('NumericValue') }) - return this + return new Numbers(res.document, res.pointer) } /** add commas, or nicer formatting for numbers */ toLocaleString() {