Whitespace in square brackets problem
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.9k
- Forks
- 1.6k
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
there seems to be a problem with parsing whitespace inside of square brackets here:
My code:
from pattern.search import match
from pattern.en import parsetreetext = "The Sega CD, released as the Mega-CD in most regions outside North America, is an add-on CD-ROM device for the Sega Genesis video game console designed and produced by Sega as part of the fourth generation of video game consoles."
t = parsetree(text)
m = match('{DT?} [Sega CD] *+ {VBZ}', t)
print m.group(0)
print m.group(1)
print m.group(2)
... produces the following error:
Gregors-MacBook-Air:Python gregor$ python constraint.py
Traceback (most recent call last):
File "constraint.py", line 7, in
m = match('{DT?} [Sega CD] _+ {VBZ}', t)
File "/Library/Python/2.7/site-packages/pattern/text/search.py", line 938, in match
return compile(pattern, *args, *_kwargs).match(sentence)
File "/Library/Python/2.7/site-packages/pattern/text/search.py", line 799, in match
return find(lambda (m,s): m is not None, ((self.match(s, start, _v), s) for s in sentence))[0]
TypeError: 'NoneType' object has no attribute 'getitem'
"Sega_CD" instead of "[Sega CD]" doesn't work either.
When I remove the "CD" and the whitespace inside of the square brackets everything works fine:
Gregors-MacBook-Air:Python gregor$ python constraint.py
[Word(u'The/DT'), Word(u'Sega/NNP'), Word(u'CD/NNP'), Word(u',/,'), Word(u'released/JJ'), Word(u'as/IN'), Word(u'the/DT'), Word(u'Mega->CD/NNP'), Word(u'in/IN'), Word(u'most/JJS'), Word(u'regions/NNS'), Word(u'outside/IN'), Word(u'North/NNP-LOC'), Word(u'America/NNP-LOC'>), >Word(u',/,'), Word(u'is/VBZ')]>
[Word(u'The/DT')]
[Word(u'is/VBZ')]
Thanks for the great work guys! Pattern is one of the greatest modules outside!
Gregor
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the reported Python example first, then inspect the match/compile path in pattern/text/search.py, especially handling of bracketed patterns. Done means the [Sega CD] constraint parses and returns the expected match and groups without the NoneType error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100