Compromise: Capture group doesn't work for .+ or *

Created on 18 Dec 2019  Â·  8Comments  Â·  Source: spencermountain/compromise

Quick one since we're all ready for the holidays!
Happy to go into more detail when people are free.

Capture groups seem to capture everything BEFORE your target, if using .+ or *. Using OR (#Noun|#Verb)+ works fine.

Quick console example:

> nlp('John always ravenously eats his glue').match('john [.+] eats').tag('test').debug()
=====
  -----
  | 'John'     - MaleName, FirstName, Person, ProperNoun, Singular, Noun, TitleCase, Test
  | 'always'   - Adverb, Test
  | 'ravenously'  - Adverb, Test
  | 'eats'     - PresentTense, Verb, Test

> nlp('John always ravenously eats his glue').match('john [*] eats').tag('test').debug()
=====
  -----
  | 'John'     - MaleName, FirstName, Person, ProperNoun, Singular, Noun, TitleCase, Test
  | 'always'   - Adverb, Test
  | 'ravenously'  - Adverb, Test
  | 'eats'     - PresentTense, Verb, Test

> nlp('John always ravenously eats his glue').match('john [#Adverb+] eats').tag('test').debug()
=====
  -----
  | 'always'   - Adverb, Test
  | 'ravenously'  - Adverb, Test

> nlp('John always ravenously eats his glue').match('john [(#Noun|#Adverb)+] eats').tag('test').debug()
=====
  -----
  | 'always'   - Adverb, Test
  | 'ravenously'  - Adverb, Test

Last two examples are correct and expected behaviour of the first 2.

bug

All 8 comments

ah, thank you.
Looking into the issue, i guess I see what this comment is for ;).

um, maybe I could ask your advice on something similar that I got stuck on -
It may be the same issue:

// === optional greedy at start ==
nlp(`wayne's world, party time`)
  .match('#Noun+? wayne')
  .debug()
// 'wayne's world, party time'

'aaa'.match(/b?a/)
//a


// ==== greedy-until-anything====
nlp('Toronto Ontario foo')
  .match('#Place+ .')
  .debug()
//'toronto ontario'

'aaab'.match(/a+b/)

I think your examples are the same as the 2nd example, right?
this stuff does my head in.
thanks

Yeh was wondering about those comments :D Will take a look proper look tomorrow but looks like a bug if I'm understanding the expected behaviour...

This works fine:

nlp(`wayne's world, party time`)
  .match('#Noun+? world') // changed end to 2nd word
  .text()
// wayne's world

Probably escaping too early somewhere...

You might be able to shed some light here...

test('optional greedy at start - first', function(t) {
  let doc = nlp(`wayne's world, party time`).match('#Noun+? wayne')
  t.equal(doc.text(), 'wayne')

  t.end()
})

Before the result actually get's returned as a doc, the match gets run quite a number of times, with differing result, I'm printing out the sliced terms and the current regs:

result: wayne's [{"tag":"Noun"}]
result: wayne's [{"tag":"Possessive"}]
result: wayne's [{"tag":"Person"}]
result: wayne's [{"tag":"FirstName"}]
result: wayne's world [{"tag":"FirstName"},{"choices":[{"tag":"Singular"},{"tag":"Possessive"}],"operator":"or"}]
result: world [{"end":true,"anything":true}]
result: wayne's world [{"tag":"FirstName"},{"choices":[{"tag":"Noun"},{"tag":"TitleCase"}],"operator":"or"}]
result: wayne's [{"start":true,"tag":"Possessive"}]
result: world [{"tag":"LastName"}]
result: wayne's world [{"choices":[{"tag":"TitleCase"},{"tag":"Singular"}],"operator":"or"},{"optional":true,"tag":"Acronym"},{"tag":"LastName"}]
result: world [{"end":true,"anything":true}]
result: wayne's world party time [{"optional":true,"greedy":true,"tag":"Noun"},{"word":"wayne"}]

Second last line get's us into here https://github.com/spencermountain/compromise/blob/dev/src/Phrase/match/03-tryMatch.js#L97 which is where things go wrong. I don't quite get the logic of continuing if it's optional, but this is only happening because world has "end":true.

But generally, I would expect to see optional/end waaay back at the start.

yeah, for cleaner logs i either run nlp.tokenize() or i comment-out this line to reduce the number of match statements run by the tagger.

if you're looking at a pr today/tomorrow, use the dev branch. I've got a bunch of fixes there

Ah that's fair, I'll take another look. Thanks, not in any rush this year!

Will take another look at this next!

hey @Drache93 I just discovered the .export() format bungles any sentence with a contraction. It's kind of bad. I should have caught this before now.

It'll require a breaking change - the good news though, is that it's an opportunity to change anything you'd like in this release - so free license to you.
Take a crack at anything you want.

Ah bad luck! Haha that's a dangerous idea! 😂

Would you be up for selecting and or creating some good issues for next version that are big enough? Might as well get other breaking changes and/or just major stuff too! Ooh, I wonder if a hook into the HTML output might be good for creating react content...

Was this page helpful?
0 / 5 - 0 ratings