Skip to content

Commit

Permalink
Merge pull request #1151 from spencermountain/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
spencermountain authored Oct 10, 2024
2 parents 8a2fd3d + 9c876a9 commit e22ba77
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 27 deletions.
2 changes: 1 addition & 1 deletion builds/compromise.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion builds/one/compromise-one.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion builds/one/compromise-one.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion builds/three/compromise-three.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion builds/three/compromise-three.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion builds/two/compromise-two.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion builds/two/compromise-two.mjs

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ While all _Major_ releases should be reviewed, our only _large_ releases are **v
- **[fix]** - .before() .after()
-->

#### 14.14.1 [July 2024]
#### 14.14.2 [Oct 2024]
- **[fix]** - runtime error in punctuation replace #1150

#### 14.14.1 [Oct 2024]
- **[update]** - compromise-dates 3.7.0
- **[fix]** - runtime error in number parser #1145
- **[update]** - dependencies
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Spencer Kelly <[email protected]> (http://spencermounta.in)",
"name": "compromise",
"description": "modest natural language processing",
"version": "14.14.1",
"version": "14.14.2",
"module": "./src/three.js",
"main": "./src/three.js",
"unpkg": "./builds/compromise.js",
Expand Down Expand Up @@ -132,4 +132,4 @@
"_tests/**"
],
"license": "MIT"
}
}
32 changes: 19 additions & 13 deletions scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@ nlp.plugin(plg)
// nlp.verbose('tagger')



const context = {
today: '2024-09-24'
}

let text = 'first half of march'
// let text = 'in 2-3 years'
// let text = 'March 28 next year'
// let text = 'June next year'
const doc1 = nlp(text).debug()
const dates1 = doc1.dates(context).get()[0]
console.log(text)
console.log(dates1)
const text = 'to the window'

// Throws an error, capturing group at beginning, replacing with an empty string
const doc1 = nlp(text)
doc1.match('[to] the window', 0).replaceWith('by')
doc1.debug()
doc1.match('[by]', 0).debug().replaceWith('')

// Works, capturing group at beginning, replacing with a non-empty string
const doc2 = nlp(text)
doc2.match('[to] the window', 0).replaceWith('near')
doc2.match('[near]', 0).replaceWith('by')
console.log('doc2', doc2.text())

// Works, capture group at end, replacing with an empty string
const doc3 = nlp(text)
doc3.match('to the [window]', 0).replaceWith('wall')
doc3.match('[wall]', 0).replaceWith('')
console.log('doc3', doc3.text())


// const doc = nlp('one match match after')
Expand Down
14 changes: 11 additions & 3 deletions src/1-one/change/api/replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,17 @@ fns.replaceWith = function (input, keep = {}) {
}
}

// try to keep some pre-post punctuation
if (originalPre) main.docs[0][0].pre = originalPre
if (originalPost && !main.docs[0][main.docs[0].length - 1].post.trim()) main.docs[0][main.docs[0].length - 1].post = originalPost
// try to keep some pre-punctuation
if (originalPre) {
main.docs[0][0].pre = originalPre
}
// try to keep any post-punctuation
if (originalPost && main.docs[0]) {
let lastOne = main.docs[0][main.docs[0].length - 1]
if (!lastOne.post.trim()) {
lastOne.post = originalPost
}
}

// what should we return?
let m = main.toView(ptrs).compute(['index', 'freeze', 'lexicon'])
Expand Down
2 changes: 1 addition & 1 deletion src/_version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default '14.14.1'
export default '14.14.2'

0 comments on commit e22ba77

Please sign in to comment.