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

Match Syntax: Multiple not-words #997

Closed
thegoatherder opened this issue Mar 13, 2023 · 4 comments
Closed

Match Syntax: Multiple not-words #997

thegoatherder opened this issue Mar 13, 2023 · 4 comments

Comments

@thegoatherder
Copy link
Contributor

The match-syntax !foo{0,5} works well for matching: any word (except for the word foo) 0-5 times
Is there any match syntax for expanding this to multiple not-want words?

I have tried:

  • !(foo|bar){0,5}
  • (!foo|!bar){0,5}
  • (!foo && !bar){0,5}

Here's some playing around:

const nlp = require('compromise')
const patterns = ['before (!foo|!bar){0,8}', 'before (!foo && !bar){0,8} something', 'before !(foo|bar){0,8} something']

const sentences = [
  { want: true, text: 'before one two three four five six seven something' },
  { want: false, text: 'before one bar two three something' },
  { want: false, text: 'before one two foo four five six something' },
]

patterns.forEach((pattern) => {
  console.log(pattern)
  sentences.forEach((sentence) => {
    const result = nlp(sentence.text).has(pattern) === sentence.want ? '✅' : '❌'
    console.log(`${result} ${sentence.text}`)
  })
  console.log()
})

Output

I'm failing to get an output where all three sentences get ✅ for a pattern...

before (!foo|!bar){0,8}
✅ before one two three four five six seven something
❌ before one bar two three something
❌ before one two foo four five six something

before (!foo && !bar){0,8} something
❌ before one two three four five six seven something
✅ before one bar two three something
✅ before one two foo four five six something

before !(foo|bar){0,8} something
✅ before one two three four five six seven something
❌ before one bar two three something
❌ before one two foo four five six something
@spencermountain
Copy link
Owner

yeah - !(foo|bar){0,3} should work - looks like the tokenizer bonks the syntax

console.log(nlp.parseMatch('match !(foo|bar){0,3}'))

happy to take a look at this

@spencermountain
Copy link
Owner

fixed on dev

@spencermountain
Copy link
Owner

fixed in 14.9.0
thanks

@vjsnagglepuss
Copy link

thank you so much for this fix @spencermountain -- it will make my life much easier!

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

No branches or pull requests

3 participants