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

Capture group tagging does not work when trailing an optional negative #1148

Open
Fdawgs opened this issue Oct 3, 2024 · 0 comments
Open

Comments

@Fdawgs
Copy link
Contributor

Fdawgs commented Oct 3, 2024

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

As title states, when a capture group is trailing an optional negative (? or {0,x}) it fails to capture the group.
If the negative is not optional it's fine (see doc8 example below).

Hopefully it's just down to me not understanding match syntax, otherwise it may be related to #1139?

'use strict'

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

const text = 'To be reviewed urgently'
const doc = nlp(text)
const doc2 = doc.clone()
const doc3 = doc.clone()
const doc4 = doc.clone()
const doc5 = doc.clone()
const doc6 = doc.clone()
const doc7 = doc.clone()

// Tags #PastTense and #Urgent as #SuperSerious
console.log('negative tag range, no group access')
doc2.match('#PastTense !#Conjunction{0,10} [#Adverb]').tag('SuperSerious')
doc2.debug()

// Does not tag #Adverb as #SuperSerious
doc3.match('#PastTense !#Conjunction{0,10} [#Adverb]', 0).tag('SuperSerious')
doc3.debug()

// Tags #Adverb as #SuperSerious
console.log('positive tag optional')
doc4.match('#PastTense #Conjunction{0,10} [#Adverb]', 0).tag('SuperSerious')
doc4.debug()

// Does not tag #Adverb as #SuperSerious
console.log('negative tag optional')
doc5.match('#PastTense !#Conjunction? [#Adverb]', 0).tag('SuperSerious')
doc5.debug()

// Does not tag #Adverb as #SuperSerious
console.log('negative non-tag optional')
doc6.match('#PastTense !and{0,10} [#Adverb]', 0).tag('SuperSerious')
doc6.debug()

console.log('negative tag range, no tagging')
const test = doc7.match('#PastTense !#Conjunction{0,10} [#Adverb]', 0)
console.log(test.out('text') || 'no match')

console.log('negative tag range')
const newDoc = nlp('To be reviewed super urgently')
const doc8 = newDoc.match('#PastTense !#Conjunction [#Adverb]', 0).tag('SuperSerious')
doc8.debug()
@Fdawgs Fdawgs changed the title Capture group tagging does not work when trailing a negative Capture group tagging does not work when trailing an optional negative Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant