Skip to content

Commit

Permalink
match term by id
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Oct 28, 2022
1 parent abc487e commit ff93ea2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.md
Expand Up @@ -7,6 +7,7 @@ compromise uses semver, and pushes to npm and github frequently
While all _Major_ releases should be reviewed, our only _large_ releases are **v6** in 2016 **v12** in 2019 and **v14** in 2022. Others have been mostly incremental.

<!-- #### 14.6.0 [Unreleased]
- **[new]** - match term id
-->

#### 14.6.0 [Oct 2022]
Expand Down
14 changes: 11 additions & 3 deletions scratch.js
Expand Up @@ -2,13 +2,21 @@
import nlp from './src/three.js'
// import plg from './plugins/dates/src/plugin.js'
// nlp.plugin(plg)
// nlp.verbose('tagger')
let txt = ''
// let doc
// let m

let doc = nlp("I am a boy")
console.log(doc.sentences().json()[0].sentence)
// nlp.verbose('tagger')

// let doc = nlp('i got in one little fight and my momma got scared, she said you\'re moving')



let doc = nlp('one two three')
let two = doc.match('two')
let id = two.json()[0].terms[0].id
doc.match([{ id: id }]).debug()
// console.log(id)
/*
{
subject: 'i',
Expand Down
4 changes: 4 additions & 0 deletions src/1-one/match/methods/match/term/doesMatch.js
Expand Up @@ -17,6 +17,10 @@ const doesMatch = function (term, reg, index, length) {
if (reg.end === true && index !== length - 1) {
return false
}
// match an id
if (reg.id !== undefined && reg.id === term.id) {
return true
}
//support a text match
if (reg.word !== undefined) {
// check case-sensitivity, etc
Expand Down
9 changes: 9 additions & 0 deletions tests/two/match/fancy-match.test.js
Expand Up @@ -76,3 +76,12 @@ test('match-doc-freeze', function (t) {
t.deepEqual(arr, ['boy', 'girl.'], here + 'match-doc-2')
t.end()
})

test('match-term-id', function (t) {
let doc = nlp('one two three')
let two = doc.match('two')
let id = two.json()[0].terms[0].id
let m = doc.match([{ id: id }])
t.ok(m.has('^two$'), here + 'match-id')
t.end()
})

0 comments on commit ff93ea2

Please sign in to comment.