Skip to content

Commit

Permalink
isfull method
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Nov 3, 2022
1 parent 373131b commit 5977bfa
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.md
Expand Up @@ -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]
Expand Down
17 changes: 10 additions & 7 deletions scratch.js
Expand Up @@ -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?",
Expand Down
21 changes: 21 additions & 0 deletions src/API/methods/utils.js
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions 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()
})

0 comments on commit 5977bfa

Please sign in to comment.