diff --git a/changelog.md b/changelog.md index b68822e50..2c19bb199 100644 --- a/changelog.md +++ b/changelog.md @@ -15,6 +15,7 @@ While all _Major_ releases should be reviewed, our only _large_ releases are **v - **[change]** - tag text by default on .concat('') - **[change]** - allow changing term prePunctuation - **[new]** - .wrap() method +- **[new]** - .isFull() method --> #### 14.6.0 [Oct 2022] diff --git a/scratch.js b/scratch.js index 89fbe700a..b53217885 100644 --- a/scratch.js +++ b/scratch.js @@ -15,15 +15,18 @@ 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)) +let doc = nlp('one two three. four five') +console.log(doc.isFull()) + let arr = [ // "keep a cool head", "petsmart application?", diff --git a/src/API/methods/utils.js b/src/API/methods/utils.js index 5b14379d0..f9fb361ed 100644 --- a/src/API/methods/utils.js +++ b/src/API/methods/utils.js @@ -111,6 +111,27 @@ const utils = { }, 0) }, + // is the pointer the full sentence? + isFull: function () { + let ptrs = this.pointer + if (!ptrs) { + return true + } + let document = this.document + for (let i = 0; i < ptrs.length; i += 1) { + let [n, start, end] = ptrs[i] + // it's not the start + if (n !== i || start !== 0) { + return false + } + // it's too short + if (document[n].length > end) { + return false + } + } + return true + } + } utils.group = utils.groups utils.fullSentence = utils.fullSentences diff --git a/tests/one/misc/isFull.test.js b/tests/one/misc/isFull.test.js new file mode 100644 index 000000000..a8558af42 --- /dev/null +++ b/tests/one/misc/isFull.test.js @@ -0,0 +1,29 @@ +import test from 'tape' +import nlp from '../_lib.js' +const here = '[one/isFull] ' + +test('isFull :', function (t) { + let doc = nlp('one two three. four five. six seven eight. nine') + t.equal(doc.isFull(), true, here + 'full') + + let m = doc.match('four five') + t.equal(m.isFull(), false, here + 'part') + + m = doc.terms() + t.equal(m.isFull(), false, here + 'terms') + + m = doc.harden() + t.equal(m.isFull(), true, here + 'harden') + + m = m.eq(2) + t.equal(m.isFull(), false, here + 'eq') + + doc.remove('four') + t.equal(doc.isFull(), true, here + 'remove') + doc.remove('five') + t.equal(doc.isFull(), true, here + 'remove2') + + m = doc.terms().all() + t.equal(m.isFull(), true, here + 'all') + t.end() +})