Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last word missing from capture groups when . syntax used #1139

Open
Fdawgs opened this issue Aug 16, 2024 · 1 comment
Open

Last word missing from capture groups when . syntax used #1139

Fdawgs opened this issue Aug 16, 2024 · 1 comment
Labels

Comments

@Fdawgs
Copy link
Contributor

Fdawgs commented Aug 16, 2024

Node version: 20.16.0
Compromise version: 14.14.0
Compromise-dates version: 3.6.0

Bit of an odd one, when using capture groups with the . syntax, the last word is always missing:

'use strict'

/** @type {import('compromise').default} */
const nlp = require('compromise')
const nlpDates = require('compromise-dates')
nlp.plugin(nlpDates)

const text = 'I ate some cheeseburgers with Mr. Lahey'

const doc = nlp(text)
let result = doc.match('[#PastTense .{0,10} cheeseburgers] with', 0)
console.log(result.out('text'))
// Outputs 'ate some', expected 'ate some cheeseburgers'

result = doc.match('[#PastTense some cheeseburgers] with', 0)
console.log(result.out('text'))
// Outputs 'ate some cheeseburgers' as expected

result = doc.match('[#PastTense .{0,10} cheeseburgers] with').groups(0)
console.log(result.out('text'))
// Outputs 'ate some', expected 'ate some cheeseburgers'
@Fdawgs Fdawgs changed the title Last word missing from capture groups Last word missing from capture groups when . syntax used Aug 16, 2024
@spencermountain
Copy link
Owner

can reproduce this:

const doc = nlp('one match after')
 // works without capture
doc.match('one .* after').debug()
// incomplete match with capture
doc.match('[one .* after]', 0).debug()

// and strangely, this works fine
doc.match('[one match+ after]', 0).debug() 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants